gnurl_multi_wait(3)
π gnurl_multi_wait(3) β like, the whole libgnurl manual vibe β¨
okay bestie, buckle up π this is the page for gnurl_multi_wait(3) out of the libgnurl Manual, and it's genuinely one of those functions that looks scary and is actually just "wait for something to happen, but politely." let's go π
β¨ NAME β¨
curl_multi_wait β polls on all the easy handles chillin' inside a multi handle π«Ά
(the name says curl_multi_wait but the page is filed under gnurl_multi_wait, iykyk, that's just how it's labeled here π)
πΈ SYNOPSIS πΈ
#include <gnurl/curl.h>
CURLMcode curl_multi_wait(CURLM *multi_handle,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
int timeout_ms,
int *numfds);
look at that signature. five args. main character energy fr fr π
π¦ DESCRIPTION π¦
so curl_multi_wait(3) polls all the file descriptors that the curl easy handles inside your given multi handle set are using. it literally just sits there and waits π
it will block until either:
- activity is detected on at least one of the handles, or
timeout_mshas passed π΄
okay but here's the cute part β if the multi handle has a pending internal timeout that expires sooner than timeout_ms, then that shorter time gets used instead, so timeout accuracy is reasonably kept. she's considerate like that π
your calling application is totally allowed to pass extra curl_waitfd structures β they're basically poll(2)'s pollfd structure's cousin β so they get waited on in the same call π«Ά
on completion, if numfds is non-NULL, it gets populated with the total number of file descriptors on which interesting events occurred. and that number can include both libcurl internal descriptors and the ones you provided in extra_fds. equal opportunity counting β¨
β οΈ heads up: if no extra file descriptors are provided and libcurl has no file descriptor to offer to wait for, this function will return immediately. no waiting, no blocking, just β¨goneβ¨. (try curl_multi_poll(3) instead if you'd rather avoid this behavior π)
and yes β this function is encouraged to be used instead of select(3) when you're using the multi interface. why? because it lets applications more easily circumvent that classic common problem with 1024 maximum file descriptors. we love a function that solves a real problem π
π curl_waitfd π
the little struct herself:
struct curl_waitfd {
curl_socket_t fd;
short events;
short revents;
};
adorable. iconic. three fields. no notes π
now the bit flags that go in events:
CURL_WAIT_POLLINβ bit flag forcurl_waitfd.eventssaying the socket should poll on read events, like new data received π₯CURL_WAIT_POLLPRIβ bit flag forcurl_waitfd.eventssaying the socket should poll on high priority read events, like out of band data π₯CURL_WAIT_POLLOUTβ bit flag forcurl_waitfd.eventssaying the socket should poll on write events, like the socket being clear to write without blocking π€
π₯ EXAMPLE π₯
here's the whole example, copied exactly because you know I don't play with your code blocks π:
CURL *easy_handle;
CURLM *multi_handle;
/* add the individual easy handle */
curl_multi_add_handle(multi_handle, easy_handle);
do {
CURLMcode mc;
int numfds;
mc = curl_multi_perform(multi_handle, &still_running);
if(mc == CURLM_OK ) {
/* wait for activity, timeout or "nothing" */
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
}
if(mc != CURLM_OK) {
fprintf(stderr, "curl_multi failed, code %d.\n", mc);
break;
}
/* 'numfds' being zero means either a timeout or no file descriptors to
wait for. Try timeout on first occurrence, then assume no file
descriptors and no file descriptors to wait for means wait for 100
milliseconds. */
if(!numfds) {
repeats++; /* count number of repeated zero numfds */
if(repeats > 1) {
WAITMS(100); /* sleep 100 milliseconds */
}
}
else
repeats = 0;
} while(still_running);
curl_multi_remove_handle(multi_handle, easy_handle);
π RETURN VALUE π
returns a CURLMcode type β that's the general libcurl multi interface error code, bestie. see libcurl-errors(3) for the full lore π
β AVAILABILITY β
this function was added in libcurl 7.28.0. vintage. retro. still slaying π
π SEE ALSO π
curl_multi_fdset(3), curl_multi_perform(3),curl_multi_poll(3) ,
(yes those last two are smooshed together in the original and there's a stray comma β I am not fixing it, I'm preserving her exactly as she is π«Ά)
aaaand that's the whole page!! πΈ you did so good getting to the bottom, honestly π§
libcurl 7.28.0 Β· 12 Jul 2012 β the source and version and that date, right here in the cutest little sign-off I could manage π byeee β¨π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms