2
0

CURLINFO_ACTIVESOCKET.3 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLINFO_ACTIVESOCKET 3 "12 Sep 2015" "libcurl" "libcurl"
  26. .SH NAME
  27. CURLINFO_ACTIVESOCKET \- get the active socket
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET,
  32. curl_socket_t *socket);
  33. .fi
  34. .SH DESCRIPTION
  35. Pass a pointer to a curl_socket_t to receive the most recently active socket
  36. used for the transfer connection by this curl session. If the socket is no
  37. longer valid, \fICURL_SOCKET_BAD\fP is returned. When you are finished working
  38. with the socket, you must call \fIcurl_easy_cleanup(3)\fP as usual on the easy
  39. handle and let libcurl close the socket and cleanup other resources associated
  40. with the handle. This option returns the active socket only after the transfer
  41. is complete, and is typically used in combination with
  42. \fICURLOPT_CONNECT_ONLY(3)\fP, which skips the transfer phase.
  43. \fICURLINFO_ACTIVESOCKET(3)\fP was added as a replacement for
  44. \fICURLINFO_LASTSOCKET(3)\fP since that one is not working on all platforms.
  45. .SH PROTOCOLS
  46. All
  47. .SH EXAMPLE
  48. .nf
  49. CURL *curl = curl_easy_init();
  50. if(curl) {
  51. curl_socket_t sockfd;
  52. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  53. /* Do not do the transfer - only connect to host */
  54. curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
  55. res = curl_easy_perform(curl);
  56. /* Extract the socket from the curl handle */
  57. res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
  58. if(res != CURLE_OK) {
  59. printf("Error: %s\\n", curl_easy_strerror(res));
  60. return 1;
  61. }
  62. }
  63. .fi
  64. .SH AVAILABILITY
  65. Added in 7.45.0
  66. .SH RETURN VALUE
  67. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  68. .SH "SEE ALSO"
  69. .BR curl_easy_getinfo "(3), " curl_easy_setopt "(3), "
  70. .BR CURLINFO_LASTSOCKET "(3), "