2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libmemcached/common.h"
19 # include "libmemcached/poll.h"
21 # include <sys/time.h>
28 int poll(struct pollfd fds
[], nfds_t nfds
, int tmo
) {
29 fd_set readfds
, writefds
, errorfds
;
36 for (nfds_t x
= 0; x
< nfds
; ++x
) {
37 if (fds
[x
].events
& (POLLIN
| POLLOUT
)) {
39 if (fds
[x
].fd
> maxfd
) {
43 if (fds
[x
].events
& POLLIN
) {
44 FD_SET(fds
[x
].fd
, &readfds
);
46 if (fds
[x
].events
& POLLOUT
) {
47 FD_SET(fds
[x
].fd
, &writefds
);
52 struct timeval timeout
= {.tv_sec
= tmo
/ 1000, .tv_usec
= (tmo
% 1000) * 1000};
53 struct timeval
*tp
= &timeout
;
57 int ret
= select(maxfd
+ 1, &readfds
, &writefds
, &errorfds
, tp
);
62 /* Iterate through all of them because I need to clear the revent map */
63 for (nfds_t x
= 0; x
< nfds
; ++x
) {
65 if (FD_ISSET(fds
[x
].fd
, &readfds
)) {
66 fds
[x
].revents
|= POLLIN
;
68 if (FD_ISSET(fds
[x
].fd
, &writefds
)) {
69 fds
[x
].revents
|= POLLOUT
;
71 if (FD_ISSET(fds
[x
].fd
, &errorfds
)) {
72 fds
[x
].revents
|= POLLERR
;
79 #endif // defined(_WIN32)