1CURLMOPT_SOCKETFUNCTION(3) curl_multi_setopt optionsCURLMOPT_SOCKETFUNCTION(3)
2
3
4

NAME

6       CURLMOPT_SOCKETFUNCTION - callback informed about what to wait for
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       int socket_callback(CURL *easy,      /* easy handle */
12                           curl_socket_t s, /* socket */
13                           int what,        /* describes the socket */
14                           void *userp,     /* private callback pointer */
15                           void *socketp);  /* private socket pointer */
16
17       CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETFUNCTION, socket_callback);
18

DESCRIPTION

20       Pass a pointer to your callback function, which should match the proto‐
21       type shown above.
22
23       When the curl_multi_socket_action(3)  function  runs,  it  informs  the
24       application  about  updates  in  the socket (file descriptor) status by
25       doing none, one, or multiple calls to the socket_callback. The callback
26       gets  status  updates with changes since the previous time the callback
27       was called.  If the given callback pointer is NULL, no callback will be
28       called.  Set the callback's userp argument with CURLMOPT_SOCKETDATA(3).
29       See curl_multi_socket_action(3) for more details on how the callback is
30       used and should work.
31
32       The  what  parameter  informs  the  callback on the status of the given
33       socket. It can hold one of these values:
34
35       CURL_POLL_IN
36              Wait for incoming data. For the socket to become readable.
37
38       CURL_POLL_OUT
39              Wait for outgoing data. For the socket to become writable.
40
41       CURL_POLL_INOUT
42              Wait for incoming and outgoing data. For the  socket  to  become
43              readable or writable.
44
45       CURL_POLL_REMOVE
46              The  specified  socket/file  descriptor  is  no  longer  used by
47              libcurl.
48

DEFAULT

50       NULL (no callback)
51

PROTOCOLS

53       All
54

EXAMPLE

56       static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
57       {
58         GlobalInfo *g = (GlobalInfo*) cbp;
59         SockInfo *fdp = (SockInfo*) sockp;
60
61         if(what == CURL_POLL_REMOVE) {
62           remsock(fdp);
63         }
64         else {
65           if(!fdp) {
66             addsock(s, e, what, g);
67           }
68           else {
69             setsock(fdp, s, e, what, g);
70           }
71         }
72         return 0;
73       }
74
75       main()
76       {
77         GlobalInfo setup;
78         /* ... use socket callback and custom pointer */
79         curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
80         curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
81       }
82

AVAILABILITY

84       Added in 7.15.4
85

RETURN VALUE

87       Returns CURLM_OK.
88

SEE ALSO

90       CURLMOPT_SOCKETDATA(3),  curl_multi_socket_action(3),   CURLMOPT_TIMER‐
91       FUNCTION(3)
92
93
94
95libcurl 7.64.0                September 23, 2018    CURLMOPT_SOCKETFUNCTION(3)
Impressum