diff options
author | Daniel Stenberg <daniel@haxx.se> | 2005-01-13 21:51:48 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2005-01-13 21:51:48 +0000 |
commit | 0e263553488ffbc08b5e98012835bceff9d23f7d (patch) | |
tree | 84aae6c5c0254027471b718b8ad43569828e099c /lib | |
parent | 246ea56eab26e9a13211e88a919e7e30d29272e8 (diff) |
Inspired by Martijn Koster's patch and example source at
http://www.greenhills.co.uk/mak/gentoo/curl-eintr-bug.c, I now made the
select() and poll() calls properly loop if they return -1 and errno is
EINTR. glibc docs for this is found here:
http://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html
This last link says BSD doesn't have this "effect". Will there be a problem
if we do this unconditionally?
S: ----------------------------------------------------------------------
Diffstat (limited to 'lib')
-rw-r--r-- | lib/select.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/select.c b/lib/select.c index 8b6a8ce5c..3a1b6bc44 100644 --- a/lib/select.c +++ b/lib/select.c @@ -23,6 +23,8 @@ #include "setup.h" +#include <errno.h> + #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif @@ -80,7 +82,9 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms) num++; } - r = poll(pfd, num, timeout_ms); + do { + r = poll(pfd, num, timeout_ms); + } while((r == -1) && (errno == EINTR)); if (r < 0) return -1; @@ -142,7 +146,9 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms) maxfd = writefd; } - r = select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout); + do { + r = select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout); + } while((r == -1) && (errno == EINTR)); if (r < 0) return -1; @@ -179,8 +185,11 @@ int Curl_select(curl_socket_t readfd, curl_socket_t writefd, int timeout_ms) */ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms) { + int r; #ifdef HAVE_POLL_FINE - return poll(ufds, nfds, timeout_ms); + do { + r = poll(ufds, nfds, timeout_ms); + } while((r == -1) && (errno == EINTR)); #else struct timeval timeout; struct timeval *ptimeout; @@ -188,7 +197,6 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms) fd_set fds_write; fd_set fds_err; curl_socket_t maxfd; - int r; unsigned int i; FD_ZERO(&fds_read); @@ -223,7 +231,9 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms) ptimeout = &timeout; } - r = select(maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout); + do { + r = select(maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout); + } while((r == -1) && (errno == EINTR)); if (r < 0) return -1; @@ -244,7 +254,6 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms) if (ufds[i].revents != 0) r++; } - - return r; #endif + return r; } |