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 do‐
25       ing 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       The  socket  callback  should  return 0 on success, and -1 on error. If
40       this callback returns error, all transfers  currently  in  progress  in
41       this multi handle will be aborted and fail.
42
43       userp is set with CURLMOPT_SOCKETDATA(3).
44
45       socketp is set with curl_multi_assign(3) or will be NULL.
46
47       The  what  parameter  informs  the  callback on the status of the given
48       socket. It can hold one of these values:
49
50       CURL_POLL_IN
51              Wait for incoming data. For the socket to become readable.
52
53       CURL_POLL_OUT
54              Wait for outgoing data. For the socket to become writable.
55
56       CURL_POLL_INOUT
57              Wait for incoming and outgoing data. For the  socket  to  become
58              readable or writable.
59
60       CURL_POLL_REMOVE
61              The  specified  socket/file  descriptor  is  no  longer  used by
62              libcurl.
63

DEFAULT

65       NULL (no callback)
66

PROTOCOLS

68       All
69

EXAMPLE

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

AVAILABILITY

99       Added in 7.15.4
100

RETURN VALUE

102       Returns CURLM_OK.
103

SEE ALSO

105       CURLMOPT_SOCKETDATA(3),  curl_multi_socket_action(3),   CURLMOPT_TIMER‐
106       FUNCTION(3)
107
108
109
110libcurl 7.85.0                   May 17, 2022       CURLMOPT_SOCKETFUNCTION(3)
Impressum