CURLOPT_OPENSOCKETDATA.3 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2021, 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. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_OPENSOCKETDATA 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_OPENSOCKETDATA \- pointer passed to open socket callback
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_OPENSOCKETDATA, void *pointer);
  30. .fi
  31. .SH DESCRIPTION
  32. Pass a \fIpointer\fP that will be untouched by libcurl and passed as the first
  33. argument in the opensocket callback set with \fICURLOPT_OPENSOCKETFUNCTION(3)\fP.
  34. .SH DEFAULT
  35. The default value of this parameter is NULL.
  36. .SH PROTOCOLS
  37. All
  38. .SH EXAMPLE
  39. .nf
  40. /* make libcurl use the already established socket 'sockfd' */
  41. static curl_socket_t opensocket(void *clientp,
  42. curlsocktype purpose,
  43. struct curl_sockaddr *address)
  44. {
  45. curl_socket_t sockfd;
  46. sockfd = *(curl_socket_t *)clientp;
  47. /* the actual externally set socket is passed in via the OPENSOCKETDATA
  48. option */
  49. return sockfd;
  50. }
  51. static int sockopt_callback(void *clientp, curl_socket_t curlfd,
  52. curlsocktype purpose)
  53. {
  54. /* This return code was added in libcurl 7.21.5 */
  55. return CURL_SOCKOPT_ALREADY_CONNECTED;
  56. }
  57. curl = curl_easy_init();
  58. if(curl) {
  59. /* libcurl will internally think that you connect to the host
  60. * and port that you specify in the URL option. */
  61. curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
  62. /* call this function to get a socket */
  63. curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
  64. curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
  65. /* call this function to set options for the socket */
  66. curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  67. res = curl_easy_perform(curl);
  68. curl_easy_cleanup(curl);
  69. }
  70. .fi
  71. .SH AVAILABILITY
  72. Added in 7.17.1
  73. .SH RETURN VALUE
  74. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  75. .SH "SEE ALSO"
  76. .BR CURLOPT_OPENSOCKETFUNCTION "(3), " CURLOPT_SOCKOPTFUNCTION "(3), "