Install curl-7.28.1.tar.bz2
[msysgit.git] / mingw / include / curl / multi.h
blob6dcd2bac4c118335834e49aeed08ee81e63213ba
1 #ifndef __CURL_MULTI_H
2 #define __CURL_MULTI_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2012, 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_LAST
68 } CURLMcode;
70 /* just to make code nicer when using curl_multi_socket() you can now check
71 for CURLM_CALL_MULTI_SOCKET too in the same style it works for
72 curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
73 #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
75 typedef enum {
76 CURLMSG_NONE, /* first, not used */
77 CURLMSG_DONE, /* This easy handle has completed. 'result' contains
78 the CURLcode of the transfer */
79 CURLMSG_LAST /* last, not used */
80 } CURLMSG;
82 struct CURLMsg {
83 CURLMSG msg; /* what this message means */
84 CURL *easy_handle; /* the handle it concerns */
85 union {
86 void *whatever; /* message-specific data */
87 CURLcode result; /* return code for transfer */
88 } data;
90 typedef struct CURLMsg CURLMsg;
92 /* Based on poll(2) structure and values.
93 * We don't use pollfd and POLL* constants explicitly
94 * to cover platforms without poll(). */
95 #define CURL_WAIT_POLLIN 0x0001
96 #define CURL_WAIT_POLLPRI 0x0002
97 #define CURL_WAIT_POLLOUT 0x0004
99 struct curl_waitfd {
100 curl_socket_t fd;
101 short events;
102 short revents; /* not supported yet */
106 * Name: curl_multi_init()
108 * Desc: inititalize multi-style curl usage
110 * Returns: a new CURLM handle to use in all 'curl_multi' functions.
112 CURL_EXTERN CURLM *curl_multi_init(void);
115 * Name: curl_multi_add_handle()
117 * Desc: add a standard curl handle to the multi stack
119 * Returns: CURLMcode type, general multi error code.
121 CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
122 CURL *curl_handle);
125 * Name: curl_multi_remove_handle()
127 * Desc: removes a curl handle from the multi stack again
129 * Returns: CURLMcode type, general multi error code.
131 CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
132 CURL *curl_handle);
135 * Name: curl_multi_fdset()
137 * Desc: Ask curl for its fd_set sets. The app can use these to select() or
138 * poll() on. We want curl_multi_perform() called as soon as one of
139 * them are ready.
141 * Returns: CURLMcode type, general multi error code.
143 CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
144 fd_set *read_fd_set,
145 fd_set *write_fd_set,
146 fd_set *exc_fd_set,
147 int *max_fd);
150 * Name: curl_multi_wait()
152 * Desc: Poll on all fds within a CURLM set as well as any
153 * additional fds passed to the function.
155 * Returns: CURLMcode type, general multi error code.
157 CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
158 struct curl_waitfd extra_fds[],
159 unsigned int extra_nfds,
160 int timeout_ms,
161 int *ret);
164 * Name: curl_multi_perform()
166 * Desc: When the app thinks there's data available for curl it calls this
167 * function to read/write whatever there is right now. This returns
168 * as soon as the reads and writes are done. This function does not
169 * require that there actually is data available for reading or that
170 * data can be written, it can be called just in case. It returns
171 * the number of handles that still transfer data in the second
172 * argument's integer-pointer.
174 * Returns: CURLMcode type, general multi error code. *NOTE* that this only
175 * returns errors etc regarding the whole multi stack. There might
176 * still have occurred problems on invidual transfers even when this
177 * returns OK.
179 CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
180 int *running_handles);
183 * Name: curl_multi_cleanup()
185 * Desc: Cleans up and removes a whole multi stack. It does not free or
186 * touch any individual easy handles in any way. We need to define
187 * in what state those handles will be if this function is called
188 * in the middle of a transfer.
190 * Returns: CURLMcode type, general multi error code.
192 CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
195 * Name: curl_multi_info_read()
197 * Desc: Ask the multi handle if there's any messages/informationals from
198 * the individual transfers. Messages include informationals such as
199 * error code from the transfer or just the fact that a transfer is
200 * completed. More details on these should be written down as well.
202 * Repeated calls to this function will return a new struct each
203 * time, until a special "end of msgs" struct is returned as a signal
204 * that there is no more to get at this point.
206 * The data the returned pointer points to will not survive calling
207 * curl_multi_cleanup().
209 * The 'CURLMsg' struct is meant to be very simple and only contain
210 * very basic informations. If more involved information is wanted,
211 * we will provide the particular "transfer handle" in that struct
212 * and that should/could/would be used in subsequent
213 * curl_easy_getinfo() calls (or similar). The point being that we
214 * must never expose complex structs to applications, as then we'll
215 * undoubtably get backwards compatibility problems in the future.
217 * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
218 * of structs. It also writes the number of messages left in the
219 * queue (after this read) in the integer the second argument points
220 * to.
222 CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
223 int *msgs_in_queue);
226 * Name: curl_multi_strerror()
228 * Desc: The curl_multi_strerror function may be used to turn a CURLMcode
229 * value into the equivalent human readable error string. This is
230 * useful for printing meaningful error messages.
232 * Returns: A pointer to a zero-terminated error message.
234 CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
237 * Name: curl_multi_socket() and
238 * curl_multi_socket_all()
240 * Desc: An alternative version of curl_multi_perform() that allows the
241 * application to pass in one of the file descriptors that have been
242 * detected to have "action" on them and let libcurl perform.
243 * See man page for details.
245 #define CURL_POLL_NONE 0
246 #define CURL_POLL_IN 1
247 #define CURL_POLL_OUT 2
248 #define CURL_POLL_INOUT 3
249 #define CURL_POLL_REMOVE 4
251 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
253 #define CURL_CSELECT_IN 0x01
254 #define CURL_CSELECT_OUT 0x02
255 #define CURL_CSELECT_ERR 0x04
257 typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
258 curl_socket_t s, /* socket */
259 int what, /* see above */
260 void *userp, /* private callback
261 pointer */
262 void *socketp); /* private socket
263 pointer */
265 * Name: curl_multi_timer_callback
267 * Desc: Called by libcurl whenever the library detects a change in the
268 * maximum number of milliseconds the app is allowed to wait before
269 * curl_multi_socket() or curl_multi_perform() must be called
270 * (to allow libcurl's timed events to take place).
272 * Returns: The callback should return zero.
274 typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
275 long timeout_ms, /* see above */
276 void *userp); /* private callback
277 pointer */
279 CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
280 int *running_handles);
282 CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
283 curl_socket_t s,
284 int ev_bitmask,
285 int *running_handles);
287 CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
288 int *running_handles);
290 #ifndef CURL_ALLOW_OLD_MULTI_SOCKET
291 /* This macro below was added in 7.16.3 to push users who recompile to use
292 the new curl_multi_socket_action() instead of the old curl_multi_socket()
294 #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
295 #endif
298 * Name: curl_multi_timeout()
300 * Desc: Returns the maximum number of milliseconds the app is allowed to
301 * wait before curl_multi_socket() or curl_multi_perform() must be
302 * called (to allow libcurl's timed events to take place).
304 * Returns: CURLM error code.
306 CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
307 long *milliseconds);
309 #undef CINIT /* re-using the same name as in curl.h */
311 #ifdef CURL_ISOCPP
312 #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
313 #else
314 /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
315 #define LONG CURLOPTTYPE_LONG
316 #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
317 #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
318 #define OFF_T CURLOPTTYPE_OFF_T
319 #define CINIT(name,type,number) CURLMOPT_/**/name = type + number
320 #endif
322 typedef enum {
323 /* This is the socket callback function pointer */
324 CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1),
326 /* This is the argument passed to the socket callback */
327 CINIT(SOCKETDATA, OBJECTPOINT, 2),
329 /* set to 1 to enable pipelining for this multi handle */
330 CINIT(PIPELINING, LONG, 3),
332 /* This is the timer callback function pointer */
333 CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4),
335 /* This is the argument passed to the timer callback */
336 CINIT(TIMERDATA, OBJECTPOINT, 5),
338 /* maximum number of entries in the connection cache */
339 CINIT(MAXCONNECTS, LONG, 6),
341 CURLMOPT_LASTENTRY /* the last unused */
342 } CURLMoption;
346 * Name: curl_multi_setopt()
348 * Desc: Sets options for the multi handle.
350 * Returns: CURLM error code.
352 CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
353 CURLMoption option, ...);
357 * Name: curl_multi_assign()
359 * Desc: This function sets an association in the multi handle between the
360 * given socket and a private pointer of the application. This is
361 * (only) useful for curl_multi_socket uses.
363 * Returns: CURLM error code.
365 CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
366 curl_socket_t sockfd, void *sockp);
368 #ifdef __cplusplus
369 } /* end of extern "C" */
370 #endif
372 #endif