26 #ifdef HAVE_SYS_SELECT_H 27 #include <sys/select.h> 30 #if !defined(HAVE_SELECT) && !defined(HAVE_POLL_FINE) 31 #error "We can't compile without select() or poll() support." 38 #include <sys/types.h> 40 #include "lirc/curl_poll.h" 68 int curl_poll(
struct pollfd ufds[],
unsigned int nfds,
int timeout_ms)
70 return poll(ufds, nfds, timeout_ms);
75 static struct timeval curlx_tvnow(void)
84 (void)gettimeofday(&now, NULL);
95 long curlx_tvdiff(
struct timeval newer,
struct timeval older)
97 return (newer.tv_sec - older.tv_sec) * 1000 +
98 (long)(newer.tv_usec - older.tv_usec) / 1000;
102 static int verify_sock(
int s)
104 if (s < 0 || s >= FD_SETSIZE) {
106 log_notice(
"curl_poll: Invalid socket %d", s);
113 int curl_poll(
struct pollfd ufds[],
unsigned int nfds,
int timeout_ms)
115 struct timeval pending_tv;
116 struct timeval* ptimeout;
122 struct timeval initial_tv = { 0, 0 };
132 if (timeout_ms > 0) {
133 pending_ms = timeout_ms;
134 gettimeofday(&initial_tv, NULL);
142 for (i = 0; i < nfds; i++) {
144 if (ufds[i].fd == -1)
146 ufds[i].fd = verify_sock(ufds[i].fd);
147 if (ufds[i].events & (POLLIN | POLLOUT | POLLPRI |
148 POLLRDNORM | POLLWRNORM | POLLRDBAND)) {
149 if (ufds[i].fd > maxfd)
151 if (ufds[i].events & (POLLRDNORM | POLLIN))
152 FD_SET(ufds[i].fd, &fds_read);
153 if (ufds[i].events & (POLLWRNORM | POLLOUT))
154 FD_SET(ufds[i].fd, &fds_write);
155 if (ufds[i].events & (POLLRDBAND | POLLPRI))
156 FD_SET(ufds[i].fd, &fds_err);
160 ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
162 if (timeout_ms > 0) {
163 pending_tv.tv_sec = pending_ms / 1000;
164 pending_tv.tv_usec = (pending_ms % 1000) * 1000;
165 }
else if (!timeout_ms) {
166 pending_tv.tv_sec = 0;
167 pending_tv.tv_usec = 0;
169 r = select((
int)maxfd + 1, &fds_read, &fds_write, &fds_err,
176 for (i = 0; i < nfds; i++) {
178 if (ufds[i].fd == -1)
180 if (FD_ISSET(ufds[i].fd, &fds_read))
181 ufds[i].revents |= POLLIN;
182 if (FD_ISSET(ufds[i].fd, &fds_write))
183 ufds[i].revents |= POLLOUT;
184 if (FD_ISSET(ufds[i].fd, &fds_err))
185 ufds[i].revents |= POLLPRI;
186 if (ufds[i].revents != 0)
#define log_notice(fmt,...)