1*cf3c1e67SAndrew Jeffery 
2*cf3c1e67SAndrew Jeffery /*File:EINTR_wrappers.h
3*cf3c1e67SAndrew Jeffery *
4*cf3c1e67SAndrew Jeffery * Wrapper functions header file.
5*cf3c1e67SAndrew Jeffery *
6*cf3c1e67SAndrew Jeffery * Copyright (C) <2019>  <American Megatrends International LLC>
7*cf3c1e67SAndrew Jeffery *
8*cf3c1e67SAndrew Jeffery */
9*cf3c1e67SAndrew Jeffery 
10*cf3c1e67SAndrew Jeffery #ifndef EINTR_WRAPPERS_H__
11*cf3c1e67SAndrew Jeffery #define EINTR_WRAPPERS_H__
12*cf3c1e67SAndrew Jeffery 
13*cf3c1e67SAndrew Jeffery #if defined(__linux__)
14*cf3c1e67SAndrew Jeffery #ifndef _SYS_TYPES_H
15*cf3c1e67SAndrew Jeffery #include <sys/types.h>
16*cf3c1e67SAndrew Jeffery #endif
17*cf3c1e67SAndrew Jeffery 
18*cf3c1e67SAndrew Jeffery #ifndef _SYS_PC_H
19*cf3c1e67SAndrew Jeffery #include <sys/ipc.h>
20*cf3c1e67SAndrew Jeffery #endif
21*cf3c1e67SAndrew Jeffery 
22*cf3c1e67SAndrew Jeffery #ifndef _SYS_SEM_H
23*cf3c1e67SAndrew Jeffery #include <sys/sem.h>
24*cf3c1e67SAndrew Jeffery #endif
25*cf3c1e67SAndrew Jeffery 
26*cf3c1e67SAndrew Jeffery #ifndef _SYS_EPOLL_H
27*cf3c1e67SAndrew Jeffery #include <sys/epoll.h>
28*cf3c1e67SAndrew Jeffery #endif
29*cf3c1e67SAndrew Jeffery 
30*cf3c1e67SAndrew Jeffery #ifndef _SYS_SOCKET_H
31*cf3c1e67SAndrew Jeffery #include <sys/socket.h>
32*cf3c1e67SAndrew Jeffery #endif
33*cf3c1e67SAndrew Jeffery 
34*cf3c1e67SAndrew Jeffery #ifndef _SIGNAL_H
35*cf3c1e67SAndrew Jeffery #include <signal.h>
36*cf3c1e67SAndrew Jeffery #endif
37*cf3c1e67SAndrew Jeffery 
38*cf3c1e67SAndrew Jeffery #ifndef _TIME_H
39*cf3c1e67SAndrew Jeffery #include <time.h>
40*cf3c1e67SAndrew Jeffery #endif
41*cf3c1e67SAndrew Jeffery 
42*cf3c1e67SAndrew Jeffery #ifndef _POLL_H
43*cf3c1e67SAndrew Jeffery #include <poll.h>
44*cf3c1e67SAndrew Jeffery #endif
45*cf3c1e67SAndrew Jeffery 
46*cf3c1e67SAndrew Jeffery #ifndef _WAIT_H
47*cf3c1e67SAndrew Jeffery #include <wait.h>
48*cf3c1e67SAndrew Jeffery #endif
49*cf3c1e67SAndrew Jeffery 
50*cf3c1e67SAndrew Jeffery #ifndef _UNISTD_H
51*cf3c1e67SAndrew Jeffery #include <unistd.h>
52*cf3c1e67SAndrew Jeffery #endif
53*cf3c1e67SAndrew Jeffery 
54*cf3c1e67SAndrew Jeffery int  sigwrap_semop(int semid, struct sembuf *sops, size_t nsops);
55*cf3c1e67SAndrew Jeffery int  sigwrap_semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout);
56*cf3c1e67SAndrew Jeffery int  sigwrap_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
57*cf3c1e67SAndrew Jeffery int  sigwrap_epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t *sigmask);
58*cf3c1e67SAndrew Jeffery int  sigwrap_sigwaitinfo(const sigset_t *set, siginfo_t *info);
59*cf3c1e67SAndrew Jeffery int  sigwrap_sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout);
60*cf3c1e67SAndrew Jeffery int  sigwrap_nanosleep(const struct timespec *req, struct timespec *rem);
61*cf3c1e67SAndrew Jeffery int  sigwrap_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain);
62*cf3c1e67SAndrew Jeffery int  sigwrap_usleep(useconds_t usec);
63*cf3c1e67SAndrew Jeffery int  sigwrap_poll(struct pollfd *fds, nfds_t nfds, int timeout);
64*cf3c1e67SAndrew Jeffery int  sigwrap_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask);
65*cf3c1e67SAndrew Jeffery int  sigwrap_select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);
66*cf3c1e67SAndrew Jeffery int  sigwrap_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask);
67*cf3c1e67SAndrew Jeffery int  sigwrap_msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
68*cf3c1e67SAndrew Jeffery int  sigwrap_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
69*cf3c1e67SAndrew Jeffery int  sigwrap_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
70*cf3c1e67SAndrew Jeffery int  sigwrap_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
71*cf3c1e67SAndrew Jeffery int  sigwrap_close(int hFile);
72*cf3c1e67SAndrew Jeffery int sigwrap_open_mode(const char *pathname, int flags, mode_t mode);
73*cf3c1e67SAndrew Jeffery int  sigwrap_open(const char *pathname, int flags);
74*cf3c1e67SAndrew Jeffery 
75*cf3c1e67SAndrew Jeffery 
76*cf3c1e67SAndrew Jeffery pid_t sigwrap_wait(int *status);
77*cf3c1e67SAndrew Jeffery pid_t sigwrap_waitpid(pid_t pid, int *status, int options);
78*cf3c1e67SAndrew Jeffery int   sigwrap_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
79*cf3c1e67SAndrew Jeffery 
80*cf3c1e67SAndrew Jeffery 
81*cf3c1e67SAndrew Jeffery ssize_t sigwrap_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
82*cf3c1e67SAndrew Jeffery ssize_t sigwrap_send(int sockfd, const void *buf, size_t len, int flags);
83*cf3c1e67SAndrew Jeffery ssize_t sigwrap_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
84*cf3c1e67SAndrew Jeffery ssize_t sigwrap_sendsendmsg(int sockfd, const struct msghdr *msg, int flags);
85*cf3c1e67SAndrew Jeffery 
86*cf3c1e67SAndrew Jeffery ssize_t sigwrap_read(int fd, void *buf, size_t count);
87*cf3c1e67SAndrew Jeffery // EINTR wrapper for the standard read() function. Waits until ALL requested data is available. Use the non-blocking version (sigwrap_read)
88*cf3c1e67SAndrew Jeffery // for sockets that are set to non-blocking mode or when partial data is okay
89*cf3c1e67SAndrew Jeffery // Although the description for the read() function describes it differently, it seems possible that the original function may already return
90*cf3c1e67SAndrew Jeffery // even though partial data has already been read. This implementation makes sure that all requested data have been read.
91*cf3c1e67SAndrew Jeffery // See the comment in the signal description https://linux.die.net/man/7/signal
92*cf3c1e67SAndrew Jeffery //* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices.
93*cf3c1e67SAndrew Jeffery //* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket.
94*cf3c1e67SAndrew Jeffery //* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
95*cf3c1e67SAndrew Jeffery //* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred).
96*cf3c1e67SAndrew Jeffery ssize_t sigwrap_blocking_read(int hFile, void *pData, size_t RdLen);
97*cf3c1e67SAndrew Jeffery 
98*cf3c1e67SAndrew Jeffery ssize_t sigwrap_readv(int fd, const struct iovec *iov, int iovcnt);
99*cf3c1e67SAndrew Jeffery 
100*cf3c1e67SAndrew Jeffery ssize_t sigwrap_write(int fd, const void *buf, size_t count);
101*cf3c1e67SAndrew Jeffery // EINTR wrapper for the standard write() function. Waits until ALL data is written! Use the non-blocking version (sigwrap_write)
102*cf3c1e67SAndrew Jeffery // for sockets that are set to non-blocking mode, or when it is OK to write only partial data.
103*cf3c1e67SAndrew Jeffery // Although the description for the write() function describes it differently, it seems possible that the original function may already return
104*cf3c1e67SAndrew Jeffery // even though partial data has already been written. This implementation makes sure that all requested data have been written.
105*cf3c1e67SAndrew Jeffery // See the comment in the signal description https://linux.die.net/man/7/signal
106*cf3c1e67SAndrew Jeffery //* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices.
107*cf3c1e67SAndrew Jeffery //* A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket.
108*cf3c1e67SAndrew Jeffery //* (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred
109*cf3c1e67SAndrew Jeffery //* some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred).
110*cf3c1e67SAndrew Jeffery ssize_t sigwrap_blocking_write(int hFile, const void *pData, ssize_t WrtLen);
111*cf3c1e67SAndrew Jeffery 
112*cf3c1e67SAndrew Jeffery ssize_t sigwrap_writev(int fd, const struct iovec *iov, int iovcnt);
113*cf3c1e67SAndrew Jeffery 
114*cf3c1e67SAndrew Jeffery ssize_t sigwrap_recv(int sockfd, void *buf, size_t len, int flags);
115*cf3c1e67SAndrew Jeffery 
116*cf3c1e67SAndrew Jeffery ssize_t sigwrap_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
117*cf3c1e67SAndrew Jeffery 
118*cf3c1e67SAndrew Jeffery ssize_t sigwrap_recvmsg(int sockfd, struct msghdr *msg, int flags);
119*cf3c1e67SAndrew Jeffery 
120*cf3c1e67SAndrew Jeffery int sigwrap_flock(int fd, int operation);
121*cf3c1e67SAndrew Jeffery 
122*cf3c1e67SAndrew Jeffery 
123*cf3c1e67SAndrew Jeffery #endif
124*cf3c1e67SAndrew Jeffery #endif
125