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