CURLINFO_LASTSOCKET.3 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. .\" generated by cd2nroff 0.1 from CURLINFO_LASTSOCKET.md
  2. .TH CURLINFO_LASTSOCKET 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_LASTSOCKET \- get the last socket used
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LASTSOCKET, long *socket);
  9. .fi
  10. .SH DESCRIPTION
  11. Deprecated since 7.45.0. Use \fICURLINFO_ACTIVESOCKET(3)\fP instead.
  12. Pass a pointer to a long to receive the last socket used by this curl
  13. session. If the socket is no longer valid, \-1 is returned. When you finish
  14. working with the socket, you must call \fIcurl_easy_cleanup(3)\fP as usual and
  15. let libcurl close the socket and cleanup other resources associated with the
  16. handle. This is typically used in combination with
  17. \fICURLOPT_CONNECT_ONLY(3)\fP.
  18. NOTE: this API is deprecated since it is not working on win64 where the SOCKET
  19. type is 64 bits large while its \(aqlong\(aq is 32 bits. Use the
  20. \fICURLINFO_ACTIVESOCKET(3)\fP instead, if possible.
  21. .SH PROTOCOLS
  22. This functionality affects all supported protocols
  23. .SH EXAMPLE
  24. .nf
  25. int main(void)
  26. {
  27. CURL *curl = curl_easy_init();
  28. if(curl) {
  29. CURLcode res;
  30. long sockfd; /* does not work on win64! */
  31. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  32. /* Do not do the transfer - only connect to host */
  33. curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
  34. res = curl_easy_perform(curl);
  35. if(res != CURLE_OK) {
  36. printf("Error: %s\\n", curl_easy_strerror(res));
  37. curl_easy_cleanup(curl);
  38. return 1;
  39. }
  40. /* Extract the socket from the curl handle */
  41. res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
  42. if(!res && sockfd != -1) {
  43. /* operate on sockfd */
  44. }
  45. curl_easy_cleanup(curl);
  46. }
  47. }
  48. .fi
  49. .SH AVAILABILITY
  50. Added in curl 7.15.2
  51. .SH RETURN VALUE
  52. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  53. .SH SEE ALSO
  54. .BR CURLINFO_ACTIVESOCKET (3),
  55. .BR CURLOPT_CONNECT_ONLY (3),
  56. .BR curl_easy_getinfo (3),
  57. .BR curl_easy_setopt (3)