xref: /curl/docs/libcurl/opts/CURLINFO_CONN_ID.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_CONN_ID
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_XFER_ID (3)
9  - curl_easy_getinfo (3)
10  - curl_easy_setopt (3)
11Protocol:
12  - All
13Added-in: 8.2.0
14---
15
16# NAME
17
18CURLINFO_CONN_ID - get the ID of the last connection used by the handle
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CONN_ID,
26                           curl_off_t *conn_id);
27~~~
28
29# DESCRIPTION
30
31Pass a pointer to a *curl_off_t* to receive the connection identifier last
32used by the handle. Stores -1 if there was no connection used.
33
34The connection id is unique among all connections using the same
35connection cache. This is implicitly the case for all connections in the
36same multi handle.
37
38# %PROTOCOLS%
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *curl = curl_easy_init();
46  if(curl) {
47    CURLcode res;
48
49    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
50
51    /* Perform the request */
52    res = curl_easy_perform(curl);
53
54    if(!res) {
55      curl_off_t conn_id;
56      res = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
57      if(!res) {
58        printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\n", conn_id);
59      }
60    }
61  }
62}
63~~~
64
65# %AVAILABILITY%
66
67# RETURN VALUE
68
69Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
70