michael@0: #ifndef __CURL_MULTI_H michael@0: #define __CURL_MULTI_H michael@0: /*************************************************************************** michael@0: * _ _ ____ _ michael@0: * Project ___| | | | _ \| | michael@0: * / __| | | | |_) | | michael@0: * | (__| |_| | _ <| |___ michael@0: * \___|\___/|_| \_\_____| michael@0: * michael@0: * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. michael@0: * michael@0: * This software is licensed as described in the file COPYING, which michael@0: * you should have received as part of this distribution. The terms michael@0: * are also available at http://curl.haxx.se/docs/copyright.html. michael@0: * michael@0: * You may opt to use, copy, modify, merge, publish, distribute and/or sell michael@0: * copies of the Software, and permit persons to whom the Software is michael@0: * furnished to do so, under the terms of the COPYING file. michael@0: * michael@0: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY michael@0: * KIND, either express or implied. michael@0: * michael@0: * $Id: multi.h,v 1.45 2008-05-20 10:21:50 patrickm Exp $ michael@0: ***************************************************************************/ michael@0: /* michael@0: This is an "external" header file. Don't give away any internals here! michael@0: michael@0: GOALS michael@0: michael@0: o Enable a "pull" interface. The application that uses libcurl decides where michael@0: and when to ask libcurl to get/send data. michael@0: michael@0: o Enable multiple simultaneous transfers in the same thread without making it michael@0: complicated for the application. michael@0: michael@0: o Enable the application to select() on its own file descriptors and curl's michael@0: file descriptors simultaneous easily. michael@0: michael@0: */ michael@0: michael@0: /* michael@0: * This header file should not really need to include "curl.h" since curl.h michael@0: * itself includes this file and we expect user applications to do #include michael@0: * without the need for especially including multi.h. michael@0: * michael@0: * For some reason we added this include here at one point, and rather than to michael@0: * break existing (wrongly written) libcurl applications, we leave it as-is michael@0: * but with this warning attached. michael@0: */ michael@0: #include "curl.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: typedef void CURLM; michael@0: michael@0: typedef enum { michael@0: CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or michael@0: curl_multi_socket*() soon */ michael@0: CURLM_OK, michael@0: CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ michael@0: CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ michael@0: CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ michael@0: CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ michael@0: CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ michael@0: CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ michael@0: CURLM_LAST michael@0: } CURLMcode; michael@0: michael@0: /* just to make code nicer when using curl_multi_socket() you can now check michael@0: for CURLM_CALL_MULTI_SOCKET too in the same style it works for michael@0: curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ michael@0: #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM michael@0: michael@0: typedef enum { michael@0: CURLMSG_NONE, /* first, not used */ michael@0: CURLMSG_DONE, /* This easy handle has completed. 'result' contains michael@0: the CURLcode of the transfer */ michael@0: CURLMSG_LAST /* last, not used */ michael@0: } CURLMSG; michael@0: michael@0: struct CURLMsg { michael@0: CURLMSG msg; /* what this message means */ michael@0: CURL *easy_handle; /* the handle it concerns */ michael@0: union { michael@0: void *whatever; /* message-specific data */ michael@0: CURLcode result; /* return code for transfer */ michael@0: } data; michael@0: }; michael@0: typedef struct CURLMsg CURLMsg; michael@0: michael@0: /* michael@0: * Name: curl_multi_init() michael@0: * michael@0: * Desc: inititalize multi-style curl usage michael@0: * michael@0: * Returns: a new CURLM handle to use in all 'curl_multi' functions. michael@0: */ michael@0: CURL_EXTERN CURLM *curl_multi_init(void); michael@0: michael@0: /* michael@0: * Name: curl_multi_add_handle() michael@0: * michael@0: * Desc: add a standard curl handle to the multi stack michael@0: * michael@0: * Returns: CURLMcode type, general multi error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, michael@0: CURL *curl_handle); michael@0: michael@0: /* michael@0: * Name: curl_multi_remove_handle() michael@0: * michael@0: * Desc: removes a curl handle from the multi stack again michael@0: * michael@0: * Returns: CURLMcode type, general multi error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, michael@0: CURL *curl_handle); michael@0: michael@0: /* michael@0: * Name: curl_multi_fdset() michael@0: * michael@0: * Desc: Ask curl for its fd_set sets. The app can use these to select() or michael@0: * poll() on. We want curl_multi_perform() called as soon as one of michael@0: * them are ready. michael@0: * michael@0: * Returns: CURLMcode type, general multi error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, michael@0: fd_set *read_fd_set, michael@0: fd_set *write_fd_set, michael@0: fd_set *exc_fd_set, michael@0: int *max_fd); michael@0: michael@0: /* michael@0: * Name: curl_multi_perform() michael@0: * michael@0: * Desc: When the app thinks there's data available for curl it calls this michael@0: * function to read/write whatever there is right now. This returns michael@0: * as soon as the reads and writes are done. This function does not michael@0: * require that there actually is data available for reading or that michael@0: * data can be written, it can be called just in case. It returns michael@0: * the number of handles that still transfer data in the second michael@0: * argument's integer-pointer. michael@0: * michael@0: * Returns: CURLMcode type, general multi error code. *NOTE* that this only michael@0: * returns errors etc regarding the whole multi stack. There might michael@0: * still have occurred problems on invidual transfers even when this michael@0: * returns OK. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, michael@0: int *running_handles); michael@0: michael@0: /* michael@0: * Name: curl_multi_cleanup() michael@0: * michael@0: * Desc: Cleans up and removes a whole multi stack. It does not free or michael@0: * touch any individual easy handles in any way. We need to define michael@0: * in what state those handles will be if this function is called michael@0: * in the middle of a transfer. michael@0: * michael@0: * Returns: CURLMcode type, general multi error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); michael@0: michael@0: /* michael@0: * Name: curl_multi_info_read() michael@0: * michael@0: * Desc: Ask the multi handle if there's any messages/informationals from michael@0: * the individual transfers. Messages include informationals such as michael@0: * error code from the transfer or just the fact that a transfer is michael@0: * completed. More details on these should be written down as well. michael@0: * michael@0: * Repeated calls to this function will return a new struct each michael@0: * time, until a special "end of msgs" struct is returned as a signal michael@0: * that there is no more to get at this point. michael@0: * michael@0: * The data the returned pointer points to will not survive calling michael@0: * curl_multi_cleanup(). michael@0: * michael@0: * The 'CURLMsg' struct is meant to be very simple and only contain michael@0: * very basic informations. If more involved information is wanted, michael@0: * we will provide the particular "transfer handle" in that struct michael@0: * and that should/could/would be used in subsequent michael@0: * curl_easy_getinfo() calls (or similar). The point being that we michael@0: * must never expose complex structs to applications, as then we'll michael@0: * undoubtably get backwards compatibility problems in the future. michael@0: * michael@0: * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out michael@0: * of structs. It also writes the number of messages left in the michael@0: * queue (after this read) in the integer the second argument points michael@0: * to. michael@0: */ michael@0: CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, michael@0: int *msgs_in_queue); michael@0: michael@0: /* michael@0: * Name: curl_multi_strerror() michael@0: * michael@0: * Desc: The curl_multi_strerror function may be used to turn a CURLMcode michael@0: * value into the equivalent human readable error string. This is michael@0: * useful for printing meaningful error messages. michael@0: * michael@0: * Returns: A pointer to a zero-terminated error message. michael@0: */ michael@0: CURL_EXTERN const char *curl_multi_strerror(CURLMcode); michael@0: michael@0: /* michael@0: * Name: curl_multi_socket() and michael@0: * curl_multi_socket_all() michael@0: * michael@0: * Desc: An alternative version of curl_multi_perform() that allows the michael@0: * application to pass in one of the file descriptors that have been michael@0: * detected to have "action" on them and let libcurl perform. michael@0: * See man page for details. michael@0: */ michael@0: #define CURL_POLL_NONE 0 michael@0: #define CURL_POLL_IN 1 michael@0: #define CURL_POLL_OUT 2 michael@0: #define CURL_POLL_INOUT 3 michael@0: #define CURL_POLL_REMOVE 4 michael@0: michael@0: #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD michael@0: michael@0: #define CURL_CSELECT_IN 0x01 michael@0: #define CURL_CSELECT_OUT 0x02 michael@0: #define CURL_CSELECT_ERR 0x04 michael@0: michael@0: typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ michael@0: curl_socket_t s, /* socket */ michael@0: int what, /* see above */ michael@0: void *userp, /* private callback michael@0: pointer */ michael@0: void *socketp); /* private socket michael@0: pointer */ michael@0: /* michael@0: * Name: curl_multi_timer_callback michael@0: * michael@0: * Desc: Called by libcurl whenever the library detects a change in the michael@0: * maximum number of milliseconds the app is allowed to wait before michael@0: * curl_multi_socket() or curl_multi_perform() must be called michael@0: * (to allow libcurl's timed events to take place). michael@0: * michael@0: * Returns: The callback should return zero. michael@0: */ michael@0: typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ michael@0: long timeout_ms, /* see above */ michael@0: void *userp); /* private callback michael@0: pointer */ michael@0: michael@0: CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, michael@0: int *running_handles); michael@0: michael@0: CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, michael@0: curl_socket_t s, michael@0: int ev_bitmask, michael@0: int *running_handles); michael@0: michael@0: CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, michael@0: int *running_handles); michael@0: michael@0: #ifndef CURL_ALLOW_OLD_MULTI_SOCKET michael@0: /* This macro below was added in 7.16.3 to push users who recompile to use michael@0: the new curl_multi_socket_action() instead of the old curl_multi_socket() michael@0: */ michael@0: #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) michael@0: #endif michael@0: michael@0: /* michael@0: * Name: curl_multi_timeout() michael@0: * michael@0: * Desc: Returns the maximum number of milliseconds the app is allowed to michael@0: * wait before curl_multi_socket() or curl_multi_perform() must be michael@0: * called (to allow libcurl's timed events to take place). michael@0: * michael@0: * Returns: CURLM error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, michael@0: long *milliseconds); michael@0: michael@0: #undef CINIT /* re-using the same name as in curl.h */ michael@0: michael@0: #ifdef CURL_ISOCPP michael@0: #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num michael@0: #else michael@0: /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ michael@0: #define LONG CURLOPTTYPE_LONG michael@0: #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT michael@0: #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT michael@0: #define OFF_T CURLOPTTYPE_OFF_T michael@0: #define CINIT(name,type,number) CURLMOPT_/**/name = type + number michael@0: #endif michael@0: michael@0: typedef enum { michael@0: /* This is the socket callback function pointer */ michael@0: CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), michael@0: michael@0: /* This is the argument passed to the socket callback */ michael@0: CINIT(SOCKETDATA, OBJECTPOINT, 2), michael@0: michael@0: /* set to 1 to enable pipelining for this multi handle */ michael@0: CINIT(PIPELINING, LONG, 3), michael@0: michael@0: /* This is the timer callback function pointer */ michael@0: CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), michael@0: michael@0: /* This is the argument passed to the timer callback */ michael@0: CINIT(TIMERDATA, OBJECTPOINT, 5), michael@0: michael@0: /* maximum number of entries in the connection cache */ michael@0: CINIT(MAXCONNECTS, LONG, 6), michael@0: michael@0: CURLMOPT_LASTENTRY /* the last unused */ michael@0: } CURLMoption; michael@0: michael@0: michael@0: /* michael@0: * Name: curl_multi_setopt() michael@0: * michael@0: * Desc: Sets options for the multi handle. michael@0: * michael@0: * Returns: CURLM error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, michael@0: CURLMoption option, ...); michael@0: michael@0: michael@0: /* michael@0: * Name: curl_multi_assign() michael@0: * michael@0: * Desc: This function sets an association in the multi handle between the michael@0: * given socket and a private pointer of the application. This is michael@0: * (only) useful for curl_multi_socket uses. michael@0: * michael@0: * Returns: CURLM error code. michael@0: */ michael@0: CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, michael@0: curl_socket_t sockfd, void *sockp); michael@0: michael@0: #ifdef __cplusplus michael@0: } /* end of extern "C" */ michael@0: #endif michael@0: michael@0: #endif