1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_NUM_CONNECTS
5Section: 3
6Source: libcurl
7See-also:
8  - curl_easy_getinfo (3)
9  - curl_easy_setopt (3)
10Protocol:
11  - All
12Added-in: 7.12.3
13---
14
15# NAME
16
17CURLINFO_NUM_CONNECTS - get number of created connections
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_NUM_CONNECTS, long *nump);
25~~~
26
27# DESCRIPTION
28
29Pass a pointer to a long to receive how many new connections libcurl had to
30create to achieve the previous transfer (only the successful connects are
31counted). Combined with CURLINFO_REDIRECT_COUNT(3) you are able to know how
32many times libcurl successfully reused existing connection(s) or not. See the
33connection options of curl_easy_setopt(3) to see how libcurl tries to make
34persistent connections to save time.
35
36# %PROTOCOLS%
37
38# EXAMPLE
39
40~~~c
41int 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
64Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
65