summaryrefslogtreecommitdiff
path: root/lib/select.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2009-09-15 00:07:56 +0000
committerYang Tse <yangsita@gmail.com>2009-09-15 00:07:56 +0000
commitf7690db37d5c0225c73b02cbadc9a4d32137c75b (patch)
tree7f7bb83dfe1b9cd30480e185dbbec1257b9a458d /lib/select.c
parent7e0b0763fc609f99ec8938382a8ffada9493d7ab (diff)
downloadcurl-f7690db37d5c0225c73b02cbadc9a4d32137c75b.tar.gz
Some systems poll function sets POLLHUP in revents without setting
POLLIN, and sets POLLERR without setting POLLIN and POLLOUT. In some libcurl code execution paths this could trigger busy wait loops with high CPU usage until a timeout condition aborted the loop. This fix for Curl_poll adresses the above in a libcurl-wide mode.
Diffstat (limited to 'lib/select.c')
-rw-r--r--lib/select.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/select.c b/lib/select.c
index 7d6a6234f..2e1f38e5f 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -398,6 +398,20 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
}
} while(r == -1);
+ if(r < 0)
+ return -1;
+ if(r == 0)
+ return 0;
+
+ for (i = 0; i < nfds; i++) {
+ if(ufds[i].fd == CURL_SOCKET_BAD)
+ continue;
+ if(ufds[i].revents & POLLHUP)
+ ufds[i].revents |= POLLIN;
+ if(ufds[i].revents & POLLERR)
+ ufds[i].revents |= (POLLIN|POLLOUT);
+ }
+
#else /* HAVE_POLL_FINE */
FD_ZERO(&fds_read);