1 | #ifndef CURLINC_MULTI_H |
2 | #define CURLINC_MULTI_H |
3 | /*************************************************************************** |
4 | * _ _ ____ _ |
5 | * Project ___| | | | _ \| | |
6 | * / __| | | | |_) | | |
7 | * | (__| |_| | _ <| |___ |
8 | * \___|\___/|_| \_\_____| |
9 | * |
10 | * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | * |
12 | * This software is licensed as described in the file COPYING, which |
13 | * you should have received as part of this distribution. The terms |
14 | * are also available at https://curl.se/docs/copyright.html. |
15 | * |
16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | * copies of the Software, and permit persons to whom the Software is |
18 | * furnished to do so, under the terms of the COPYING file. |
19 | * |
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | * KIND, either express or implied. |
22 | * |
23 | ***************************************************************************/ |
24 | /* |
25 | This is an "external" header file. Don't give away any internals here! |
26 | |
27 | GOALS |
28 | |
29 | o Enable a "pull" interface. The application that uses libcurl decides where |
30 | and when to ask libcurl to get/send data. |
31 | |
32 | o Enable multiple simultaneous transfers in the same thread without making it |
33 | complicated for the application. |
34 | |
35 | o Enable the application to select() on its own file descriptors and curl's |
36 | file descriptors simultaneous easily. |
37 | |
38 | */ |
39 | |
40 | /* |
41 | * This header file should not really need to include "curl.h" since curl.h |
42 | * itself includes this file and we expect user applications to do #include |
43 | * <curl/curl.h> without the need for especially including multi.h. |
44 | * |
45 | * For some reason we added this include here at one point, and rather than to |
46 | * break existing (wrongly written) libcurl applications, we leave it as-is |
47 | * but with this warning attached. |
48 | */ |
49 | #include "curl.h" |
50 | |
51 | #ifdef __cplusplus |
52 | extern "C" { |
53 | #endif |
54 | |
55 | #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) |
56 | typedef struct Curl_multi CURLM; |
57 | #else |
58 | typedef void CURLM; |
59 | #endif |
60 | |
61 | typedef enum { |
62 | CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or |
63 | curl_multi_socket*() soon */ |
64 | CURLM_OK, |
65 | CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ |
66 | CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ |
67 | CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ |
68 | CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ |
69 | CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ |
70 | CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ |
71 | CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was |
72 | attempted to get added - again */ |
73 | CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a |
74 | callback */ |
75 | CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */ |
76 | CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */ |
77 | CURLM_ABORTED_BY_CALLBACK, |
78 | CURLM_LAST |
79 | } CURLMcode; |
80 | |
81 | /* just to make code nicer when using curl_multi_socket() you can now check |
82 | for CURLM_CALL_MULTI_SOCKET too in the same style it works for |
83 | curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ |
84 | #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM |
85 | |
86 | /* bitmask bits for CURLMOPT_PIPELINING */ |
87 | #define CURLPIPE_NOTHING 0L |
88 | #define CURLPIPE_HTTP1 1L |
89 | #define CURLPIPE_MULTIPLEX 2L |
90 | |
91 | typedef enum { |
92 | CURLMSG_NONE, /* first, not used */ |
93 | CURLMSG_DONE, /* This easy handle has completed. 'result' contains |
94 | the CURLcode of the transfer */ |
95 | CURLMSG_LAST /* last, not used */ |
96 | } CURLMSG; |
97 | |
98 | struct CURLMsg { |
99 | CURLMSG msg; /* what this message means */ |
100 | CURL *easy_handle; /* the handle it concerns */ |
101 | union { |
102 | void *whatever; /* message-specific data */ |
103 | CURLcode result; /* return code for transfer */ |
104 | } data; |
105 | }; |
106 | typedef struct CURLMsg CURLMsg; |
107 | |
108 | /* Based on poll(2) structure and values. |
109 | * We don't use pollfd and POLL* constants explicitly |
110 | * to cover platforms without poll(). */ |
111 | #define CURL_WAIT_POLLIN 0x0001 |
112 | #define CURL_WAIT_POLLPRI 0x0002 |
113 | #define CURL_WAIT_POLLOUT 0x0004 |
114 | |
115 | struct curl_waitfd { |
116 | curl_socket_t fd; |
117 | short events; |
118 | short revents; /* not supported yet */ |
119 | }; |
120 | |
121 | /* |
122 | * Name: curl_multi_init() |
123 | * |
124 | * Desc: inititalize multi-style curl usage |
125 | * |
126 | * Returns: a new CURLM handle to use in all 'curl_multi' functions. |
127 | */ |
128 | CURL_EXTERN CURLM *curl_multi_init(void); |
129 | |
130 | /* |
131 | * Name: curl_multi_add_handle() |
132 | * |
133 | * Desc: add a standard curl handle to the multi stack |
134 | * |
135 | * Returns: CURLMcode type, general multi error code. |
136 | */ |
137 | CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, |
138 | CURL *curl_handle); |
139 | |
140 | /* |
141 | * Name: curl_multi_remove_handle() |
142 | * |
143 | * Desc: removes a curl handle from the multi stack again |
144 | * |
145 | * Returns: CURLMcode type, general multi error code. |
146 | */ |
147 | CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, |
148 | CURL *curl_handle); |
149 | |
150 | /* |
151 | * Name: curl_multi_fdset() |
152 | * |
153 | * Desc: Ask curl for its fd_set sets. The app can use these to select() or |
154 | * poll() on. We want curl_multi_perform() called as soon as one of |
155 | * them are ready. |
156 | * |
157 | * Returns: CURLMcode type, general multi error code. |
158 | */ |
159 | CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, |
160 | fd_set *read_fd_set, |
161 | fd_set *write_fd_set, |
162 | fd_set *exc_fd_set, |
163 | int *max_fd); |
164 | |
165 | /* |
166 | * Name: curl_multi_wait() |
167 | * |
168 | * Desc: Poll on all fds within a CURLM set as well as any |
169 | * additional fds passed to the function. |
170 | * |
171 | * Returns: CURLMcode type, general multi error code. |
172 | */ |
173 | CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, |
174 | struct curl_waitfd [], |
175 | unsigned int , |
176 | int timeout_ms, |
177 | int *ret); |
178 | |
179 | /* |
180 | * Name: curl_multi_poll() |
181 | * |
182 | * Desc: Poll on all fds within a CURLM set as well as any |
183 | * additional fds passed to the function. |
184 | * |
185 | * Returns: CURLMcode type, general multi error code. |
186 | */ |
187 | CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle, |
188 | struct curl_waitfd [], |
189 | unsigned int , |
190 | int timeout_ms, |
191 | int *ret); |
192 | |
193 | /* |
194 | * Name: curl_multi_wakeup() |
195 | * |
196 | * Desc: wakes up a sleeping curl_multi_poll call. |
197 | * |
198 | * Returns: CURLMcode type, general multi error code. |
199 | */ |
200 | CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle); |
201 | |
202 | /* |
203 | * Name: curl_multi_perform() |
204 | * |
205 | * Desc: When the app thinks there's data available for curl it calls this |
206 | * function to read/write whatever there is right now. This returns |
207 | * as soon as the reads and writes are done. This function does not |
208 | * require that there actually is data available for reading or that |
209 | * data can be written, it can be called just in case. It returns |
210 | * the number of handles that still transfer data in the second |
211 | * argument's integer-pointer. |
212 | * |
213 | * Returns: CURLMcode type, general multi error code. *NOTE* that this only |
214 | * returns errors etc regarding the whole multi stack. There might |
215 | * still have occurred problems on individual transfers even when |
216 | * this returns OK. |
217 | */ |
218 | CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, |
219 | int *running_handles); |
220 | |
221 | /* |
222 | * Name: curl_multi_cleanup() |
223 | * |
224 | * Desc: Cleans up and removes a whole multi stack. It does not free or |
225 | * touch any individual easy handles in any way. We need to define |
226 | * in what state those handles will be if this function is called |
227 | * in the middle of a transfer. |
228 | * |
229 | * Returns: CURLMcode type, general multi error code. |
230 | */ |
231 | CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); |
232 | |
233 | /* |
234 | * Name: curl_multi_info_read() |
235 | * |
236 | * Desc: Ask the multi handle if there's any messages/informationals from |
237 | * the individual transfers. Messages include informationals such as |
238 | * error code from the transfer or just the fact that a transfer is |
239 | * completed. More details on these should be written down as well. |
240 | * |
241 | * Repeated calls to this function will return a new struct each |
242 | * time, until a special "end of msgs" struct is returned as a signal |
243 | * that there is no more to get at this point. |
244 | * |
245 | * The data the returned pointer points to will not survive calling |
246 | * curl_multi_cleanup(). |
247 | * |
248 | * The 'CURLMsg' struct is meant to be very simple and only contain |
249 | * very basic information. If more involved information is wanted, |
250 | * we will provide the particular "transfer handle" in that struct |
251 | * and that should/could/would be used in subsequent |
252 | * curl_easy_getinfo() calls (or similar). The point being that we |
253 | * must never expose complex structs to applications, as then we'll |
254 | * undoubtably get backwards compatibility problems in the future. |
255 | * |
256 | * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out |
257 | * of structs. It also writes the number of messages left in the |
258 | * queue (after this read) in the integer the second argument points |
259 | * to. |
260 | */ |
261 | CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, |
262 | int *msgs_in_queue); |
263 | |
264 | /* |
265 | * Name: curl_multi_strerror() |
266 | * |
267 | * Desc: The curl_multi_strerror function may be used to turn a CURLMcode |
268 | * value into the equivalent human readable error string. This is |
269 | * useful for printing meaningful error messages. |
270 | * |
271 | * Returns: A pointer to a null-terminated error message. |
272 | */ |
273 | CURL_EXTERN const char *curl_multi_strerror(CURLMcode); |
274 | |
275 | /* |
276 | * Name: curl_multi_socket() and |
277 | * curl_multi_socket_all() |
278 | * |
279 | * Desc: An alternative version of curl_multi_perform() that allows the |
280 | * application to pass in one of the file descriptors that have been |
281 | * detected to have "action" on them and let libcurl perform. |
282 | * See man page for details. |
283 | */ |
284 | #define CURL_POLL_NONE 0 |
285 | #define CURL_POLL_IN 1 |
286 | #define CURL_POLL_OUT 2 |
287 | #define CURL_POLL_INOUT 3 |
288 | #define CURL_POLL_REMOVE 4 |
289 | |
290 | #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD |
291 | |
292 | #define CURL_CSELECT_IN 0x01 |
293 | #define CURL_CSELECT_OUT 0x02 |
294 | #define CURL_CSELECT_ERR 0x04 |
295 | |
296 | typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ |
297 | curl_socket_t s, /* socket */ |
298 | int what, /* see above */ |
299 | void *userp, /* private callback |
300 | pointer */ |
301 | void *socketp); /* private socket |
302 | pointer */ |
303 | /* |
304 | * Name: curl_multi_timer_callback |
305 | * |
306 | * Desc: Called by libcurl whenever the library detects a change in the |
307 | * maximum number of milliseconds the app is allowed to wait before |
308 | * curl_multi_socket() or curl_multi_perform() must be called |
309 | * (to allow libcurl's timed events to take place). |
310 | * |
311 | * Returns: The callback should return zero. |
312 | */ |
313 | typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ |
314 | long timeout_ms, /* see above */ |
315 | void *userp); /* private callback |
316 | pointer */ |
317 | |
318 | CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, |
319 | int *running_handles); |
320 | |
321 | CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, |
322 | curl_socket_t s, |
323 | int ev_bitmask, |
324 | int *running_handles); |
325 | |
326 | CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, |
327 | int *running_handles); |
328 | |
329 | #ifndef CURL_ALLOW_OLD_MULTI_SOCKET |
330 | /* This macro below was added in 7.16.3 to push users who recompile to use |
331 | the new curl_multi_socket_action() instead of the old curl_multi_socket() |
332 | */ |
333 | #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) |
334 | #endif |
335 | |
336 | /* |
337 | * Name: curl_multi_timeout() |
338 | * |
339 | * Desc: Returns the maximum number of milliseconds the app is allowed to |
340 | * wait before curl_multi_socket() or curl_multi_perform() must be |
341 | * called (to allow libcurl's timed events to take place). |
342 | * |
343 | * Returns: CURLM error code. |
344 | */ |
345 | CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, |
346 | long *milliseconds); |
347 | |
348 | typedef enum { |
349 | /* This is the socket callback function pointer */ |
350 | CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1), |
351 | |
352 | /* This is the argument passed to the socket callback */ |
353 | CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2), |
354 | |
355 | /* set to 1 to enable pipelining for this multi handle */ |
356 | CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3), |
357 | |
358 | /* This is the timer callback function pointer */ |
359 | CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4), |
360 | |
361 | /* This is the argument passed to the timer callback */ |
362 | CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5), |
363 | |
364 | /* maximum number of entries in the connection cache */ |
365 | CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6), |
366 | |
367 | /* maximum number of (pipelining) connections to one host */ |
368 | CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7), |
369 | |
370 | /* maximum number of requests in a pipeline */ |
371 | CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8), |
372 | |
373 | /* a connection with a content-length longer than this |
374 | will not be considered for pipelining */ |
375 | CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9), |
376 | |
377 | /* a connection with a chunk length longer than this |
378 | will not be considered for pipelining */ |
379 | CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10), |
380 | |
381 | /* a list of site names(+port) that are blocked from pipelining */ |
382 | CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11), |
383 | |
384 | /* a list of server types that are blocked from pipelining */ |
385 | CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12), |
386 | |
387 | /* maximum number of open connections in total */ |
388 | CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13), |
389 | |
390 | /* This is the server push callback function pointer */ |
391 | CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14), |
392 | |
393 | /* This is the argument passed to the server push callback */ |
394 | CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15), |
395 | |
396 | /* maximum number of concurrent streams to support on a connection */ |
397 | CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16), |
398 | |
399 | CURLMOPT_LASTENTRY /* the last unused */ |
400 | } CURLMoption; |
401 | |
402 | |
403 | /* |
404 | * Name: curl_multi_setopt() |
405 | * |
406 | * Desc: Sets options for the multi handle. |
407 | * |
408 | * Returns: CURLM error code. |
409 | */ |
410 | CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, |
411 | CURLMoption option, ...); |
412 | |
413 | |
414 | /* |
415 | * Name: curl_multi_assign() |
416 | * |
417 | * Desc: This function sets an association in the multi handle between the |
418 | * given socket and a private pointer of the application. This is |
419 | * (only) useful for curl_multi_socket uses. |
420 | * |
421 | * Returns: CURLM error code. |
422 | */ |
423 | CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, |
424 | curl_socket_t sockfd, void *sockp); |
425 | |
426 | |
427 | /* |
428 | * Name: curl_push_callback |
429 | * |
430 | * Desc: This callback gets called when a new stream is being pushed by the |
431 | * server. It approves or denies the new stream. It can also decide |
432 | * to completely fail the connection. |
433 | * |
434 | * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT |
435 | */ |
436 | #define CURL_PUSH_OK 0 |
437 | #define CURL_PUSH_DENY 1 |
438 | #define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */ |
439 | |
440 | struct ; /* forward declaration only */ |
441 | |
442 | CURL_EXTERN char *(struct curl_pushheaders *h, |
443 | size_t num); |
444 | CURL_EXTERN char *(struct curl_pushheaders *h, |
445 | const char *name); |
446 | |
447 | typedef int (*curl_push_callback)(CURL *parent, |
448 | CURL *easy, |
449 | size_t , |
450 | struct curl_pushheaders *, |
451 | void *userp); |
452 | |
453 | #ifdef __cplusplus |
454 | } /* end of extern "C" */ |
455 | #endif |
456 | |
457 | #endif |
458 | |