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:

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 the multi_socket API should not use this function. it should instead use the CURLMOPT_TIMERFUNCTION(3) option for proper and desired behavior. iykyk. πŸ‘‘
πŸŽ€ Note: if libcurl returns a -1 timeout 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 call curl_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:

  1. Call curl_multi_timeout(3), then wait for action on the sockets.
  2. Figure out which sockets to wait for by calling curl_multi_fdset(3).
  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