1CURLINFO_ACTIVESOCKET(3)   curl_easy_getinfo options  CURLINFO_ACTIVESOCKET(3)
2
3
4

NAME

6       CURLINFO_ACTIVESOCKET - get the active socket
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET,
12                                  curl_socket_t *socket);
13

DESCRIPTION

15       Pass  a  pointer to a curl_socket_t to receive the most recently active
16       socket used for the transfer connection by this curl  session.  If  the
17       socket  is  no  longer valid, CURL_SOCKET_BAD is returned. When you are
18       finished working with the socket, you must call curl_easy_cleanup(3) as
19       usual  on  the easy handle and let libcurl close the socket and cleanup
20       other resources associated with the handle. This option returns the ac‐
21       tive  socket only after the transfer is complete, and is typically used
22       in combination with CURLOPT_CONNECT_ONLY(3), which skips  the  transfer
23       phase.
24
25       CURLINFO_ACTIVESOCKET(3)  was added as a replacement for CURLINFO_LAST‐
26       SOCKET(3) since that one is not working on all platforms.
27

PROTOCOLS

29       All
30

EXAMPLE

32       CURL *curl = curl_easy_init();
33       if(curl) {
34         curl_socket_t sockfd;
35         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
36
37         /* Do not do the transfer - only connect to host */
38         curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
39         res = curl_easy_perform(curl);
40
41         /* Extract the socket from the curl handle */
42         res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
43
44         if(res != CURLE_OK) {
45           printf("Error: %s\n", curl_easy_strerror(res));
46           return 1;
47         }
48       }
49

AVAILABILITY

51       Added in 7.45.0
52

RETURN VALUE

54       Returns CURLE_OK if the option is supported,  and  CURLE_UNKNOWN_OPTION
55       if not.
56

SEE ALSO

58       curl_easy_getinfo(3), curl_easy_setopt(3), CURLINFO_LASTSOCKET(3),
59
60
61
62libcurl 7.82.0                 November 26, 2021      CURLINFO_ACTIVESOCKET(3)
Impressum