2
* Copyright (C) 2010 Brian Aker, Trond Norbye
5
* Use and distribution licensed under the BSD license. See
6
* the COPYING file in the parent directory for full text.
8
* Summary: Implementation of poll by using select
14
#include "libdrizzle/common.h"
16
#if defined(WIN32) || defined(__MINGW32__)
17
#include "libdrizzle/poll.h"
22
int poll(struct pollfd fds[], nfds_t nfds, int tmo)
24
fd_set readfds, writefds, errorfds;
31
for (nfds_t x= 0; x < nfds; ++x)
33
if (fds[x].events & (POLLIN | POLLOUT))
36
if (fds[x].fd > maxfd)
41
if (fds[x].events & POLLIN)
43
FD_SET(fds[x].fd, &readfds);
45
if (fds[x].events & POLLOUT)
47
FD_SET(fds[x].fd, &writefds);
52
struct timeval timeout= { .tv_sec = tmo / 1000,
53
.tv_usec= (tmo % 1000) * 1000 };
54
struct timeval *tp= &timeout;
59
int ret= select(maxfd + 1, &readfds, &writefds, &errorfds, tp);
65
/* Iterate through all of them because I need to clear the revent map */
66
for (nfds_t x= 0; x < nfds; ++x)
69
if (FD_ISSET(fds[x].fd, &readfds))
71
fds[x].revents |= POLLIN;
73
if (FD_ISSET(fds[x].fd, &writefds))
75
fds[x].revents |= POLLOUT;
77
if (FD_ISSET(fds[x].fd, &errorfds))
79
fds[x].revents |= POLLERR;
86
#endif // defined(WIN32) || defined(__MINGW32__)