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