Changeset View
Changeset View
Standalone View
Standalone View
tests/gpg/t-eventloop.c
Context not available. | |||||
#include <assert.h> | #include <assert.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <sys/types.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> | #include <gpgme.h> | ||||
Context not available. | |||||
} | } | ||||
#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 | int | ||||
do_select (void) | do_select (void) | ||||
{ | { | ||||
Context not available. | |||||
} | } | ||||
return any; | return any; | ||||
} | } | ||||
#endif | |||||
int | int | ||||
my_wait (void) | my_wait (void) | ||||
Context not available. |