diff options
Diffstat (limited to 'tests/gpg/t-eventloop.c')
-rw-r--r-- | tests/gpg/t-eventloop.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/gpg/t-eventloop.c b/tests/gpg/t-eventloop.c index b31764ea..0106670b 100644 --- a/tests/gpg/t-eventloop.c +++ b/tests/gpg/t-eventloop.c @@ -31,7 +31,17 @@ #include <assert.h> #include <errno.h> #include <sys/types.h> -#include <sys/select.h> +#ifdef HAVE_POLL_H +# include <poll.h> +#else +# ifdef HAVE_SYS_SELECT_H +# include <sys/select.h> +# else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# endif +# endif +#endif #include <gpgme.h> @@ -104,6 +114,56 @@ io_event (void *data, gpgme_event_io_t type, void *type_data) } +#ifdef HAVE_POLL_H +int +do_select (void) +{ + struct pollfd poll_fds[FDLIST_MAX]; + nfds_t poll_nfds; + int i, n; + int any = 0; + + poll_nfds = 0; + for (i = 0; i < FDLIST_MAX; i++) + if (fdlist[i].fd != -1) + { + poll_fds[poll_nfds].fd = fdlist[i].fd; + poll_fds[poll_nfds].events = 0; + poll_fds[poll_nfds].revents = 0; + if (fdlist[i].dir) + poll_fds[poll_nfds].events |= POLLIN; + else + poll_fds[poll_nfds].events |= POLLOUT; + poll_nfds++; + } + + do + { + n = poll (poll_fds, poll_nfds, 1000); + } + while (n < 0 && (errno == EINTR || errno == EAGAIN)); + + if (n < 0) + return n; /* Error or timeout. */ + + poll_nfds = 0; + for (i = 0; i < FDLIST_MAX && n; i++) + { + if (fdlist[i].fd != -1) + { + if ((poll_fds[poll_nfds++].revents + & (fdlist[i].dir ? (POLLIN|POLLHUP) : POLLOUT))) + { + assert (n); + n--; + any = 1; + (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd); + } + } + } + return any; +} +#else int do_select (void) { @@ -146,6 +206,7 @@ do_select (void) } return any; } +#endif int my_wait (void) |