1CURLINFO_ACTIVESOCKET(3) curl_easy_getinfo options CURLINFO_ACTIVESOCKET(3)
2
3
4
6 CURLINFO_ACTIVESOCKET - get the active socket
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET,
12 curl_socket_t *socket);
13
15 Pass a pointer to a curl_socket_t to receive the active socket used by
16 this curl session. If the socket is no longer valid, CURL_SOCKET_BAD is
17 returned. When you finish working with the socket, you must call
18 curl_easy_cleanup(3) as usual on the easy handle and let libcurl close
19 the socket and cleanup other resources associated with the handle. This
20 is typically used in combination with CURLOPT_CONNECT_ONLY(3).
21
22 This option was added as a replacement for CURLINFO_LASTSOCKET(3) since
23 that one isn't working on all platforms.
24
26 All
27
29 CURL *curl = curl_easy_init();
30 if(curl) {
31 curl_socket_t sockfd;
32 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
33
34 /* Do not do the transfer - only connect to host */
35 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
36 res = curl_easy_perform(curl);
37
38 /* Extract the socket from the curl handle */
39 res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
40
41 if(res != CURLE_OK) {
42 printf("Error: %s\n", curl_easy_strerror(res));
43 return 1;
44 }
45 }
46
48 Added in 7.45.0
49
51 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION
52 if not.
53
55 curl_easy_getinfo(3), curl_easy_setopt(3), CURLINFO_LASTSOCKET(3),
56
57
58
59libcurl 7.64.0 May 06, 2017 CURLINFO_ACTIVESOCKET(3)