25 #ifdef HAVE_SYS_SELECT_H 26 #include <sys/select.h> 29 #if !defined(HAVE_SELECT) && !defined(HAVE_POLL_FINE) 30 #error "We can't compile without select() or poll() support." 33 #if defined(__BEOS__) && !defined(__HAIKU__) 54 #define ELAPSED_MS() (int)curlx_tvdiff(curlx_tvnow(), initial_tv) 57 #define ERROR_NOT_EINTR(error) (Curl_ack_eintr || error != EINTR) 77 #if !defined(MSDOS) && !defined(USE_WINSOCK) 78 #ifndef HAVE_POLL_FINE 95 #elif defined(USE_WINSOCK) 98 pending_ms = timeout_ms;
101 #if defined(HAVE_POLL_FINE) 102 r = poll(NULL, 0, pending_ms);
104 pending_tv.
tv_sec = pending_ms / 1000;
105 pending_tv.
tv_usec = (pending_ms % 1000) * 1000;
106 r = select(0, NULL, NULL, NULL, &pending_tv);
114 if(pending_ms <= 0) {
150 #ifdef HAVE_POLL_FINE 161 struct curltime initial_tv = {0, 0};
167 #if SIZEOF_TIME_T != SIZEOF_INT 169 if(timeout_ms >= INT_MAX)
170 timeout_ms = INT_MAX;
186 pending_ms = (int)timeout_ms;
190 #ifdef HAVE_POLL_FINE 194 pfd[num].
fd = readfd0;
200 pfd[num].
fd = readfd1;
206 pfd[num].
fd = writefd;
217 r = poll(pfd, num, pending_ms);
224 pending_ms = (int)(timeout_ms -
ELAPSED_MS());
225 if(pending_ms <= 0) {
270 FD_SET(readfd0, &fds_read);
271 FD_SET(readfd0, &fds_err);
276 FD_SET(readfd1, &fds_read);
277 FD_SET(readfd1, &fds_err);
285 FD_SET(writefd, &fds_write);
286 FD_SET(writefd, &fds_err);
291 ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
295 pending_tv.
tv_sec = pending_ms / 1000;
296 pending_tv.
tv_usec = (pending_ms % 1000) * 1000;
298 else if(!timeout_ms) {
325 r = select((
int)maxfd + 1,
326 fds_read.fd_count ? &fds_read : NULL,
327 fds_write.fd_count ? &fds_write : NULL,
330 r = select((
int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
339 pending_ms = (int)(timeout_ms -
ELAPSED_MS());
340 if(pending_ms <= 0) {
354 if(FD_ISSET(readfd0, &fds_read))
356 if(FD_ISSET(readfd0, &fds_err))
360 if(FD_ISSET(readfd1, &fds_read))
362 if(FD_ISSET(readfd1, &fds_err))
366 if(FD_ISSET(writefd, &fds_write))
368 if(FD_ISSET(writefd, &fds_err))
393 #ifndef HAVE_POLL_FINE 401 struct curltime initial_tv = {0, 0};
402 bool fds_none =
TRUE;
409 for(i = 0; i < nfds; i++) {
427 pending_ms = timeout_ms;
431 #ifdef HAVE_POLL_FINE 438 r = poll(ufds, nfds, pending_ms);
445 pending_ms = (int)(timeout_ms -
ELAPSED_MS());
446 if(pending_ms <= 0) {
458 for(i = 0; i < nfds; i++) {
474 for(i = 0; i < nfds; i++) {
481 if(ufds[i].fd > maxfd)
484 FD_SET(ufds[i].fd, &fds_read);
486 FD_SET(ufds[i].fd, &fds_write);
488 FD_SET(ufds[i].fd, &fds_err);
495 if(fds_read.fd_count == 0 && fds_write.fd_count == 0
496 && fds_err.fd_count == 0) {
502 ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
506 pending_tv.
tv_sec = pending_ms / 1000;
507 pending_tv.
tv_usec = (pending_ms % 1000) * 1000;
509 else if(!timeout_ms) {
515 r = select((
int)maxfd + 1,
520 fds_read.fd_count ? &fds_read : NULL,
521 fds_write.fd_count ? &fds_write : NULL,
522 fds_err.fd_count ? &fds_err : NULL, ptimeout);
524 r = select((
int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
533 if(pending_ms <= 0) {
546 for(i = 0; i < nfds; i++) {
550 if(FD_ISSET(ufds[i].fd, &fds_read))
552 if(FD_ISSET(ufds[i].fd, &fds_write))
554 if(FD_ISSET(ufds[i].fd, &fds_err))
556 if(ufds[i].revents != 0)
574 int tpf_select_libcurl(
int maxfds, fd_set *reads, fd_set *writes,
575 fd_set *excepts,
struct timeval *tv)
579 rc = tpf_select_bsd(maxfds, reads, writes, excepts, tv);
580 tpf_process_signals();
struct curltime curlx_tvnow(void)
int Curl_wait_ms(int timeout_ms)
int Curl_socket_check(curl_socket_t readfd0, curl_socket_t readfd1, curl_socket_t writefd, time_t timeout_ms)
#define ERROR_NOT_EINTR(error)
int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)