aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-03-09 22:26:07 +0100
committerDaniel Stenberg <daniel@haxx.se>2013-03-09 22:27:15 +0100
commit136a3a0ee25f28fec1dde216467389f9e6e4f65c (patch)
treedc1d2df93c0ec6eb4dced28f3efd1e64f3f1d75d
parent64b2d2d77e112f1519995b54cb0806e1f2e4a9f6 (diff)
curl_multi_wait: avoid second loop if nothing to do
... hopefully this will also make clang-analyzer stop warning on potentional NULL dereferences (which were false positives anyway).
-rw-r--r--lib/multi.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/multi.c b/lib/multi.c
index 825f77740..a369d0361 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -802,7 +802,8 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
int bitmap;
unsigned int i;
- unsigned int nfds = extra_nfds;
+ unsigned int nfds = 0;
+ unsigned int curlfds;
struct pollfd *ufds = NULL;
if(!GOOD_MULTI_HANDLE(multi))
@@ -832,6 +833,9 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
easy = easy->next; /* check next handle */
}
+ curlfds = nfds; /* number of internal file descriptors */
+ nfds += extra_nfds; /* add the externally provided ones */
+
if(nfds) {
ufds = malloc(nfds * sizeof(struct pollfd));
if(!ufds)
@@ -839,32 +843,37 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
}
nfds = 0;
- /* Add the curl handles to our pollfds first */
- easy=multi->easy.next;
- while(easy != &multi->easy) {
- bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
+ /* only do the second loop if we found descriptors in the first stage run
+ above */
- for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
- curl_socket_t s = CURL_SOCKET_BAD;
+ if(curlfds) {
+ /* Add the curl handles to our pollfds first */
+ easy=multi->easy.next;
+ while(easy != &multi->easy) {
+ bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
- if(bitmap & GETSOCK_READSOCK(i)) {
- ufds[nfds].fd = sockbunch[i];
- ufds[nfds].events = POLLIN;
- ++nfds;
- s = sockbunch[i];
- }
- if(bitmap & GETSOCK_WRITESOCK(i)) {
- ufds[nfds].fd = sockbunch[i];
- ufds[nfds].events = POLLOUT;
- ++nfds;
- s = sockbunch[i];
- }
- if(s == CURL_SOCKET_BAD) {
- break;
+ for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
+ curl_socket_t s = CURL_SOCKET_BAD;
+
+ if(bitmap & GETSOCK_READSOCK(i)) {
+ ufds[nfds].fd = sockbunch[i];
+ ufds[nfds].events = POLLIN;
+ ++nfds;
+ s = sockbunch[i];
+ }
+ if(bitmap & GETSOCK_WRITESOCK(i)) {
+ ufds[nfds].fd = sockbunch[i];
+ ufds[nfds].events = POLLOUT;
+ ++nfds;
+ s = sockbunch[i];
+ }
+ if(s == CURL_SOCKET_BAD) {
+ break;
+ }
}
- }
- easy = easy->next; /* check next handle */
+ easy = easy->next; /* check next handle */
+ }
}
/* Add external file descriptions from poll-like struct curl_waitfd */