summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Hoersken <info@marc-hoersken.de>2020-09-12 21:59:26 +0200
committerMarc Hoersken <info@marc-hoersken.de>2020-09-17 07:40:49 +0200
commit40d67da7caaef4c23399306cbcac7883a925ce6f (patch)
treebf859e6f6133c01bc86b6ec6866580eb8e5c50cd
parentaf09599958bfdcdc3136da1dc8a7b2bfc9f108c4 (diff)
downloadcurl-40d67da7caaef4c23399306cbcac7883a925ce6f.tar.gz
multi: reuse WinSock events variable in Curl_multi_wait
Since the struct is quite large (1 long and 10 ints) we declare it once at the beginning of the function instead of multiple times inside loops to avoid stack movements. Reviewed-by: Viktor Szakats Reviewed-by: Daniel Stenberg Closes #5886
-rw-r--r--lib/multi.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/multi.c b/lib/multi.c
index b9316b3c4..f374b2721 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -1095,6 +1095,7 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
bool ufds_malloc = FALSE;
#else
struct pollfd pre_poll;
+ WSANETWORKEVENTS wsa_events;
DEBUGASSERT(multi->wsa_event != WSA_INVALID_EVENT);
#endif
@@ -1295,18 +1296,17 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
for(i = 0; i < extra_nfds; i++) {
unsigned short mask = 0;
#ifdef USE_WINSOCK
- WSANETWORKEVENTS events = {0};
+ wsa_events.lNetworkEvents = 0;
mask = extra_fds[i].revents;
if(WSAEnumNetworkEvents(extra_fds[i].fd, multi->wsa_event,
- &events) == 0) {
- if(events.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE))
+ &wsa_events) == 0) {
+ if(wsa_events.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE))
mask |= CURL_WAIT_POLLIN;
- if(events.lNetworkEvents & (FD_WRITE|FD_CONNECT|FD_CLOSE))
+ if(wsa_events.lNetworkEvents & (FD_WRITE|FD_CONNECT|FD_CLOSE))
mask |= CURL_WAIT_POLLOUT;
- if(events.lNetworkEvents & FD_OOB)
+ if(wsa_events.lNetworkEvents & FD_OOB)
mask |= CURL_WAIT_POLLPRI;
-
- if(ret && events.lNetworkEvents != 0)
+ if(ret && wsa_events.lNetworkEvents != 0)
retcode++;
}
WSAEventSelect(extra_fds[i].fd, multi->wsa_event, 0);
@@ -1320,7 +1320,6 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
if(r & POLLPRI)
mask |= CURL_WAIT_POLLPRI;
#endif
-
extra_fds[i].revents = mask;
}
@@ -1334,13 +1333,13 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
for(i = 0; i < MAX_SOCKSPEREASYHANDLE; i++) {
if(bitmap & (GETSOCK_READSOCK(i) | GETSOCK_WRITESOCK(i))) {
- WSANETWORKEVENTS events = {0};
+ wsa_events.lNetworkEvents = 0;
if(WSAEnumNetworkEvents(sockbunch[i], multi->wsa_event,
- &events) == 0) {
- if(ret && events.lNetworkEvents != 0)
+ &wsa_events) == 0) {
+ if(ret && wsa_events.lNetworkEvents != 0)
retcode++;
}
- if(ret && !timeout_ms && !events.lNetworkEvents) {
+ if(ret && !timeout_ms && wsa_events.lNetworkEvents == 0) {
if((bitmap & GETSOCK_READSOCK(i)) &&
SOCKET_READABLE(sockbunch[i], 0) > 0)
retcode++;