curl_multi_add_handle(3)
π curl_multi_add_handle(3) π
okay so bestie, welcome to the Library Functions Manual page for curl_multi_add_handle β this is the curl function that adds an easy handle to a multi session. yes that's the whole vibe. let's get into it β¨
β¨ NAME β¨
curl_multi_add_handle β add an easy handle to a multi session π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *easy_handle);
π¦ DESCRIPTION π¦
so what it does: it adds the easy handle to the multi_handle. that's it, that's the whole function. slay π
the biggest rule, no cap: while an easy handle is added to a multi stack, you cannot and you must not use curl_easy_perform(3) on that handle. literally don't. but once you've removed the easy handle from the multi stack again, it is perfectly fine to use it with the easy interface again. so it's not a permanent breakup, it's just a "we need space" era π
if the easy handle is not set to use a shared (CURLOPT_SHARE(3)) cache, then it gets made to use a DNS cache that's shared between all easy handles within the multi handle β and this happens when curl_multi_add_handle(3) is called. so the DNS knowledge gets pooled together, cute π
when an easy interface is added to a multi handle, it is set to use a shared connection cache owned by the multi handle. and because of that, removing and adding new easy handles does not affect the pool of connections or the ability to do connection reuse. connection reuse stays iconic, periodt π₯
if you have CURLMOPT_TIMERFUNCTION(3) set in the multi handle β and you should if you're working event-based with curl_multi_socket_action(3) and friends β that callback is called from within this function to ask for an updated timer, so that your main event loop gets the activity on this handle to get started. main character energy from a callback, honestly π
the easy handle remains added to the multi handle until you remove it again with curl_multi_remove_handle(3) β even when a transfer with that specific easy handle is completed. like, it does not quietly leave the group chat on its own. you have to remove it. π
and you should remove the easy handle from the multi stack before you terminate first the easy handle and then the multi handle. the order is literally:
bestie please respect the order. cleanup out of order is not the vibe π
π PROTOCOLS π
this functionality affects all supported protocols. all of them. every single one. we love an inclusive king π
π EXAMPLE π
int main(void)
{
/* init a multi stack */
CURLM *multi = curl_multi_init();
/* create two easy handles */
CURL *http_handle = curl_easy_init();
CURL *http_handle2 = curl_easy_init();
/* add individual transfers */
curl_multi_add_handle(multi, http_handle);
curl_multi_add_handle(multi, http_handle2);
}
two easy handles, one multi, added individually. it's giving teamwork π€β¨
β AVAILABILITY β
Added in curl 7.9.6 β an elder icon at this point, honestly π
π RETURN VALUE π
this function returns a CURLMcode indicating success or error.
CURLM_OK (0) means everything was OK. non-zero means an error occurred β go check libcurl-errors(3) for the tea π
πΈ SEE ALSO πΈ
curl_multi_cleanup(3)curl_multi_get_handles(3)curl_multi_init(3)curl_multi_setopt(3)curl_multi_socket_action(3)
okay that's the page!! π«Ά this was libcurl, dated 2026-10-12, and you were reading curl_multi_add_handle(3) β go add those handles bestie, and remember: no curl_easy_perform(3) on a handle that's in a multi stack. iykyk π
β¨π
π¦ 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