CURLOPT_OPENSOCKETDATA.3 3.0 KB

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