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