curl_multi_waitfds(3)
π curl_multi_waitfds β bestie, let's talk
okay so this is a page from the libcurl Library Functions Manual β¨ β yes, that libcurl, the one you already know and love. sit down, grab a strawberry, we're getting into it π
πΈ NAME πΈ
curl_multi_waitfds β extract file descriptor info from a multi handle. that's it, that's the vibe. it's giving "tell me what file descriptors your multi handle is working with" π¦
β¨ SYNOPSIS β¨
#include <curl/curl.h>
#include <stdlib.h>
CURLMcode curl_multi_waitfds(CURLM *multi,
struct curl_waitfd *ufds,
unsigned int size,
unsigned int *fd_count);
like, four arguments, no drama, main character energy π
π DESCRIPTION π
okay so this function extracts curl_waitfd structures from a given multi_handle. and bestie, these structs are literally siblings of poll(2)'s pollfd structure β no cap, same energy π₯
you can use these structures to poll on the multi_handle file descriptors, in a fashion similar to curl_multi_poll(3). and the moment one of them is ready to be read from or written to, you should call curl_multi_perform(3). like, immediately. don't ghost it π
libcurl fills your provided ufds array up to size. but heads up:
if the number of descriptors used by the multi_handle is greater than the size parameter, libcurl returns CURLM_OUT_OF_MEMORY. so don't be stingy with the size, bestie π
if the fd_count argument is not a null pointer, it points to a variable that on return specifies the number of descriptors used by the multi_handle to be checked for being ready to read or write. iconic behavior, honestly π
and here's the cute trick: the client code can pass size equal to zero just to get the number of descriptors, then allocate appropriate storage for them to be used in a subsequent function call. in this case, fd_count receives a number greater than or equal to the number of descriptors. it's giving "two-step, but make it efficient" β¨
π PROTOCOLS π
this functionality affects all supported protocols. all of them. every single one. we stan an inclusive king π
π§ EXAMPLE π§
#include <stdlib.h>
int main(void)
{
CURLMcode mresult;
struct curl_waitfd *ufds;
CURLM *multi = curl_multi_init();
do {
/* call curl_multi_perform() */
/* get the count of file descriptors from the transfers */
unsigned int fd_count = 0;
mresult = curl_multi_waitfds(multi, NULL, 0, &fd_count);
if(mresult != CURLM_OK) {
fprintf(stderr, "curl_multi_waitfds() failed, code %d.\n", mresult);
break;
}
if(!fd_count)
continue; /* no descriptors yet */
/* allocate storage for our descriptors */
ufds = malloc(fd_count * sizeof(struct curl_waitfd));
/* get wait descriptors from the transfers and put them into array. */
mresult = curl_multi_waitfds(multi, ufds, fd_count, &fd_count);
if(mresult != CURLM_OK) {
fprintf(stderr, "curl_multi_waitfds() failed, code %d.\n", mresult);
free(ufds);
break;
}
/* Do polling on descriptors in ufds */
free(ufds);
} while(!mresult);
}
see how it first asks "how many?" with NULL and 0, then allocates, then asks for realsies? that's the whole two-call pattern in action, and it ate π
π«Ά AVAILABILITY π«Ά
Added in curl 8.8.0. so if you're on something older... bestie, upgrade π
β RETURN VALUE β
this function returns a CURLMcode indicating success or error.
CURLM_OK (0) means everything was OK β slay. non-zero means an error occurred. see libcurl-errors(3) for the full tea π΅
π SEE ALSO π
okay that's the whole page, bestie β go poll those descriptors responsibly πΈπ
this has been libcurl, dated 2026-10-12, signing off with main character energy β¨ππ¦
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms