jpayne@69: #ifndef CURLINC_MULTI_H jpayne@69: #define CURLINC_MULTI_H jpayne@69: /*************************************************************************** jpayne@69: * _ _ ____ _ jpayne@69: * Project ___| | | | _ \| | jpayne@69: * / __| | | | |_) | | jpayne@69: * | (__| |_| | _ <| |___ jpayne@69: * \___|\___/|_| \_\_____| jpayne@69: * jpayne@69: * Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. jpayne@69: * jpayne@69: * This software is licensed as described in the file COPYING, which jpayne@69: * you should have received as part of this distribution. The terms jpayne@69: * are also available at https://curl.se/docs/copyright.html. jpayne@69: * jpayne@69: * You may opt to use, copy, modify, merge, publish, distribute and/or sell jpayne@69: * copies of the Software, and permit persons to whom the Software is jpayne@69: * furnished to do so, under the terms of the COPYING file. jpayne@69: * jpayne@69: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY jpayne@69: * KIND, either express or implied. jpayne@69: * jpayne@69: * SPDX-License-Identifier: curl jpayne@69: * jpayne@69: ***************************************************************************/ jpayne@69: /* jpayne@69: This is an "external" header file. Don't give away any internals here! jpayne@69: jpayne@69: GOALS jpayne@69: jpayne@69: o Enable a "pull" interface. The application that uses libcurl decides where jpayne@69: and when to ask libcurl to get/send data. jpayne@69: jpayne@69: o Enable multiple simultaneous transfers in the same thread without making it jpayne@69: complicated for the application. jpayne@69: jpayne@69: o Enable the application to select() on its own file descriptors and curl's jpayne@69: file descriptors simultaneous easily. jpayne@69: jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * This header file should not really need to include "curl.h" since curl.h jpayne@69: * itself includes this file and we expect user applications to do #include jpayne@69: * without the need for especially including multi.h. jpayne@69: * jpayne@69: * For some reason we added this include here at one point, and rather than to jpayne@69: * break existing (wrongly written) libcurl applications, we leave it as-is jpayne@69: * but with this warning attached. jpayne@69: */ jpayne@69: #include "curl.h" jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) jpayne@69: typedef struct Curl_multi CURLM; jpayne@69: #else jpayne@69: typedef void CURLM; jpayne@69: #endif jpayne@69: jpayne@69: typedef enum { jpayne@69: CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or jpayne@69: curl_multi_socket*() soon */ jpayne@69: CURLM_OK, jpayne@69: CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ jpayne@69: CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ jpayne@69: CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ jpayne@69: CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ jpayne@69: CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ jpayne@69: CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ jpayne@69: CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was jpayne@69: attempted to get added - again */ jpayne@69: CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a jpayne@69: callback */ jpayne@69: CURLM_WAKEUP_FAILURE, /* wakeup is unavailable or failed */ jpayne@69: CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */ jpayne@69: CURLM_ABORTED_BY_CALLBACK, jpayne@69: CURLM_UNRECOVERABLE_POLL, jpayne@69: CURLM_LAST jpayne@69: } CURLMcode; jpayne@69: jpayne@69: /* just to make code nicer when using curl_multi_socket() you can now check jpayne@69: for CURLM_CALL_MULTI_SOCKET too in the same style it works for jpayne@69: curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ jpayne@69: #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM jpayne@69: jpayne@69: /* bitmask bits for CURLMOPT_PIPELINING */ jpayne@69: #define CURLPIPE_NOTHING 0L jpayne@69: #define CURLPIPE_HTTP1 1L jpayne@69: #define CURLPIPE_MULTIPLEX 2L jpayne@69: jpayne@69: typedef enum { jpayne@69: CURLMSG_NONE, /* first, not used */ jpayne@69: CURLMSG_DONE, /* This easy handle has completed. 'result' contains jpayne@69: the CURLcode of the transfer */ jpayne@69: CURLMSG_LAST /* last, not used */ jpayne@69: } CURLMSG; jpayne@69: jpayne@69: struct CURLMsg { jpayne@69: CURLMSG msg; /* what this message means */ jpayne@69: CURL *easy_handle; /* the handle it concerns */ jpayne@69: union { jpayne@69: void *whatever; /* message-specific data */ jpayne@69: CURLcode result; /* return code for transfer */ jpayne@69: } data; jpayne@69: }; jpayne@69: typedef struct CURLMsg CURLMsg; jpayne@69: jpayne@69: /* Based on poll(2) structure and values. jpayne@69: * We don't use pollfd and POLL* constants explicitly jpayne@69: * to cover platforms without poll(). */ jpayne@69: #define CURL_WAIT_POLLIN 0x0001 jpayne@69: #define CURL_WAIT_POLLPRI 0x0002 jpayne@69: #define CURL_WAIT_POLLOUT 0x0004 jpayne@69: jpayne@69: struct curl_waitfd { jpayne@69: curl_socket_t fd; jpayne@69: short events; jpayne@69: short revents; /* not supported yet */ jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_init() jpayne@69: * jpayne@69: * Desc: initialize multi-style curl usage jpayne@69: * jpayne@69: * Returns: a new CURLM handle to use in all 'curl_multi' functions. jpayne@69: */ jpayne@69: CURL_EXTERN CURLM *curl_multi_init(void); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_add_handle() jpayne@69: * jpayne@69: * Desc: add a standard curl handle to the multi stack jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, jpayne@69: CURL *curl_handle); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_remove_handle() jpayne@69: * jpayne@69: * Desc: removes a curl handle from the multi stack again jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, jpayne@69: CURL *curl_handle); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_fdset() jpayne@69: * jpayne@69: * Desc: Ask curl for its fd_set sets. The app can use these to select() or jpayne@69: * poll() on. We want curl_multi_perform() called as soon as one of jpayne@69: * them are ready. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, jpayne@69: fd_set *read_fd_set, jpayne@69: fd_set *write_fd_set, jpayne@69: fd_set *exc_fd_set, jpayne@69: int *max_fd); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_wait() jpayne@69: * jpayne@69: * Desc: Poll on all fds within a CURLM set as well as any jpayne@69: * additional fds passed to the function. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, jpayne@69: struct curl_waitfd extra_fds[], jpayne@69: unsigned int extra_nfds, jpayne@69: int timeout_ms, jpayne@69: int *ret); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_poll() jpayne@69: * jpayne@69: * Desc: Poll on all fds within a CURLM set as well as any jpayne@69: * additional fds passed to the function. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle, jpayne@69: struct curl_waitfd extra_fds[], jpayne@69: unsigned int extra_nfds, jpayne@69: int timeout_ms, jpayne@69: int *ret); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_wakeup() jpayne@69: * jpayne@69: * Desc: wakes up a sleeping curl_multi_poll call. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_perform() jpayne@69: * jpayne@69: * Desc: When the app thinks there's data available for curl it calls this jpayne@69: * function to read/write whatever there is right now. This returns jpayne@69: * as soon as the reads and writes are done. This function does not jpayne@69: * require that there actually is data available for reading or that jpayne@69: * data can be written, it can be called just in case. It returns jpayne@69: * the number of handles that still transfer data in the second jpayne@69: * argument's integer-pointer. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. *NOTE* that this only jpayne@69: * returns errors etc regarding the whole multi stack. There might jpayne@69: * still have occurred problems on individual transfers even when jpayne@69: * this returns OK. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, jpayne@69: int *running_handles); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_cleanup() jpayne@69: * jpayne@69: * Desc: Cleans up and removes a whole multi stack. It does not free or jpayne@69: * touch any individual easy handles in any way. We need to define jpayne@69: * in what state those handles will be if this function is called jpayne@69: * in the middle of a transfer. jpayne@69: * jpayne@69: * Returns: CURLMcode type, general multi error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_info_read() jpayne@69: * jpayne@69: * Desc: Ask the multi handle if there's any messages/informationals from jpayne@69: * the individual transfers. Messages include informationals such as jpayne@69: * error code from the transfer or just the fact that a transfer is jpayne@69: * completed. More details on these should be written down as well. jpayne@69: * jpayne@69: * Repeated calls to this function will return a new struct each jpayne@69: * time, until a special "end of msgs" struct is returned as a signal jpayne@69: * that there is no more to get at this point. jpayne@69: * jpayne@69: * The data the returned pointer points to will not survive calling jpayne@69: * curl_multi_cleanup(). jpayne@69: * jpayne@69: * The 'CURLMsg' struct is meant to be very simple and only contain jpayne@69: * very basic information. If more involved information is wanted, jpayne@69: * we will provide the particular "transfer handle" in that struct jpayne@69: * and that should/could/would be used in subsequent jpayne@69: * curl_easy_getinfo() calls (or similar). The point being that we jpayne@69: * must never expose complex structs to applications, as then we'll jpayne@69: * undoubtably get backwards compatibility problems in the future. jpayne@69: * jpayne@69: * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out jpayne@69: * of structs. It also writes the number of messages left in the jpayne@69: * queue (after this read) in the integer the second argument points jpayne@69: * to. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, jpayne@69: int *msgs_in_queue); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_strerror() jpayne@69: * jpayne@69: * Desc: The curl_multi_strerror function may be used to turn a CURLMcode jpayne@69: * value into the equivalent human readable error string. This is jpayne@69: * useful for printing meaningful error messages. jpayne@69: * jpayne@69: * Returns: A pointer to a null-terminated error message. jpayne@69: */ jpayne@69: CURL_EXTERN const char *curl_multi_strerror(CURLMcode); jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_socket() and jpayne@69: * curl_multi_socket_all() jpayne@69: * jpayne@69: * Desc: An alternative version of curl_multi_perform() that allows the jpayne@69: * application to pass in one of the file descriptors that have been jpayne@69: * detected to have "action" on them and let libcurl perform. jpayne@69: * See man page for details. jpayne@69: */ jpayne@69: #define CURL_POLL_NONE 0 jpayne@69: #define CURL_POLL_IN 1 jpayne@69: #define CURL_POLL_OUT 2 jpayne@69: #define CURL_POLL_INOUT 3 jpayne@69: #define CURL_POLL_REMOVE 4 jpayne@69: jpayne@69: #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD jpayne@69: jpayne@69: #define CURL_CSELECT_IN 0x01 jpayne@69: #define CURL_CSELECT_OUT 0x02 jpayne@69: #define CURL_CSELECT_ERR 0x04 jpayne@69: jpayne@69: typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ jpayne@69: curl_socket_t s, /* socket */ jpayne@69: int what, /* see above */ jpayne@69: void *userp, /* private callback jpayne@69: pointer */ jpayne@69: void *socketp); /* private socket jpayne@69: pointer */ jpayne@69: /* jpayne@69: * Name: curl_multi_timer_callback jpayne@69: * jpayne@69: * Desc: Called by libcurl whenever the library detects a change in the jpayne@69: * maximum number of milliseconds the app is allowed to wait before jpayne@69: * curl_multi_socket() or curl_multi_perform() must be called jpayne@69: * (to allow libcurl's timed events to take place). jpayne@69: * jpayne@69: * Returns: The callback should return zero. jpayne@69: */ jpayne@69: typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ jpayne@69: long timeout_ms, /* see above */ jpayne@69: void *userp); /* private callback jpayne@69: pointer */ jpayne@69: jpayne@69: CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()") jpayne@69: curl_multi_socket(CURLM *multi_handle, curl_socket_t s, int *running_handles); jpayne@69: jpayne@69: CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, jpayne@69: curl_socket_t s, jpayne@69: int ev_bitmask, jpayne@69: int *running_handles); jpayne@69: jpayne@69: CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()") jpayne@69: curl_multi_socket_all(CURLM *multi_handle, int *running_handles); jpayne@69: jpayne@69: #ifndef CURL_ALLOW_OLD_MULTI_SOCKET jpayne@69: /* This macro below was added in 7.16.3 to push users who recompile to use jpayne@69: the new curl_multi_socket_action() instead of the old curl_multi_socket() jpayne@69: */ jpayne@69: #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_timeout() jpayne@69: * jpayne@69: * Desc: Returns the maximum number of milliseconds the app is allowed to jpayne@69: * wait before curl_multi_socket() or curl_multi_perform() must be jpayne@69: * called (to allow libcurl's timed events to take place). jpayne@69: * jpayne@69: * Returns: CURLM error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, jpayne@69: long *milliseconds); jpayne@69: jpayne@69: typedef enum { jpayne@69: /* This is the socket callback function pointer */ jpayne@69: CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1), jpayne@69: jpayne@69: /* This is the argument passed to the socket callback */ jpayne@69: CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2), jpayne@69: jpayne@69: /* set to 1 to enable pipelining for this multi handle */ jpayne@69: CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3), jpayne@69: jpayne@69: /* This is the timer callback function pointer */ jpayne@69: CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4), jpayne@69: jpayne@69: /* This is the argument passed to the timer callback */ jpayne@69: CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5), jpayne@69: jpayne@69: /* maximum number of entries in the connection cache */ jpayne@69: CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6), jpayne@69: jpayne@69: /* maximum number of (pipelining) connections to one host */ jpayne@69: CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7), jpayne@69: jpayne@69: /* maximum number of requests in a pipeline */ jpayne@69: CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8), jpayne@69: jpayne@69: /* a connection with a content-length longer than this jpayne@69: will not be considered for pipelining */ jpayne@69: CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9), jpayne@69: jpayne@69: /* a connection with a chunk length longer than this jpayne@69: will not be considered for pipelining */ jpayne@69: CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10), jpayne@69: jpayne@69: /* a list of site names(+port) that are blocked from pipelining */ jpayne@69: CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11), jpayne@69: jpayne@69: /* a list of server types that are blocked from pipelining */ jpayne@69: CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12), jpayne@69: jpayne@69: /* maximum number of open connections in total */ jpayne@69: CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13), jpayne@69: jpayne@69: /* This is the server push callback function pointer */ jpayne@69: CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14), jpayne@69: jpayne@69: /* This is the argument passed to the server push callback */ jpayne@69: CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15), jpayne@69: jpayne@69: /* maximum number of concurrent streams to support on a connection */ jpayne@69: CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16), jpayne@69: jpayne@69: CURLMOPT_LASTENTRY /* the last unused */ jpayne@69: } CURLMoption; jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_setopt() jpayne@69: * jpayne@69: * Desc: Sets options for the multi handle. jpayne@69: * jpayne@69: * Returns: CURLM error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, jpayne@69: CURLMoption option, ...); jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_multi_assign() jpayne@69: * jpayne@69: * Desc: This function sets an association in the multi handle between the jpayne@69: * given socket and a private pointer of the application. This is jpayne@69: * (only) useful for curl_multi_socket uses. jpayne@69: * jpayne@69: * Returns: CURLM error code. jpayne@69: */ jpayne@69: CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, jpayne@69: curl_socket_t sockfd, void *sockp); jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Name: curl_push_callback jpayne@69: * jpayne@69: * Desc: This callback gets called when a new stream is being pushed by the jpayne@69: * server. It approves or denies the new stream. It can also decide jpayne@69: * to completely fail the connection. jpayne@69: * jpayne@69: * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT jpayne@69: */ jpayne@69: #define CURL_PUSH_OK 0 jpayne@69: #define CURL_PUSH_DENY 1 jpayne@69: #define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */ jpayne@69: jpayne@69: struct curl_pushheaders; /* forward declaration only */ jpayne@69: jpayne@69: CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, jpayne@69: size_t num); jpayne@69: CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, jpayne@69: const char *name); jpayne@69: jpayne@69: typedef int (*curl_push_callback)(CURL *parent, jpayne@69: CURL *easy, jpayne@69: size_t num_headers, jpayne@69: struct curl_pushheaders *headers, jpayne@69: void *userp); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } /* end of extern "C" */ jpayne@69: #endif jpayne@69: jpayne@69: #endif