CURLINFO_NUM_CONNECTS.md (1571B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLINFO_NUM_CONNECTS 5 Section: 3 6 Source: libcurl 7 See-also: 8 - curl_easy_getinfo (3) 9 - curl_easy_setopt (3) 10 Protocol: 11 - All 12 Added-in: 7.12.3 13 --- 14 15 # NAME 16 17 CURLINFO_NUM_CONNECTS - get number of created connections 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_NUM_CONNECTS, long *nump); 25 ~~~ 26 27 # DESCRIPTION 28 29 Pass a pointer to a long to receive how many new connections libcurl had to 30 create to achieve the previous transfer (only the successful connects are 31 counted). Combined with CURLINFO_REDIRECT_COUNT(3) you are able to know how 32 many times libcurl successfully reused existing connection(s) or not. See the 33 connection options of curl_easy_setopt(3) to see how libcurl tries to make 34 persistent connections to save time. 35 36 # %PROTOCOLS% 37 38 # EXAMPLE 39 40 ~~~c 41 int main(void) 42 { 43 CURL *curl = curl_easy_init(); 44 if(curl) { 45 CURLcode res; 46 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 47 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 48 res = curl_easy_perform(curl); 49 if(res == CURLE_OK) { 50 long connects; 51 res = curl_easy_getinfo(curl, CURLINFO_NUM_CONNECTS, &connects); 52 if(!res) 53 printf("It needed %ld connects\n", connects); 54 } 55 curl_easy_cleanup(curl); 56 } 57 } 58 ~~~ 59 60 # %AVAILABILITY% 61 62 # RETURN VALUE 63 64 curl_easy_getinfo(3) returns a CURLcode indicating success or error. 65 66 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 67 libcurl-errors(3).