|
||||
File indexing completed on 2025-01-18 09:55:11
0001 #ifndef CURLINC_MULTI_H 0002 #define CURLINC_MULTI_H 0003 /*************************************************************************** 0004 * _ _ ____ _ 0005 * Project ___| | | | _ \| | 0006 * / __| | | | |_) | | 0007 * | (__| |_| | _ <| |___ 0008 * \___|\___/|_| \_\_____| 0009 * 0010 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 0011 * 0012 * This software is licensed as described in the file COPYING, which 0013 * you should have received as part of this distribution. The terms 0014 * are also available at https://curl.se/docs/copyright.html. 0015 * 0016 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 0017 * copies of the Software, and permit persons to whom the Software is 0018 * furnished to do so, under the terms of the COPYING file. 0019 * 0020 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 0021 * KIND, either express or implied. 0022 * 0023 * SPDX-License-Identifier: curl 0024 * 0025 ***************************************************************************/ 0026 /* 0027 This is an "external" header file. Do not give away any internals here! 0028 0029 GOALS 0030 0031 o Enable a "pull" interface. The application that uses libcurl decides where 0032 and when to ask libcurl to get/send data. 0033 0034 o Enable multiple simultaneous transfers in the same thread without making it 0035 complicated for the application. 0036 0037 o Enable the application to select() on its own file descriptors and curl's 0038 file descriptors simultaneous easily. 0039 0040 */ 0041 0042 /* 0043 * This header file should not really need to include "curl.h" since curl.h 0044 * itself includes this file and we expect user applications to do #include 0045 * <curl/curl.h> without the need for especially including multi.h. 0046 * 0047 * For some reason we added this include here at one point, and rather than to 0048 * break existing (wrongly written) libcurl applications, we leave it as-is 0049 * but with this warning attached. 0050 */ 0051 #include "curl.h" 0052 0053 #ifdef __cplusplus 0054 extern "C" { 0055 #endif 0056 0057 #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) 0058 typedef struct Curl_multi CURLM; 0059 #else 0060 typedef void CURLM; 0061 #endif 0062 0063 typedef enum { 0064 CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or 0065 curl_multi_socket*() soon */ 0066 CURLM_OK, 0067 CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ 0068 CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ 0069 CURLM_OUT_OF_MEMORY, /* if you ever get this, you are in deep sh*t */ 0070 CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ 0071 CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ 0072 CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ 0073 CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was 0074 attempted to get added - again */ 0075 CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a 0076 callback */ 0077 CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */ 0078 CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */ 0079 CURLM_ABORTED_BY_CALLBACK, 0080 CURLM_UNRECOVERABLE_POLL, 0081 CURLM_LAST 0082 } CURLMcode; 0083 0084 /* just to make code nicer when using curl_multi_socket() you can now check 0085 for CURLM_CALL_MULTI_SOCKET too in the same style it works for 0086 curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ 0087 #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM 0088 0089 /* bitmask bits for CURLMOPT_PIPELINING */ 0090 #define CURLPIPE_NOTHING 0L 0091 #define CURLPIPE_HTTP1 1L 0092 #define CURLPIPE_MULTIPLEX 2L 0093 0094 typedef enum { 0095 CURLMSG_NONE, /* first, not used */ 0096 CURLMSG_DONE, /* This easy handle has completed. 'result' contains 0097 the CURLcode of the transfer */ 0098 CURLMSG_LAST /* last, not used */ 0099 } CURLMSG; 0100 0101 struct CURLMsg { 0102 CURLMSG msg; /* what this message means */ 0103 CURL *easy_handle; /* the handle it concerns */ 0104 union { 0105 void *whatever; /* message-specific data */ 0106 CURLcode result; /* return code for transfer */ 0107 } data; 0108 }; 0109 typedef struct CURLMsg CURLMsg; 0110 0111 /* Based on poll(2) structure and values. 0112 * We do not use pollfd and POLL* constants explicitly 0113 * to cover platforms without poll(). */ 0114 #define CURL_WAIT_POLLIN 0x0001 0115 #define CURL_WAIT_POLLPRI 0x0002 0116 #define CURL_WAIT_POLLOUT 0x0004 0117 0118 struct curl_waitfd { 0119 curl_socket_t fd; 0120 short events; 0121 short revents; 0122 }; 0123 0124 /* 0125 * Name: curl_multi_init() 0126 * 0127 * Desc: initialize multi-style curl usage 0128 * 0129 * Returns: a new CURLM handle to use in all 'curl_multi' functions. 0130 */ 0131 CURL_EXTERN CURLM *curl_multi_init(void); 0132 0133 /* 0134 * Name: curl_multi_add_handle() 0135 * 0136 * Desc: add a standard curl handle to the multi stack 0137 * 0138 * Returns: CURLMcode type, general multi error code. 0139 */ 0140 CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, 0141 CURL *curl_handle); 0142 0143 /* 0144 * Name: curl_multi_remove_handle() 0145 * 0146 * Desc: removes a curl handle from the multi stack again 0147 * 0148 * Returns: CURLMcode type, general multi error code. 0149 */ 0150 CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, 0151 CURL *curl_handle); 0152 0153 /* 0154 * Name: curl_multi_fdset() 0155 * 0156 * Desc: Ask curl for its fd_set sets. The app can use these to select() or 0157 * poll() on. We want curl_multi_perform() called as soon as one of 0158 * them are ready. 0159 * 0160 * Returns: CURLMcode type, general multi error code. 0161 */ 0162 CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, 0163 fd_set *read_fd_set, 0164 fd_set *write_fd_set, 0165 fd_set *exc_fd_set, 0166 int *max_fd); 0167 0168 /* 0169 * Name: curl_multi_wait() 0170 * 0171 * Desc: Poll on all fds within a CURLM set as well as any 0172 * additional fds passed to the function. 0173 * 0174 * Returns: CURLMcode type, general multi error code. 0175 */ 0176 CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, 0177 struct curl_waitfd extra_fds[], 0178 unsigned int extra_nfds, 0179 int timeout_ms, 0180 int *ret); 0181 0182 /* 0183 * Name: curl_multi_poll() 0184 * 0185 * Desc: Poll on all fds within a CURLM set as well as any 0186 * additional fds passed to the function. 0187 * 0188 * Returns: CURLMcode type, general multi error code. 0189 */ 0190 CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle, 0191 struct curl_waitfd extra_fds[], 0192 unsigned int extra_nfds, 0193 int timeout_ms, 0194 int *ret); 0195 0196 /* 0197 * Name: curl_multi_wakeup() 0198 * 0199 * Desc: wakes up a sleeping curl_multi_poll call. 0200 * 0201 * Returns: CURLMcode type, general multi error code. 0202 */ 0203 CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle); 0204 0205 /* 0206 * Name: curl_multi_perform() 0207 * 0208 * Desc: When the app thinks there is data available for curl it calls this 0209 * function to read/write whatever there is right now. This returns 0210 * as soon as the reads and writes are done. This function does not 0211 * require that there actually is data available for reading or that 0212 * data can be written, it can be called just in case. It returns 0213 * the number of handles that still transfer data in the second 0214 * argument's integer-pointer. 0215 * 0216 * Returns: CURLMcode type, general multi error code. *NOTE* that this only 0217 * returns errors etc regarding the whole multi stack. There might 0218 * still have occurred problems on individual transfers even when 0219 * this returns OK. 0220 */ 0221 CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, 0222 int *running_handles); 0223 0224 /* 0225 * Name: curl_multi_cleanup() 0226 * 0227 * Desc: Cleans up and removes a whole multi stack. It does not free or 0228 * touch any individual easy handles in any way. We need to define 0229 * in what state those handles will be if this function is called 0230 * in the middle of a transfer. 0231 * 0232 * Returns: CURLMcode type, general multi error code. 0233 */ 0234 CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); 0235 0236 /* 0237 * Name: curl_multi_info_read() 0238 * 0239 * Desc: Ask the multi handle if there is any messages/informationals from 0240 * the individual transfers. Messages include informationals such as 0241 * error code from the transfer or just the fact that a transfer is 0242 * completed. More details on these should be written down as well. 0243 * 0244 * Repeated calls to this function will return a new struct each 0245 * time, until a special "end of msgs" struct is returned as a signal 0246 * that there is no more to get at this point. 0247 * 0248 * The data the returned pointer points to will not survive calling 0249 * curl_multi_cleanup(). 0250 * 0251 * The 'CURLMsg' struct is meant to be very simple and only contain 0252 * very basic information. If more involved information is wanted, 0253 * we will provide the particular "transfer handle" in that struct 0254 * and that should/could/would be used in subsequent 0255 * curl_easy_getinfo() calls (or similar). The point being that we 0256 * must never expose complex structs to applications, as then we will 0257 * undoubtably get backwards compatibility problems in the future. 0258 * 0259 * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out 0260 * of structs. It also writes the number of messages left in the 0261 * queue (after this read) in the integer the second argument points 0262 * to. 0263 */ 0264 CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, 0265 int *msgs_in_queue); 0266 0267 /* 0268 * Name: curl_multi_strerror() 0269 * 0270 * Desc: The curl_multi_strerror function may be used to turn a CURLMcode 0271 * value into the equivalent human readable error string. This is 0272 * useful for printing meaningful error messages. 0273 * 0274 * Returns: A pointer to a null-terminated error message. 0275 */ 0276 CURL_EXTERN const char *curl_multi_strerror(CURLMcode); 0277 0278 /* 0279 * Name: curl_multi_socket() and 0280 * curl_multi_socket_all() 0281 * 0282 * Desc: An alternative version of curl_multi_perform() that allows the 0283 * application to pass in one of the file descriptors that have been 0284 * detected to have "action" on them and let libcurl perform. 0285 * See manpage for details. 0286 */ 0287 #define CURL_POLL_NONE 0 0288 #define CURL_POLL_IN 1 0289 #define CURL_POLL_OUT 2 0290 #define CURL_POLL_INOUT 3 0291 #define CURL_POLL_REMOVE 4 0292 0293 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD 0294 0295 #define CURL_CSELECT_IN 0x01 0296 #define CURL_CSELECT_OUT 0x02 0297 #define CURL_CSELECT_ERR 0x04 0298 0299 typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ 0300 curl_socket_t s, /* socket */ 0301 int what, /* see above */ 0302 void *userp, /* private callback 0303 pointer */ 0304 void *socketp); /* private socket 0305 pointer */ 0306 /* 0307 * Name: curl_multi_timer_callback 0308 * 0309 * Desc: Called by libcurl whenever the library detects a change in the 0310 * maximum number of milliseconds the app is allowed to wait before 0311 * curl_multi_socket() or curl_multi_perform() must be called 0312 * (to allow libcurl's timed events to take place). 0313 * 0314 * Returns: The callback should return zero. 0315 */ 0316 typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ 0317 long timeout_ms, /* see above */ 0318 void *userp); /* private callback 0319 pointer */ 0320 0321 CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()") 0322 curl_multi_socket(CURLM *multi_handle, curl_socket_t s, int *running_handles); 0323 0324 CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, 0325 curl_socket_t s, 0326 int ev_bitmask, 0327 int *running_handles); 0328 0329 CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()") 0330 curl_multi_socket_all(CURLM *multi_handle, int *running_handles); 0331 0332 #ifndef CURL_ALLOW_OLD_MULTI_SOCKET 0333 /* This macro below was added in 7.16.3 to push users who recompile to use 0334 the new curl_multi_socket_action() instead of the old curl_multi_socket() 0335 */ 0336 #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) 0337 #endif 0338 0339 /* 0340 * Name: curl_multi_timeout() 0341 * 0342 * Desc: Returns the maximum number of milliseconds the app is allowed to 0343 * wait before curl_multi_socket() or curl_multi_perform() must be 0344 * called (to allow libcurl's timed events to take place). 0345 * 0346 * Returns: CURLM error code. 0347 */ 0348 CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, 0349 long *milliseconds); 0350 0351 typedef enum { 0352 /* This is the socket callback function pointer */ 0353 CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1), 0354 0355 /* This is the argument passed to the socket callback */ 0356 CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2), 0357 0358 /* set to 1 to enable pipelining for this multi handle */ 0359 CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3), 0360 0361 /* This is the timer callback function pointer */ 0362 CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4), 0363 0364 /* This is the argument passed to the timer callback */ 0365 CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5), 0366 0367 /* maximum number of entries in the connection cache */ 0368 CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6), 0369 0370 /* maximum number of (pipelining) connections to one host */ 0371 CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7), 0372 0373 /* maximum number of requests in a pipeline */ 0374 CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8), 0375 0376 /* a connection with a content-length longer than this 0377 will not be considered for pipelining */ 0378 CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9), 0379 0380 /* a connection with a chunk length longer than this 0381 will not be considered for pipelining */ 0382 CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10), 0383 0384 /* a list of site names(+port) that are blocked from pipelining */ 0385 CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11), 0386 0387 /* a list of server types that are blocked from pipelining */ 0388 CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12), 0389 0390 /* maximum number of open connections in total */ 0391 CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13), 0392 0393 /* This is the server push callback function pointer */ 0394 CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14), 0395 0396 /* This is the argument passed to the server push callback */ 0397 CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15), 0398 0399 /* maximum number of concurrent streams to support on a connection */ 0400 CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16), 0401 0402 CURLMOPT_LASTENTRY /* the last unused */ 0403 } CURLMoption; 0404 0405 0406 /* 0407 * Name: curl_multi_setopt() 0408 * 0409 * Desc: Sets options for the multi handle. 0410 * 0411 * Returns: CURLM error code. 0412 */ 0413 CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, 0414 CURLMoption option, ...); 0415 0416 0417 /* 0418 * Name: curl_multi_assign() 0419 * 0420 * Desc: This function sets an association in the multi handle between the 0421 * given socket and a private pointer of the application. This is 0422 * (only) useful for curl_multi_socket uses. 0423 * 0424 * Returns: CURLM error code. 0425 */ 0426 CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, 0427 curl_socket_t sockfd, void *sockp); 0428 0429 /* 0430 * Name: curl_multi_get_handles() 0431 * 0432 * Desc: Returns an allocated array holding all handles currently added to 0433 * the multi handle. Marks the final entry with a NULL pointer. If 0434 * there is no easy handle added to the multi handle, this function 0435 * returns an array with the first entry as a NULL pointer. 0436 * 0437 * Returns: NULL on failure, otherwise a CURL **array pointer 0438 */ 0439 CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle); 0440 0441 /* 0442 * Name: curl_push_callback 0443 * 0444 * Desc: This callback gets called when a new stream is being pushed by the 0445 * server. It approves or denies the new stream. It can also decide 0446 * to completely fail the connection. 0447 * 0448 * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT 0449 */ 0450 #define CURL_PUSH_OK 0 0451 #define CURL_PUSH_DENY 1 0452 #define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */ 0453 0454 struct curl_pushheaders; /* forward declaration only */ 0455 0456 CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, 0457 size_t num); 0458 CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, 0459 const char *name); 0460 0461 typedef int (*curl_push_callback)(CURL *parent, 0462 CURL *easy, 0463 size_t num_headers, 0464 struct curl_pushheaders *headers, 0465 void *userp); 0466 0467 /* 0468 * Name: curl_multi_waitfds() 0469 * 0470 * Desc: Ask curl for fds for polling. The app can use these to poll on. 0471 * We want curl_multi_perform() called as soon as one of them are 0472 * ready. Passing zero size allows to get just a number of fds. 0473 * 0474 * Returns: CURLMcode type, general multi error code. 0475 */ 0476 CURL_EXTERN CURLMcode curl_multi_waitfds(CURLM *multi, 0477 struct curl_waitfd *ufds, 0478 unsigned int size, 0479 unsigned int *fd_count); 0480 0481 #ifdef __cplusplus 0482 } /* end of extern "C" */ 0483 #endif 0484 0485 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |