From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/iopause_select.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/libstddjb/iopause_select.c (limited to 'src/libstddjb/iopause_select.c') diff --git a/src/libstddjb/iopause_select.c b/src/libstddjb/iopause_select.c new file mode 100644 index 0000000..a9c6529 --- /dev/null +++ b/src/libstddjb/iopause_select.c @@ -0,0 +1,63 @@ +/* ISC license. */ + +#include +#include /* Solaris... */ +#include +#include +#include +#include + +int iopause_select (iopause_fd *x, unsigned int len, tain_t const *deadline, tain_t const *stamp) +{ + struct timeval tv = { .tv_sec = 0, .tv_usec = 0 } ; + int nfds = 0 ; + fd_set rfds, wfds, xfds ; + int r ; + + FD_ZERO(&rfds) ; + FD_ZERO(&wfds) ; + FD_ZERO(&xfds) ; + if (deadline && tain_less(stamp, deadline)) + { + tain_t delta ; + tain_sub(&delta, deadline, stamp) ; + if (!timeval_from_tain_relative(&tv, &delta)) + { + if (errno != ERANGE) return -1 ; + else deadline = 0 ; + } + } + + { + register unsigned int i = 0 ; + for (; i < len ; i++) + { + x[i].revents = 0 ; + if (x[i].fd >= 0) + { + if (x[i].fd >= nfds) nfds = x[i].fd + 1 ; + if (x[i].events & IOPAUSE_READ) FD_SET(x[i].fd, &rfds) ; + if (x[i].events & IOPAUSE_WRITE) FD_SET(x[i].fd, &wfds) ; + if (x[i].events & IOPAUSE_EXCEPT) FD_SET(x[i].fd, &xfds) ; + } + } + } + + r = select(nfds, &rfds, &wfds, &xfds, deadline ? &tv : 0) ; + + if (r > 0) + { + register unsigned int i = 0 ; + for (; i < len ; i++) if (x[i].fd >= 0) + { + if ((x[i].events & IOPAUSE_READ) && FD_ISSET(x[i].fd, &rfds)) + x[i].revents |= IOPAUSE_READ ; + if ((x[i].events & IOPAUSE_WRITE) && FD_ISSET(x[i].fd, &wfds)) + x[i].revents |= IOPAUSE_WRITE ; + if ((x[i].events & IOPAUSE_EXCEPT) && FD_ISSET(x[i].fd, &xfds)) + x[i].revents |= IOPAUSE_EXCEPT ; + } + } + + return r ; +} -- cgit v1.2.3