1CURLOPT_OPENSOCKETDATA(3)  curl_easy_setopt options  CURLOPT_OPENSOCKETDATA(3)
2
3
4

NAME

6       CURLOPT_OPENSOCKETDATA - pointer passed to open socket callback
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_OPENSOCKETDATA, void *pointer);
12

DESCRIPTION

14       Pass  a  pointer  that  will  be untouched by libcurl and passed as the
15       first argument in the opensocket callback set with  CURLOPT_OPENSOCKETā€
16       FUNCTION(3).
17

DEFAULT

19       The default value of this parameter is NULL.
20

PROTOCOLS

22       All
23

EXAMPLE

25       /* make libcurl use the already established socket 'sockfd' */
26
27       static curl_socket_t opensocket(void *clientp,
28                                       curlsocktype purpose,
29                                       struct curl_sockaddr *address)
30       {
31         curl_socket_t sockfd;
32         sockfd = *(curl_socket_t *)clientp;
33         /* the actual externally set socket is passed in via the OPENSOCKETDATA
34            option */
35         return sockfd;
36       }
37
38       static int sockopt_callback(void *clientp, curl_socket_t curlfd,
39                                   curlsocktype purpose)
40       {
41         /* This return code was added in libcurl 7.21.5 */
42         return CURL_SOCKOPT_ALREADY_CONNECTED;
43       }
44
45       curl = curl_easy_init();
46       if(curl) {
47         /* libcurl will internally think that you connect to the host
48          * and port that you specify in the URL option. */
49         curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999");
50         /* call this function to get a socket */
51         curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket);
52         curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd);
53
54         /* call this function to set options for the socket */
55         curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
56
57         res = curl_easy_perform(curl);
58
59         curl_easy_cleanup(curl);
60       }
61

AVAILABILITY

63       Added in 7.17.1
64

RETURN VALUE

66       Returns  CURLE_OK  if the option is supported, and CURLE_UNKNOWN_OPTION
67       if not.
68

SEE ALSO

70       CURLOPT_OPENSOCKETFUNCTION(3), CURLOPT_SOCKOPTFUNCTION(3),
71
72
73
74libcurl 7.85.0                   May 17, 2022        CURLOPT_OPENSOCKETDATA(3)
Impressum