3 #if defined P9Y_NEED_POLL
5 int poll(struct pollfd fds
[], nfds_t nfds
, int tmo
) {
6 fd_set readfds
, writefds
, errorfds
;
13 for (nfds_t x
= 0; x
< nfds
; ++x
) {
14 if (fds
[x
].events
& (POLLIN
| POLLOUT
)) {
16 if (fds
[x
].fd
> maxfd
) {
20 if (fds
[x
].events
& POLLIN
) {
21 FD_SET(fds
[x
].fd
, &readfds
);
23 if (fds
[x
].events
& POLLOUT
) {
24 FD_SET(fds
[x
].fd
, &writefds
);
29 struct timeval timeout
= {tmo
/ 1000, (tmo
% 1000) * 1000};
30 struct timeval
*tp
= &timeout
;
34 int ret
= select(maxfd
+ 1, &readfds
, &writefds
, &errorfds
, tp
);
39 /* Iterate through all of them because I need to clear the revent map */
40 for (nfds_t x
= 0; x
< nfds
; ++x
) {
42 if (FD_ISSET(fds
[x
].fd
, &readfds
)) {
43 fds
[x
].revents
|= POLLIN
;
45 if (FD_ISSET(fds
[x
].fd
, &writefds
)) {
46 fds
[x
].revents
|= POLLOUT
;
48 if (FD_ISSET(fds
[x
].fd
, &errorfds
)) {
49 fds
[x
].revents
|= POLLERR
;
56 #endif // P9Y_NEED_POLL