From: Gabriel Marin Date: Mon, 24 Mar 2025 16:18:49 +0000 (+0200) Subject: easy: add 'populate_fds' func to reduce size of 'wait_or_timeout' X-Git-Tag: curl-8_13_0~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c329321bf97ec8699583f3e3ea10a7e22bbbb6ea;p=thirdparty%2Fcurl.git easy: add 'populate_fds' func to reduce size of 'wait_or_timeout' Closes #16820 --- diff --git a/lib/easy.c b/lib/easy.c index 1b03fddce7..aa1bedec38 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -542,12 +542,34 @@ static void events_setup(struct Curl_multi *multi, struct events *ev) curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev); } +/* populate_fds() + * + * populate the fds[] array + */ +static unsigned int populate_fds(struct pollfd *fds, struct events *ev) +{ + unsigned int numfds = 0; + struct pollfd *f; + struct socketmonitor *m; + + f = &fds[0]; + for(m = ev->list; m; m = m->next) { + f->fd = m->socket.fd; + f->events = m->socket.events; + f->revents = 0; +#if DEBUG_EV_POLL + fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); +#endif + f++; + numfds++; + } + return numfds; +} /* wait_or_timeout() * * waits for activity on any of the given sockets, or the timeout to trigger. */ - static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) { bool done = FALSE; @@ -556,26 +578,10 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) while(!done) { CURLMsg *msg; - struct socketmonitor *m; - struct pollfd *f; struct pollfd fds[4]; - int numfds = 0; int pollrc; - int i; struct curltime before; - - /* populate the fds[] array */ - f = &fds[0]; - for(m = ev->list; m; m = m->next) { - f->fd = m->socket.fd; - f->events = m->socket.events; - f->revents = 0; -#if DEBUG_EV_POLL - fprintf(stderr, "poll() %d check socket %d\n", numfds, f->fd); -#endif - f++; - numfds++; - } + const unsigned int numfds = populate_fds(fds, ev); /* get the time stamp to use to figure out how long poll takes */ before = Curl_now(); @@ -583,11 +589,11 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) if(numfds) { /* wait for activity or timeout */ #if DEBUG_EV_POLL - fprintf(stderr, "poll(numfds=%d, timeout=%ldms)\n", numfds, ev->ms); + fprintf(stderr, "poll(numfds=%u, timeout=%ldms)\n", numfds, ev->ms); #endif - pollrc = Curl_poll(fds, (unsigned int)numfds, ev->ms); + pollrc = Curl_poll(fds, numfds, ev->ms); #if DEBUG_EV_POLL - fprintf(stderr, "poll(numfds=%d, timeout=%ldms) -> %d\n", + fprintf(stderr, "poll(numfds=%u, timeout=%ldms) -> %d\n", numfds, ev->ms, pollrc); #endif if(pollrc < 0) @@ -615,6 +621,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) /* here pollrc is > 0 */ struct Curl_llist_node *e = Curl_llist_head(&multi->process); struct Curl_easy *data; + unsigned int i; DEBUGASSERT(e); data = Curl_node_elem(e); DEBUGASSERT(data);