1curl_multi_socket(3) libcurl Manual curl_multi_socket(3)
2
3
4
6 curl_multi_socket - reads/writes available data
7
9 #include <curl/curl.h>
10 CURLMcode curl_multi_socket(CURLM * multi_handle, curl_socket_t sockfd,
11 int *running_handles);
12
13 CURLMcode curl_multi_socket_all(CURLM *multi_handle,
14 int *running_handles);
15
17 These functions are deprecated. Do not use! See
18 curl_multi_socket_action(3) instead!
19
20 At return, the integer running_handles points to will contain the num‐
21 ber of still running easy handles within the multi handle. When this
22 number reaches zero, all transfers are complete/done. Note that when
23 you call curl_multi_socket_action(3) on a specific socket and the
24 counter decreases by one, it DOES NOT necessarily mean that this exact
25 socket/transfer is the one that completed. Use curl_multi_info_read(3)
26 to figure out which easy handle that completed.
27
28 The curl_multi_socket_action(3) functions inform the application about
29 updates in the socket (file descriptor) status by doing none, one, or
30 multiple calls to the socket callback function set with the CURL‐
31 MOPT_SOCKETFUNCTION(3) option to curl_multi_setopt(3). They update the
32 status with changes since the previous time the callback was called.
33
34 Get the timeout time by setting the CURLMOPT_TIMERFUNCTION(3) option
35 with curl_multi_setopt(3). Your application will then get called with
36 information on how long to wait for socket actions at most before doing
37 the timeout action: call the curl_multi_socket_action(3) function with
38 the sockfd argument set to CURL_SOCKET_TIMEOUT. You can also use the
39 curl_multi_timeout(3) function to poll the value at any given time, but
40 for an event-based system using the callback is far better than relying
41 on polling the timeout value.
42
43 Usage of curl_multi_socket(3) is deprecated, whereas the function is
44 equivalent to curl_multi_socket_action(3) with ev_bitmask set to 0.
45
46 Force libcurl to (re-)check all its internal sockets and transfers
47 instead of just a single one by calling curl_multi_socket_all(3). Note
48 that there should not be any reason to use this function!
49
51 The socket callback function uses a prototype like this
52
53 int curl_socket_callback(CURL *easy, /* easy handle */
54 curl_socket_t s, /* socket */
55 int action, /* see values below */
56 void *userp, /* private callback pointer */
57 void *socketp); /* private socket pointer */
58
59 The callback MUST return 0.
60
61 The easy argument is a pointer to the easy handle that deals with this
62 particular socket. Note that a single handle may work with several
63 sockets simultaneously.
64
65 The s argument is the actual socket value as you use it within your
66 system.
67
68 The action argument to the callback has one of five values:
69
70 CURL_POLL_NONE (0)
71 register, not interested in readiness (yet)
72
73 CURL_POLL_IN (1)
74 register, interested in read readiness
75
76 CURL_POLL_OUT (2)
77 register, interested in write readiness
78
79 CURL_POLL_INOUT (3)
80 register, interested in both read and write readiness
81
82 CURL_POLL_REMOVE (4)
83 unregister
84
85 The socketp argument is a private pointer you have previously set with
86 curl_multi_assign(3) to be associated with the s socket. If no pointer
87 has been set, socketp will be NULL. This argument is of course a ser‐
88 vice to applications that want to keep certain data or structs that are
89 strictly associated to the given socket.
90
91 The userp argument is a private pointer you have previously set with
92 curl_multi_setopt(3) and the CURLMOPT_SOCKETDATA(3) option.
93
95 CURLMcode type, general libcurl multi interface error code.
96
97 Legacy: If you receive CURLM_CALL_MULTI_PERFORM, this basically means
98 that you should call curl_multi_socket(3) again, before you wait for
99 more actions on libcurl's sockets. You don't have to do it immediately,
100 but the return code means that libcurl may have more data available to
101 return or that there may be more data to send off before it is "satis‐
102 fied".
103
104 In modern libcurls, CURLM_CALL_MULTI_PERFORM or CURLM_CALL_MULTI_SOCKET
105 should not be returned and no application needs to care about them.
106
107 NOTE that the return code is for the whole multi stack. Problems still
108 might have occurred on individual transfers even when one of these
109 functions return OK.
110
112 1. Create a multi handle
113
114 2. Set the socket callback with CURLMOPT_SOCKETFUNCTION(3)
115
116 3. Set the timeout callback with CURLMOPT_TIMERFUNCTION(3), to get to
117 know what timeout value to use when waiting for socket activities.
118
119 4. Add easy handles with curl_multi_add_handle()
120
121 5. Provide some means to manage the sockets libcurl is using, so you
122 can check them for activity. This can be done through your application
123 code, or by way of an external library such as libevent or glib.
124
125 6. Wait for activity on any of libcurl's sockets, use the timeout value
126 your callback has been told
127
128 7, When activity is detected, call curl_multi_socket_action() for the
129 socket(s) that got action. If no activity is detected and the timeout
130 expires, call curl_multi_socket_action(3) with CURL_SOCKET_TIMEOUT
131
132 8. Go back to step 6.
133
135 This function was added in libcurl 7.15.4, and is deemed stable since
136 7.16.0.
137
138 curl_multi_socket(3) is deprecated, use curl_multi_socket_action(3)
139 instead!
140
142 curl_multi_cleanup(3), curl_multi_init(3), curl_multi_fdset(3),
143 curl_multi_info_read(3), the hiperfifo.c example
144
145
146
147libcurl 7.64.0 June 30, 2018 curl_multi_socket(3)