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