curl_multi_add_handle.md (2534B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_multi_add_handle 5 Section: 3 6 Source: libcurl 7 See-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 Protocol: 14 - All 15 Added-in: 7.9.6 16 --- 17 18 # NAME 19 20 curl_multi_add_handle - add an easy handle to a multi session 21 22 # SYNOPSIS 23 24 ~~~c 25 #include <curl/curl.h> 26 27 CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *easy_handle); 28 ~~~ 29 30 # DESCRIPTION 31 32 Adds the *easy handle* to the *multi_handle*. 33 34 While an easy handle is added to a multi stack, you cannot and you must not 35 use curl_easy_perform(3) on that handle. After having removed the easy 36 handle from the multi stack again, it is perfectly fine to use it with the 37 easy interface again. 38 39 If the easy handle is not set to use a shared (CURLOPT_SHARE(3)) cache, 40 it is made to use a DNS cache that is shared between all easy handles within 41 the multi handle when curl_multi_add_handle(3) is called. 42 43 When an easy interface is added to a multi handle, it is set to use a shared 44 connection cache owned by the multi handle. Removing and adding new easy 45 handles does not affect the pool of connections or the ability to do 46 connection reuse. 47 48 If you have CURLMOPT_TIMERFUNCTION(3) set in the multi handle (as you 49 should if you are working event-based with curl_multi_socket_action(3) 50 and friends), that callback is called from within this function to ask for an 51 updated timer so that your main event loop gets the activity on this handle to 52 get started. 53 54 The easy handle remains added to the multi handle until you remove it again 55 with curl_multi_remove_handle(3) - even when a transfer with that 56 specific easy handle is completed. 57 58 You should remove the easy handle from the multi stack before you terminate 59 first the easy handle and then the multi handle: 60 61 1 - curl_multi_remove_handle(3) 62 63 2 - curl_easy_cleanup(3) 64 65 3 - curl_multi_cleanup(3) 66 67 # %PROTOCOLS% 68 69 # EXAMPLE 70 71 ~~~c 72 int 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 91 This function returns a CURLMcode indicating success or error. 92 93 CURLM_OK (0) means everything was OK, non-zero means an error occurred, see 94 libcurl-errors(3).