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).
This commit is contained in:
55
lib/multi.c
55
lib/multi.c
@@ -802,7 +802,8 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
|
|||||||
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
|
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
|
||||||
int bitmap;
|
int bitmap;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int nfds = extra_nfds;
|
unsigned int nfds = 0;
|
||||||
|
unsigned int curlfds;
|
||||||
struct pollfd *ufds = NULL;
|
struct pollfd *ufds = NULL;
|
||||||
|
|
||||||
if(!GOOD_MULTI_HANDLE(multi))
|
if(!GOOD_MULTI_HANDLE(multi))
|
||||||
@@ -832,6 +833,9 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
|
|||||||
easy = easy->next; /* check next handle */
|
easy = easy->next; /* check next handle */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curlfds = nfds; /* number of internal file descriptors */
|
||||||
|
nfds += extra_nfds; /* add the externally provided ones */
|
||||||
|
|
||||||
if(nfds) {
|
if(nfds) {
|
||||||
ufds = malloc(nfds * sizeof(struct pollfd));
|
ufds = malloc(nfds * sizeof(struct pollfd));
|
||||||
if(!ufds)
|
if(!ufds)
|
||||||
@@ -839,32 +843,37 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
|
|||||||
}
|
}
|
||||||
nfds = 0;
|
nfds = 0;
|
||||||
|
|
||||||
/* Add the curl handles to our pollfds first */
|
/* only do the second loop if we found descriptors in the first stage run
|
||||||
easy=multi->easy.next;
|
above */
|
||||||
while(easy != &multi->easy) {
|
|
||||||
bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
|
|
||||||
|
|
||||||
for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
|
if(curlfds) {
|
||||||
curl_socket_t s = CURL_SOCKET_BAD;
|
/* 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)) {
|
for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
|
||||||
ufds[nfds].fd = sockbunch[i];
|
curl_socket_t s = CURL_SOCKET_BAD;
|
||||||
ufds[nfds].events = POLLIN;
|
|
||||||
++nfds;
|
if(bitmap & GETSOCK_READSOCK(i)) {
|
||||||
s = sockbunch[i];
|
ufds[nfds].fd = sockbunch[i];
|
||||||
}
|
ufds[nfds].events = POLLIN;
|
||||||
if(bitmap & GETSOCK_WRITESOCK(i)) {
|
++nfds;
|
||||||
ufds[nfds].fd = sockbunch[i];
|
s = sockbunch[i];
|
||||||
ufds[nfds].events = POLLOUT;
|
}
|
||||||
++nfds;
|
if(bitmap & GETSOCK_WRITESOCK(i)) {
|
||||||
s = sockbunch[i];
|
ufds[nfds].fd = sockbunch[i];
|
||||||
}
|
ufds[nfds].events = POLLOUT;
|
||||||
if(s == CURL_SOCKET_BAD) {
|
++nfds;
|
||||||
break;
|
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 */
|
/* Add external file descriptions from poll-like struct curl_waitfd */
|
||||||
|
Reference in New Issue
Block a user