curl_multi_timeout(3)
β¨ curl_multi_timeout β the "how long do I wait tho" era β¨
ok so bestie, this page is curl_multi_timeout(3), and it lives in the Library Functions Manual section of the curl docs β very demure, very library-functions. It's a man page about how long to wait for action before proceeding, and honestly? relatable. π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLMcode curl_multi_timeout(CURLM *multi_handle, long *timeout);
that's it. that's the whole vibe. two arguments and a dream. π
π DESCRIPTION π
So if your app is out here using the libcurl multi interface, you should literally call curl_multi_timeout(3) to figure out how long it should wait for socket actions β at most β before proceeding. like, the maximum amount of patience. slay. β¨
Now, "proceeding" means one of two things, and you gotta pick your lane:
- do the socket-style timeout action: call
curl_multi_socket_action(3)with thesockfdargument set toCURL_SOCKET_TIMEOUT, or - call
curl_multi_perform(3)if you're on the simpler and older multi interface approach (the retro one, no cap)
The timeout value gets written into the long that timeout points to, and it's in number of milliseconds at this moment β present tense, right now, current era:
- if it's
0, it means you should proceed immediately without waiting for anything. go go go πββοΈ - if it returns
-1, there is no timeout at all set π
β οΈ important bestie note: an application that uses themulti_socketAPI should not use this function. it should instead use theCURLMOPT_TIMERFUNCTION(3)option for proper and desired behavior. iykyk. π
π Note: if libcurl returns a-1timeout here, it just means that libcurl currently has no stored timeout value. you must not wait too long (more than a few seconds perhaps) before you callcurl_multi_perform(3)again. like do not ghost it for a minute, it will not be iconic. π
π PROTOCOLS π
This functionality affects all supported protocols. every single one. no favorites. π
π¦ EXAMPLE π¦
here's the whole little program, verbatim, because copy-paste is self care:
int main(void)
{
struct timeval timeout;
long timeo;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = 2;
CURLM *multi = curl_multi_init();
curl_multi_timeout(multi, &timeo);
if(timeo < 0)
/* no set timeout, use a default */
timeo = 980;
timeout.tv_sec = timeo / 1000;
timeout.tv_usec = (timeo % 1000) * 1000;
/* wait for activities no longer than the set timeout */
select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
}
see how it handles the -1? timeo = 980 as a default. queen behavior. π
π TYPICAL USAGE π
the classic loop, and it's giving main character energy:
- Call
curl_multi_timeout(3), then wait for action on the sockets. - Figure out which sockets to wait for by calling
curl_multi_fdset(3). - When there is activity or timeout, call
curl_multi_perform(3)and then loop β until all transfers are complete. π
that's the whole routine. honestly obsessed. π
β AVAILABILITY β
Added in curl 7.15.4. vintage but still thriving. π§
π RETURN VALUE π
This function returns a CURLMcode indicating success or error.
CURLM_OK(0) means everything was OK β- non-zero means an error occurred β see
libcurl-errors(3)π¨
π SEE ALSO π
go read them, bestie, they're all part of the same friend group. π«Ά
and that's the page!! brought to you by libcurl, dated 2026-10-12 β the curl_multi_timeout(3) of it all. mwah. ππΈπ
π¦ 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