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>
24 int poll(struct pollfd fds
[], nfds_t nfds
, int tmo
) {
25 fd_set readfds
, writefds
, errorfds
;
32 for (nfds_t x
= 0; x
< nfds
; ++x
) {
33 if (fds
[x
].events
& (POLLIN
| POLLOUT
)) {
35 if (fds
[x
].fd
> maxfd
) {
39 if (fds
[x
].events
& POLLIN
) {
40 FD_SET(fds
[x
].fd
, &readfds
);
42 if (fds
[x
].events
& POLLOUT
) {
43 FD_SET(fds
[x
].fd
, &writefds
);
48 struct timeval timeout
= {.tv_sec
= tmo
/ 1000, .tv_usec
= (tmo
% 1000) * 1000};
49 struct timeval
*tp
= &timeout
;
53 int ret
= select(maxfd
+ 1, &readfds
, &writefds
, &errorfds
, tp
);
58 /* Iterate through all of them because I need to clear the revent map */
59 for (nfds_t x
= 0; x
< nfds
; ++x
) {
61 if (FD_ISSET(fds
[x
].fd
, &readfds
)) {
62 fds
[x
].revents
|= POLLIN
;
64 if (FD_ISSET(fds
[x
].fd
, &writefds
)) {
65 fds
[x
].revents
|= POLLOUT
;
67 if (FD_ISSET(fds
[x
].fd
, &errorfds
)) {
68 fds
[x
].revents
|= POLLERR
;
75 #endif // defined(_WIN32)