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 is called, 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       function  gets  status updates with changes since the previous time the
27       callback was called. If the given callback pointer is set to  NULL,  no
28       callback will be called.
29

CALLBACK ARGUMENTS

31       easy identifies the specific transfer for which this update is related.
32
33       s is the specific socket this function invocation concerns. If the what
34       argument is not CURL_POLL_REMOVE then it holds information  about  what
35       activity  on this socket the application is supposed to monitor. Subse‐
36       quent calls to this callback might update the what bits  for  a  socket
37       that is already monitored.
38
39       userp is set with CURLMOPT_SOCKETDATA(3).
40
41       socketp is set with curl_multi_assign(3) or will be NULL.
42
43       The  what  parameter  informs  the  callback on the status of the given
44       socket. It can hold one of these values:
45
46       CURL_POLL_IN
47              Wait for incoming data. For the socket to become readable.
48
49       CURL_POLL_OUT
50              Wait for outgoing data. For the socket to become writable.
51
52       CURL_POLL_INOUT
53              Wait for incoming and outgoing data. For the  socket  to  become
54              readable or writable.
55
56       CURL_POLL_REMOVE
57              The  specified  socket/file  descriptor  is  no  longer  used by
58              libcurl.
59

DEFAULT

61       NULL (no callback)
62

PROTOCOLS

64       All
65

EXAMPLE

67       static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
68       {
69         GlobalInfo *g = (GlobalInfo*) cbp;
70         SockInfo *fdp = (SockInfo*) sockp;
71
72         if(what == CURL_POLL_REMOVE) {
73           remsock(fdp);
74         }
75         else {
76           if(!fdp) {
77             addsock(s, e, what, g);
78           }
79           else {
80             setsock(fdp, s, e, what, g);
81           }
82         }
83         return 0;
84       }
85
86       main()
87       {
88         GlobalInfo setup;
89         /* ... use socket callback and custom pointer */
90         curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
91         curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
92       }
93

AVAILABILITY

95       Added in 7.15.4
96

RETURN VALUE

98       Returns CURLM_OK.
99

SEE ALSO

101       CURLMOPT_SOCKETDATA(3),  curl_multi_socket_action(3),   CURLMOPT_TIMER‐
102       FUNCTION(3)
103
104
105
106libcurl 7.66.0                   June 24, 2019      CURLMOPT_SOCKETFUNCTION(3)
Impressum