]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi_wait: fix and improve Curl_poll error handling on Windows
authorMarc Hoersken <info@marc-hoersken.de>
Thu, 25 Aug 2022 22:06:34 +0000 (00:06 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Fri, 26 Aug 2022 09:36:42 +0000 (11:36 +0200)
First check for errors and return CURLM_UNRECOVERABLE_POLL
before moving forward and waiting on socket readiness events.

Reviewed-by: Jay Satiro
Reviewed-by: Marcel Raad
Reported-by: Daniel Stenberg
Ref: #9361

Follow up to #8961
Closes #9372

lib/multi.c

index 5cd0277aee7c2878e79c095d47f4e65158b58c5f..ac753d2120a6c02c490e9213cf4c2bc0412eb2e4 100644 (file)
@@ -1343,8 +1343,6 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
       pollrc = Curl_poll(ufds, nfds, 0); /* just pre-check with WinSock */
     else
       pollrc = 0;
-    if(pollrc <= 0) /* now wait... if not ready during the pre-check above */
-      WSAWaitForMultipleEvents(1, &multi->wsa_event, FALSE, timeout_ms, FALSE);
 #else
     pollrc = Curl_poll(ufds, nfds, timeout_ms); /* wait... */
 #endif
@@ -1355,6 +1353,9 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
       retcode = pollrc;
 #ifdef USE_WINSOCK
     }
+    else { /* now wait... if not ready during the pre-check (pollrc == 0) */
+      WSAWaitForMultipleEvents(1, &multi->wsa_event, FALSE, timeout_ms, FALSE);
+    }
     /* With WinSock, we have to run the following section unconditionally
        to call WSAEventSelect(fd, event, 0) on all the sockets */
     {
@@ -1375,11 +1376,11 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
             mask |= CURL_WAIT_POLLOUT;
           if(wsa_events.lNetworkEvents & FD_OOB)
             mask |= CURL_WAIT_POLLPRI;
-          if(ret && pollrc <= 0 && wsa_events.lNetworkEvents)
+          if(ret && !pollrc && wsa_events.lNetworkEvents)
             retcode++;
         }
         WSAEventSelect(s, multi->wsa_event, 0);
-        if(pollrc <= 0) {
+        if(!pollrc) {
           extra_fds[i].revents = mask;
           continue;
         }
@@ -1405,7 +1406,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
             if(bitmap & (GETSOCK_READSOCK(i) | GETSOCK_WRITESOCK(i))) {
               wsa_events.lNetworkEvents = 0;
               if(WSAEnumNetworkEvents(sockbunch[i], NULL, &wsa_events) == 0) {
-                if(ret && pollrc <= 0 && wsa_events.lNetworkEvents)
+                if(ret && !pollrc && wsa_events.lNetworkEvents)
                   retcode++;
               }
               WSAEventSelect(sockbunch[i], multi->wsa_event, 0);