first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / production / 3rdparty / curl / include / curl / multi.h
1 #ifndef __CURL_MULTI_H
2 #define __CURL_MULTI_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
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.
15  *
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.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  * $Id: multi.h,v 1.1 2006/07/09 22:41:14 fred_t_hamster Exp $
24  ***************************************************************************/
25 /*
26   This is an "external" header file. Don't give away any internals here!
27
28   GOALS
29
30   o Enable a "pull" interface. The application that uses libcurl decides where
31     and when to ask libcurl to get/send data.
32
33   o Enable multiple simultaneous transfers in the same thread without making it
34     complicated for the application.
35
36   o Enable the application to select() on its own file descriptors and curl's
37     file descriptors simultaneous easily.
38
39 */
40 #if defined(_WIN32) && !defined(WIN32)
41 /* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we
42    make this adjustment to catch this. */
43 #define WIN32 1
44 #endif
45
46 #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) || \
47   defined(__MINGW32__)
48 #if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H))
49 /* The check above prevents the winsock2 inclusion if winsock.h already was
50    included, since they can't co-exist without problems */
51 #include <winsock2.h>
52 #endif
53 #else
54
55 /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
56    libc5-based Linux systems. Only include it on system that are known to
57    require it! */
58 #if defined(_AIX) || defined(NETWARE)
59 #include <sys/select.h>
60 #endif
61
62 #ifndef _WIN32_WCE
63 #include <sys/socket.h>
64 #endif
65 #include <sys/time.h>
66 #include <sys/types.h>
67 #endif
68
69 /*
70  * This header file should not really need to include "curl.h" since curl.h
71  * itself includes this file and we expect user applications to do #include
72  * <curl/curl.h> without the need for especially including multi.h.
73  *
74  * For some reason we added this include here at one point, and rather than to
75  * break existing (wrongly written) libcurl applications, we leave it as-is
76  * but with this warning attached.
77  */
78 #include "curl.h"
79
80 #ifdef  __cplusplus
81 extern "C" {
82 #endif
83
84 typedef void CURLM;
85
86 #ifdef HAVE_CURL_MULTI_SOCKET /* this is not set by anything yet */
87
88 #ifndef curl_socket_typedef
89 /* Public socket typedef */
90 #ifdef WIN32
91 typedef SOCKET curl_socket_t;
92 #define CURL_SOCKET_BAD INVALID_SOCKET
93 #else
94 typedef int curl_socket_t;
95 #define CURL_SOCKET_BAD -1
96 #endif
97 #define curl_socket_typedef
98 #endif /* curl_socket_typedef */
99
100 #endif /* HAVE_CURL_MULTI_SOCKET */
101
102 typedef enum {
103   CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() soon */
104   CURLM_OK,
105   CURLM_BAD_HANDLE,      /* the passed-in handle is not a valid CURLM handle */
106   CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
107   CURLM_OUT_OF_MEMORY,   /* if you ever get this, you're in deep sh*t */
108   CURLM_INTERNAL_ERROR,  /* this is a libcurl bug */
109   CURLM_LAST
110 } CURLMcode;
111
112 typedef enum {
113   CURLMSG_NONE, /* first, not used */
114   CURLMSG_DONE, /* This easy handle has completed. 'result' contains
115                    the CURLcode of the transfer */
116   CURLMSG_LAST /* last, not used */
117 } CURLMSG;
118
119 struct CURLMsg {
120   CURLMSG msg;       /* what this message means */
121   CURL *easy_handle; /* the handle it concerns */
122   union {
123     void *whatever;    /* message-specific data */
124     CURLcode result;   /* return code for transfer */
125   } data;
126 };
127 typedef struct CURLMsg CURLMsg;
128
129 /*
130  * Name:    curl_multi_init()
131  *
132  * Desc:    inititalize multi-style curl usage
133  *
134  * Returns: a new CURLM handle to use in all 'curl_multi' functions.
135  */
136 CURL_EXTERN CURLM *curl_multi_init(void);
137
138 /*
139  * Name:    curl_multi_add_handle()
140  *
141  * Desc:    add a standard curl handle to the multi stack
142  *
143  * Returns: CURLMcode type, general multi error code.
144  */
145 CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
146                                             CURL *curl_handle);
147
148  /*
149   * Name:    curl_multi_remove_handle()
150   *
151   * Desc:    removes a curl handle from the multi stack again
152   *
153   * Returns: CURLMcode type, general multi error code.
154   */
155 CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
156                                                CURL *curl_handle);
157
158  /*
159   * Name:    curl_multi_fdset()
160   *
161   * Desc:    Ask curl for its fd_set sets. The app can use these to select() or
162   *          poll() on. We want curl_multi_perform() called as soon as one of
163   *          them are ready.
164   *
165   * Returns: CURLMcode type, general multi error code.
166   */
167 CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
168                                        fd_set *read_fd_set,
169                                        fd_set *write_fd_set,
170                                        fd_set *exc_fd_set,
171                                        int *max_fd);
172
173  /*
174   * Name:    curl_multi_perform()
175   *
176   * Desc:    When the app thinks there's data available for curl it calls this
177   *          function to read/write whatever there is right now. This returns
178   *          as soon as the reads and writes are done. This function does not
179   *          require that there actually is data available for reading or that
180   *          data can be written, it can be called just in case. It returns
181   *          the number of handles that still transfer data in the second
182   *          argument's integer-pointer.
183   *
184   * Returns: CURLMcode type, general multi error code. *NOTE* that this only
185   *          returns errors etc regarding the whole multi stack. There might
186   *          still have occurred problems on invidual transfers even when this
187   *          returns OK.
188   */
189 CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
190                                          int *running_handles);
191
192  /*
193   * Name:    curl_multi_cleanup()
194   *
195   * Desc:    Cleans up and removes a whole multi stack. It does not free or
196   *          touch any individual easy handles in any way. We need to define
197   *          in what state those handles will be if this function is called
198   *          in the middle of a transfer.
199   *
200   * Returns: CURLMcode type, general multi error code.
201   */
202 CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
203
204 /*
205  * Name:    curl_multi_info_read()
206  *
207  * Desc:    Ask the multi handle if there's any messages/informationals from
208  *          the individual transfers. Messages include informationals such as
209  *          error code from the transfer or just the fact that a transfer is
210  *          completed. More details on these should be written down as well.
211  *
212  *          Repeated calls to this function will return a new struct each
213  *          time, until a special "end of msgs" struct is returned as a signal
214  *          that there is no more to get at this point.
215  *
216  *          The data the returned pointer points to will not survive calling
217  *          curl_multi_cleanup().
218  *
219  *          The 'CURLMsg' struct is meant to be very simple and only contain
220  *          very basic informations. If more involved information is wanted,
221  *          we will provide the particular "transfer handle" in that struct
222  *          and that should/could/would be used in subsequent
223  *          curl_easy_getinfo() calls (or similar). The point being that we
224  *          must never expose complex structs to applications, as then we'll
225  *          undoubtably get backwards compatibility problems in the future.
226  *
227  * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
228  *          of structs. It also writes the number of messages left in the
229  *          queue (after this read) in the integer the second argument points
230  *          to.
231  */
232 CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
233                                           int *msgs_in_queue);
234
235 /*
236  * Name:    curl_multi_strerror()
237  *
238  * Desc:    The curl_multi_strerror function may be used to turn a CURLMcode
239  *          value into the equivalent human readable error string.  This is
240  *          useful for printing meaningful error messages.
241  *
242  * Returns: A pointer to a zero-terminated error message.
243  */
244 CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
245
246 #ifdef HAVE_CURL_MULTI_SOCKET
247 /*
248  * Name:    curl_multi_socket() and
249  *          curl_multi_socket_all()
250  *
251  * Desc:    An alternative version of curl_multi_perform() that allows the
252  *          application to pass in one of the file descriptors that have been
253  *          detected to have "action" on them and let libcurl perform. This
254  *          allows libcurl to not have to scan through all possible file
255  *          descriptors to check for this. The app is recommended to pass in
256  *          the 'easy' argument (or set it to CURL_EASY_NONE) to make libcurl
257  *          figure out the internal structure even faster and easier.  If the
258  *          easy argument is set to something else than CURL_EASY_NONE, the
259  *          's' (socket) argument will be ignored by libcurl.
260  *
261  *          It also informs the application about updates in the socket (file
262  *          descriptor) status by doing none, one or multiple calls to the
263  *          curl_socket_callback. It thus updates the status with changes
264  *          since the previous time this function was used. If 'callback' is
265  *          NULL, no callback will be called. A status change may also be a
266  *          new timeout only, having the same IN/OUT status as before.
267  *
268  *          If a previous wait for socket action(s) timed out, you should call
269  *          this function with the socket argument set to
270  *          CURL_SOCKET_TIMEOUT. If you want to force libcurl to (re-)check
271  *          all its internal sockets, and call the callback with status for
272  *          all sockets no matter what the previous state is, you call
273  *          curl_multi_socket_all() instead.
274  *
275  *          curl_multi_perform() is thus the equivalent of calling
276  *          curl_multi_socket_all(handle, NULL, NULL);
277  *
278  *          IMPLEMENTATION: libcurl will need an internal hash table to map
279  *          socket numbers to internal easy handles for the cases when 'easy'
280  *          is set to CURL_EASY_NONE.
281  *
282  *          Regarding the timeout argument in the callback: it is the timeout
283  *          (in milliseconds) for waiting on action on this socket (and the
284  *          given time period starts when the callback is called) until you
285  *          should call curl_multi_socket() with the timeout stuff mentioned
286  *          above. If "actions" happens on the socket before the timeout
287  *          happens, remember that the timout timer keeps ticking until told
288  *          otherwise.
289  *
290  *          The "what" argument has one of five values:
291  *
292  *            0 CURL_POLL_NONE (0)   - register, not interested in readiness
293  *            1 CURL_POLL_IN         - register, interested in read readiness
294  *            2 CURL_POLL_OUT        - register, interested in write readiness
295  *            3 CURL_POLL_INOUT      - register, interested in both
296  *            4 CURL_POLL_REMOVE     - deregister
297  */
298 #define CURL_POLL_NONE   0
299 #define CURL_POLL_IN     1
300 #define CURL_POLL_OUT    2
301 #define CURL_POLL_INOUT  3
302 #define CURL_POLL_REMOVE 4
303
304 #define CURL_EASY_NONE (CURL *)0
305 #define CURL_EASY_TIMEOUT (CURL *)0
306 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
307
308 typedef int (*curl_socket_callback)(CURL *easy,      /* easy handle */
309                                     curl_socket_t s, /* socket */
310                                     int what,        /* see above */
311                                     long ms,         /* timeout for wait */
312                                     void *userp);    /* "private" pointer */
313
314 CURLMcode curl_multi_socket(CURLM *multi_handle,
315                             curl_socket_t s,
316                             CURL *easy,
317                             curl_socket_callback callback,
318                             void *userp); /* passed to callback */
319
320 CURLMcode curl_multi_socket_all(CURLM *multi_handle,
321                                 curl_socket_callback callback,
322                                 void *userp); /* passed to callback */
323
324 /*
325  * Name:    curl_multi_timeout()
326  *
327  * Desc:    Returns the maximum number of milliseconds the app is allowed to
328  *          wait before curl_multi_socket() or curl_multi_perform() must be
329  *          called (to allow libcurl's timed events to take place).
330  *
331  * Returns: CURLM error code.
332  */
333 CURLMcode curl_multi_timeout(CURLM *multi_handle, long *milliseconds);
334
335 #endif /* HAVE_CURL_MULTI_SOCKET */
336
337 #ifdef __cplusplus
338 } /* end of extern "C" */
339 #endif
340
341 #endif