1 .\" **************************************************************************
3 .\" * Project ___| | | | _ \| |
4 .\" * / __| | | | |_) | |
5 .\" * | (__| |_| | _ <| |___
6 .\" * \___|\___/|_| \_\_____|
8 .\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
21 .\" **************************************************************************
23 .TH CURLOPT_OPENSOCKETDATA 3 "May 15, 2017" "libcurl 7.59.0" "curl_easy_setopt options"
26 CURLOPT_OPENSOCKETDATA \- custom pointer passed to open socket callback
28 #include <curl/curl.h>
30 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_OPENSOCKETDATA, void *pointer);
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.
35 The default value of this parameter is NULL.
40 /* make libcurl use the already established socket 'sockfd' */
42 static curl_socket_t opensocket(void *clientp,
44 struct curl_sockaddr *address)
47 sockfd = *(curl_socket_t *)clientp;
48 /* the actual externally set socket is passed in via the OPENSOCKETDATA
53 static int sockopt_callback(void *clientp, curl_socket_t curlfd,
56 /* This return code was added in libcurl 7.21.5 */
57 return CURL_SOCKOPT_ALREADY_CONNECTED;
60 curl = curl_easy_init();
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);
69 /* call this function to set options for the socket */
70 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
72 res = curl_easy_perform(curl);
74 curl_easy_cleanup(curl);
80 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
82 .BR CURLOPT_OPENSOCKETFUNCTION "(3), " CURLOPT_SOCKOPTFUNCTION "(3), "