Skip to content

Commit

Permalink
multi_wait: fix and improve Curl_poll error handling on Windows
Browse files Browse the repository at this point in the history
First check for errors and return CURLM_UNRECOVERABLE_POLL
before moving forward and waiting on socket readiness events.

Reported-by: Daniel Stenberg
Ref: curl#9361

Follow up to curl#8961
  • Loading branch information
mback2k committed Aug 25, 2022
1 parent a71fe41 commit 4ce56f0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
{
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 4ce56f0

Please sign in to comment.