mirror of
https://github.com/curl/curl.git
synced 2026-04-16 13:35:18 +08:00
easy: add 'populate_fds' func to reduce size of 'wait_or_timeout'
Closes #16820
This commit is contained in:
parent
088f0e6a5b
commit
c329321bf9
49
lib/easy.c
49
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user