diff options
author | Daniel Stenberg <daniel@haxx.se> | 2016-03-09 10:57:42 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2016-03-10 08:17:25 +0100 |
commit | 77e172671998037d9d71f84b3b28a2fa1390daff (patch) | |
tree | db60146c560c42130fbcc3447ce1bb373aa942cd /lib | |
parent | b6665c7a44c78b064042c005af67c9e7a420a497 (diff) |
curl_multi_wait: never return -1 in 'numfds'
Such a return value isn't documented but could still happen, and the
curl tool code checks for it. It would happen when the underlying
Curl_poll() function returns an error. Starting now we mask that error
as a user of curl_multi_wait() would have no way to handle it anyway.
Reported-by: Jay Satiro
Closes #707
Diffstat (limited to 'lib')
-rw-r--r-- | lib/multi.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/multi.c b/lib/multi.c index ad7d21fea..6a1f7c82b 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -811,6 +811,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, unsigned int curlfds; struct pollfd *ufds = NULL; long timeout_internal; + int retcode = 0; if(!GOOD_MULTI_HANDLE(multi)) return CURLM_BAD_HANDLE; @@ -903,18 +904,20 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, } if(nfds) { + int pollrc; /* wait... */ - infof(data, "Curl_poll(%d ds, %d ms)\n", nfds, timeout_ms); - i = Curl_poll(ufds, nfds, timeout_ms); + pollrc = Curl_poll(ufds, nfds, timeout_ms); + DEBUGF(infof(data, "Curl_poll(%d ds, %d ms) == %d\n", + nfds, timeout_ms, pollrc)); - if(i) { - unsigned int j; + if(pollrc > 0) { + retcode = pollrc; /* copy revents results from the poll to the curl_multi_wait poll struct, the bit values of the actual underlying poll() implementation may not be the same as the ones in the public libcurl API! */ - for(j = 0; j < extra_nfds; j++) { + for(i = 0; i < extra_nfds; i++) { unsigned short mask = 0; - unsigned r = ufds[curlfds + j].revents; + unsigned r = ufds[curlfds + i].revents; if(r & POLLIN) mask |= CURL_WAIT_POLLIN; @@ -923,16 +926,14 @@ CURLMcode curl_multi_wait(CURLM *multi_handle, if(r & POLLPRI) mask |= CURL_WAIT_POLLPRI; - extra_fds[j].revents = mask; + extra_fds[i].revents = mask; } } } - else - i = 0; free(ufds); if(ret) - *ret = i; + *ret = retcode; return CURLM_OK; } |