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

NAME

6       CURLOPT_OPENSOCKETDATA - custom pointer passed to open socket callback
7

SYNOPSIS

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

DESCRIPTION

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

DEFAULT

20       The default value of this parameter is NULL.
21

PROTOCOLS

23       All
24

EXAMPLE

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

AVAILABILITY

64       Added in 7.17.1
65

RETURN VALUE

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

SEE ALSO

71       CURLOPT_OPENSOCKETFUNCTION(3), CURLOPT_SOCKOPTFUNCTION(3),
72
73
74
75libcurl 7.61.1                   May 15, 2017        CURLOPT_OPENSOCKETDATA(3)
Impressum