1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_multi_add_handle 5Section: 3 6Source: libcurl 7See-also: 8 - curl_multi_cleanup (3) 9 - curl_multi_get_handles (3) 10 - curl_multi_init (3) 11 - curl_multi_setopt (3) 12 - curl_multi_socket_action (3) 13--- 14 15# NAME 16 17curl_multi_add_handle - add an easy handle to a multi session 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *easy_handle); 25~~~ 26 27# DESCRIPTION 28 29Adds the *easy handle* to the *multi_handle*. 30 31While an easy handle is added to a multi stack, you cannot and you must not 32use curl_easy_perform(3) on that handle. After having removed the easy 33handle from the multi stack again, it is perfectly fine to use it with the 34easy interface again. 35 36If the easy handle is not set to use a shared (CURLOPT_SHARE(3)) cache, 37it is made to use a DNS cache that is shared between all easy handles within 38the multi handle when curl_multi_add_handle(3) is called. 39 40When an easy interface is added to a multi handle, it is set to use a shared 41connection cache owned by the multi handle. Removing and adding new easy 42handles does not affect the pool of connections or the ability to do 43connection reuse. 44 45If you have CURLMOPT_TIMERFUNCTION(3) set in the multi handle (as you 46should if you are working event-based with curl_multi_socket_action(3) 47and friends), that callback is called from within this function to ask for an 48updated timer so that your main event loop gets the activity on this handle to 49get started. 50 51The easy handle remains added to the multi handle until you remove it again 52with curl_multi_remove_handle(3) - even when a transfer with that 53specific easy handle is completed. 54 55You should remove the easy handle from the multi stack before you terminate 56first the easy handle and then the multi handle: 57 581 - curl_multi_remove_handle(3) 59 602 - curl_easy_cleanup(3) 61 623 - curl_multi_cleanup(3) 63 64# EXAMPLE 65 66~~~c 67int main(void) 68{ 69 /* init a multi stack */ 70 CURLM *multi = curl_multi_init(); 71 72 /* create two easy handles */ 73 CURL *http_handle = curl_easy_init(); 74 CURL *http_handle2 = curl_easy_init(); 75 76 /* add individual transfers */ 77 curl_multi_add_handle(multi, http_handle); 78 curl_multi_add_handle(multi, http_handle2); 79} 80~~~ 81 82# AVAILABILITY 83 84Added in 7.9.6 85 86# RETURN VALUE 87 88CURLMcode type, general libcurl multi interface error code. 89