24 #if _POSIX_C_SOURCE >= 200112L
35 int arg = fcntl(fd, F_GETFD);
38 if (!(arg & FD_CLOEXEC) && fcntl(fd, F_SETFD, arg | FD_CLOEXEC) == -1)
46 int arg = fcntl(fd, F_GETFL);
49 if (!(arg & O_NONBLOCK) && fcntl(fd, F_SETFL, arg | O_NONBLOCK) == -1)
60 struct pollfd fds[1] = { { .fd = fd, .events = *events } };
62 result = poll(fds, 1, timeout);
64 while (result == -1 && ((timeout < 0 && errno == EINTR)
70 if (!result && timeout >= 0) {
75 *events = fds[0].revents;
84 flags |= MSG_DONTWAIT;
92 result = recvmsg(fd, msg, flags);
97 if (!timeout || (errno != EAGAIN && errno != EWOULDBLOCK))
101 int events = (flags & MSG_OOB)
102 ? (POLLRDBAND | POLLPRI) : POLLRDNORM;
118 flags |= MSG_NOSIGNAL;
121 flags |= MSG_DONTWAIT;
129 result = sendmsg(fd, msg, flags);
134 if (!timeout || (errno != EAGAIN && errno != EWOULDBLOCK))
137 int events = (flags & MSG_OOB) ? POLLWRBAND : POLLWRNORM;
int io_fd_set_cloexec(int fd)
Sets the FD_CLOEXEC flag of the file descriptor fd.
ssize_t io_fd_sendmsg(int fd, const struct msghdr *msg, int flags, int timeout)
Equivalent to POSIX sendmsg(fd, msg, flags | MSG_NOSIGNAL), except that if fd is non-blocking (or the...
ssize_t io_fd_recvmsg(int fd, struct msghdr *msg, int flags, int timeout)
Equivalent to POSIX recvmsg(fd, msg, flags), except that if fd is non-blocking (or the implementation...
int io_fd_wait(int fd, int *events, int timeout)
Waits for one or more of the I/O events in *events to occur as if by POSIX poll().
int io_fd_set_nonblock(int fd)
Sets the O_NONBLOCK flag of the file descriptor fd.
This is the internal header file of the common file descriptor functions.