CURLOPT_OPENSOCKETDATA.3 3.0 KB

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