Install curl-7.41.0.tar.bz2
[msysgit.git] / mingw / include / curl / multi.h
blob3c4acb0f6eafdedaa81bcd24af8f0b5353b5f304
1 #ifndef __CURL_MULTI_H
2 #define __CURL_MULTI_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
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 http://curl.haxx.se/docs/copyright.html.
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 This is an "external" header file. Don't give away any internals here!
27 GOALS
29 o Enable a "pull" interface. The application that uses libcurl decides where
30 and when to ask libcurl to get/send data.
32 o Enable multiple simultaneous transfers in the same thread without making it
33 complicated for the application.
35 o Enable the application to select() on its own file descriptors and curl's
36 file descriptors simultaneous easily.
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.
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.
49 #include "curl.h"
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
55 typedef void CURLM;
57 typedef enum {
58 CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
59 curl_multi_socket*() soon */
60 CURLM_OK,
61 CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
62 CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
63 CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
64 CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
65 CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
66 CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
67 CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
68 attempted to get added - again */
69 CURLM_LAST
70 } CURLMcode;
72 /* just to make code nicer when using curl_multi_socket() you can now check
73 for CURLM_CALL_MULTI_SOCKET too in the same style it works for
74 curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
75 #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
77 typedef enum {
78 CURLMSG_NONE, /* first, not used */
79 CURLMSG_DONE, /* This easy handle has completed. 'result' contains
80 the CURLcode of the transfer */
81 CURLMSG_LAST /* last, not used */
82 } CURLMSG;
84 struct CURLMsg {
85 CURLMSG msg; /* what this message means */
86 CURL *easy_handle; /* the handle it concerns */
87 union {
88 void *whatever; /* message-specific data */
89 CURLcode result; /* return code for transfer */
90 } data;
92 typedef struct CURLMsg CURLMsg;
94 /* Based on poll(2) structure and values.
95 * We don't use pollfd and POLL* constants explicitly
96 * to cover platforms without poll(). */
97 #define CURL_WAIT_POLLIN 0x0001
98 #define CURL_WAIT_POLLPRI 0x0002
99 #define CURL_WAIT_POLLOUT 0x0004
101 struct curl_waitfd {
102 curl_socket_t fd;
103 short events;
104 short revents; /* not supported yet */
108 * Name: curl_multi_init()
110 * Desc: inititalize multi-style curl usage
112 * Returns: a new CURLM handle to use in all 'curl_multi' functions.
114 CURL_EXTERN CURLM *curl_multi_init(void);
117 * Name: curl_multi_add_handle()
119 * Desc: add a standard curl handle to the multi stack
121 * Returns: CURLMcode type, general multi error code.
123 CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
124 CURL *curl_handle);
127 * Name: curl_multi_remove_handle()
129 * Desc: removes a curl handle from the multi stack again
131 * Returns: CURLMcode type, general multi error code.
133 CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
134 CURL *curl_handle);
137 * Name: curl_multi_fdset()
139 * Desc: Ask curl for its fd_set sets. The app can use these to select() or
140 * poll() on. We want curl_multi_perform() called as soon as one of
141 * them are ready.
143 * Returns: CURLMcode type, general multi error code.
145 CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
146 fd_set *read_fd_set,
147 fd_set *write_fd_set,
148 fd_set *exc_fd_set,
149 int *max_fd);
152 * Name: curl_multi_wait()
154 * Desc: Poll on all fds within a CURLM set as well as any
155 * additional fds passed to the function.
157 * Returns: CURLMcode type, general multi error code.
159 CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
160 struct curl_waitfd extra_fds[],
161 unsigned int extra_nfds,
162 int timeout_ms,
163 int *ret);
166 * Name: curl_multi_perform()
168 * Desc: When the app thinks there's data available for curl it calls this
169 * function to read/write whatever there is right now. This returns
170 * as soon as the reads and writes are done. This function does not
171 * require that there actually is data available for reading or that
172 * data can be written, it can be called just in case. It returns
173 * the number of handles that still transfer data in the second
174 * argument's integer-pointer.
176 * Returns: CURLMcode type, general multi error code. *NOTE* that this only
177 * returns errors etc regarding the whole multi stack. There might
178 * still have occurred problems on invidual transfers even when this
179 * returns OK.
181 CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
182 int *running_handles);
185 * Name: curl_multi_cleanup()
187 * Desc: Cleans up and removes a whole multi stack. It does not free or
188 * touch any individual easy handles in any way. We need to define
189 * in what state those handles will be if this function is called
190 * in the middle of a transfer.
192 * Returns: CURLMcode type, general multi error code.
194 CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
197 * Name: curl_multi_info_read()
199 * Desc: Ask the multi handle if there's any messages/informationals from
200 * the individual transfers. Messages include informationals such as
201 * error code from the transfer or just the fact that a transfer is
202 * completed. More details on these should be written down as well.
204 * Repeated calls to this function will return a new struct each
205 * time, until a special "end of msgs" struct is returned as a signal
206 * that there is no more to get at this point.
208 * The data the returned pointer points to will not survive calling
209 * curl_multi_cleanup().
211 * The 'CURLMsg' struct is meant to be very simple and only contain
212 * very basic informations. If more involved information is wanted,
213 * we will provide the particular "transfer handle" in that struct
214 * and that should/could/would be used in subsequent
215 * curl_easy_getinfo() calls (or similar). The point being that we
216 * must never expose complex structs to applications, as then we'll
217 * undoubtably get backwards compatibility problems in the future.
219 * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
220 * of structs. It also writes the number of messages left in the
221 * queue (after this read) in the integer the second argument points
222 * to.
224 CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
225 int *msgs_in_queue);
228 * Name: curl_multi_strerror()
230 * Desc: The curl_multi_strerror function may be used to turn a CURLMcode
231 * value into the equivalent human readable error string. This is
232 * useful for printing meaningful error messages.
234 * Returns: A pointer to a zero-terminated error message.
236 CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
239 * Name: curl_multi_socket() and
240 * curl_multi_socket_all()
242 * Desc: An alternative version of curl_multi_perform() that allows the
243 * application to pass in one of the file descriptors that have been
244 * detected to have "action" on them and let libcurl perform.
245 * See man page for details.
247 #define CURL_POLL_NONE 0
248 #define CURL_POLL_IN 1
249 #define CURL_POLL_OUT 2
250 #define CURL_POLL_INOUT 3
251 #define CURL_POLL_REMOVE 4
253 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
255 #define CURL_CSELECT_IN 0x01
256 #define CURL_CSELECT_OUT 0x02
257 #define CURL_CSELECT_ERR 0x04
259 typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
260 curl_socket_t s, /* socket */
261 int what, /* see above */
262 void *userp, /* private callback
263 pointer */
264 void *socketp); /* private socket
265 pointer */
267 * Name: curl_multi_timer_callback
269 * Desc: Called by libcurl whenever the library detects a change in the
270 * maximum number of milliseconds the app is allowed to wait before
271 * curl_multi_socket() or curl_multi_perform() must be called
272 * (to allow libcurl's timed events to take place).
274 * Returns: The callback should return zero.
276 typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
277 long timeout_ms, /* see above */
278 void *userp); /* private callback
279 pointer */
281 CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
282 int *running_handles);
284 CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
285 curl_socket_t s,
286 int ev_bitmask,
287 int *running_handles);
289 CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
290 int *running_handles);
292 #ifndef CURL_ALLOW_OLD_MULTI_SOCKET
293 /* This macro below was added in 7.16.3 to push users who recompile to use
294 the new curl_multi_socket_action() instead of the old curl_multi_socket()
296 #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
297 #endif
300 * Name: curl_multi_timeout()
302 * Desc: Returns the maximum number of milliseconds the app is allowed to
303 * wait before curl_multi_socket() or curl_multi_perform() must be
304 * called (to allow libcurl's timed events to take place).
306 * Returns: CURLM error code.
308 CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
309 long *milliseconds);
311 #undef CINIT /* re-using the same name as in curl.h */
313 #ifdef CURL_ISOCPP
314 #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
315 #else
316 /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
317 #define LONG CURLOPTTYPE_LONG
318 #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
319 #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
320 #define OFF_T CURLOPTTYPE_OFF_T
321 #define CINIT(name,type,number) CURLMOPT_/**/name = type + number
322 #endif
324 typedef enum {
325 /* This is the socket callback function pointer */
326 CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1),
328 /* This is the argument passed to the socket callback */
329 CINIT(SOCKETDATA, OBJECTPOINT, 2),
331 /* set to 1 to enable pipelining for this multi handle */
332 CINIT(PIPELINING, LONG, 3),
334 /* This is the timer callback function pointer */
335 CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4),
337 /* This is the argument passed to the timer callback */
338 CINIT(TIMERDATA, OBJECTPOINT, 5),
340 /* maximum number of entries in the connection cache */
341 CINIT(MAXCONNECTS, LONG, 6),
343 /* maximum number of (pipelining) connections to one host */
344 CINIT(MAX_HOST_CONNECTIONS, LONG, 7),
346 /* maximum number of requests in a pipeline */
347 CINIT(MAX_PIPELINE_LENGTH, LONG, 8),
349 /* a connection with a content-length longer than this
350 will not be considered for pipelining */
351 CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9),
353 /* a connection with a chunk length longer than this
354 will not be considered for pipelining */
355 CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10),
357 /* a list of site names(+port) that are blacklisted from
358 pipelining */
359 CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11),
361 /* a list of server types that are blacklisted from
362 pipelining */
363 CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12),
365 /* maximum number of open connections in total */
366 CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13),
368 CURLMOPT_LASTENTRY /* the last unused */
369 } CURLMoption;
373 * Name: curl_multi_setopt()
375 * Desc: Sets options for the multi handle.
377 * Returns: CURLM error code.
379 CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
380 CURLMoption option, ...);
384 * Name: curl_multi_assign()
386 * Desc: This function sets an association in the multi handle between the
387 * given socket and a private pointer of the application. This is
388 * (only) useful for curl_multi_socket uses.
390 * Returns: CURLM error code.
392 CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
393 curl_socket_t sockfd, void *sockp);
395 #ifdef __cplusplus
396 } /* end of extern "C" */
397 #endif
399 #endif