CURLOPT_MAXCONNECTS.md (1906B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_MAXCONNECTS 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLMOPT_MAXCONNECTS (3) 9 - CURLMOPT_MAX_HOST_CONNECTIONS (3) 10 - CURLMOPT_MAX_TOTAL_CONNECTIONS (3) 11 - CURLOPT_MAXREDIRS (3) 12 Protocol: 13 - All 14 Added-in: 7.7 15 --- 16 17 # NAME 18 19 CURLOPT_MAXCONNECTS - maximum connection cache size 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXCONNECTS, long amount); 27 ~~~ 28 29 # DESCRIPTION 30 31 Pass a long. The set *amount* is the maximum number of connections that 32 libcurl may keep alive in its connection cache after use. The default is 5, 33 and there is not much point in changing this value unless you are perfectly 34 aware of how this works. This concerns connections using any of the protocols 35 that support persistent connections. 36 37 When reaching the maximum limit, curl closes the oldest connection present in 38 the cache to prevent the number of connections from increasing. 39 40 If you already have performed transfers with this curl handle, setting a 41 smaller CURLOPT_MAXCONNECTS(3) than before may cause open connections to get 42 closed unnecessarily. 43 44 If you add this easy handle to a multi handle, this setting is not 45 acknowledged, and you must instead use curl_multi_setopt(3) and the 46 CURLMOPT_MAXCONNECTS(3) option. 47 48 # DEFAULT 49 50 5 51 52 # %PROTOCOLS% 53 54 # EXAMPLE 55 56 ~~~c 57 int main(void) 58 { 59 CURL *curl = curl_easy_init(); 60 if(curl) { 61 CURLcode ret; 62 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 63 /* limit the connection cache for this handle to no more than 3 */ 64 curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L); 65 ret = curl_easy_perform(curl); 66 } 67 } 68 ~~~ 69 70 # %AVAILABILITY% 71 72 # RETURN VALUE 73 74 curl_easy_setopt(3) returns a CURLcode indicating success or error. 75 76 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 77 libcurl-errors(3).