multi.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #ifndef __CURL_MULTI_H
  2. #define __CURL_MULTI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2004, Daniel Stenberg, <[email protected]>, 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$
  24. ***************************************************************************/
  25. /*
  26. This is meant to be the "external" header file. Don't give away any
  27. internals here!
  28. This document presents a mixture of ideas from at least:
  29. - Daniel Stenberg
  30. - Steve Dekorte
  31. - Sterling Hughes
  32. - Ben Greear
  33. -------------------------------------------
  34. GOALS
  35. o Enable a "pull" interface. The application that uses libcurl decides where
  36. and when to ask libcurl to get/send data.
  37. o Enable multiple simultaneous transfers in the same thread without making it
  38. complicated for the application.
  39. o Enable the application to select() on its own file descriptors and curl's
  40. file descriptors simultaneous easily.
  41. */
  42. #if defined(_WIN32) && !defined(WIN32)
  43. /* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we
  44. make this adjustment to catch this. */
  45. #define WIN32 1
  46. #endif
  47. #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
  48. #include <winsock2.h>
  49. #else
  50. /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
  51. libc5-based Linux systems. Only include it on system that are known to
  52. require it! */
  53. #if defined(_AIX) || defined(NETWARE)
  54. #include <sys/select.h>
  55. #endif
  56. #include <sys/socket.h>
  57. #include <sys/time.h>
  58. #include <sys/types.h>
  59. #endif
  60. #include "curl.h"
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. typedef void CURLM;
  65. typedef enum {
  66. CURLM_CALL_MULTI_PERFORM=-1, /* please call curl_multi_perform() soon */
  67. CURLM_OK,
  68. CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
  69. CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
  70. CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
  71. CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
  72. CURLM_LAST
  73. } CURLMcode;
  74. typedef enum {
  75. CURLMSG_NONE, /* first, not used */
  76. CURLMSG_DONE, /* This easy handle has completed. 'result' contains
  77. the CURLcode of the transfer */
  78. CURLMSG_LAST /* last, not used */
  79. } CURLMSG;
  80. struct CURLMsg {
  81. CURLMSG msg; /* what this message means */
  82. CURL *easy_handle; /* the handle it concerns */
  83. union {
  84. void *whatever; /* message-specific data */
  85. CURLcode result; /* return code for transfer */
  86. } data;
  87. };
  88. typedef struct CURLMsg CURLMsg;
  89. /*
  90. * Name: curl_multi_init()
  91. *
  92. * Desc: inititalize multi-style curl usage
  93. * Returns: a new CURLM handle to use in all 'curl_multi' functions.
  94. */
  95. CURLM *curl_multi_init(void);
  96. /*
  97. * Name: curl_multi_add_handle()
  98. *
  99. * Desc: add a standard curl handle to the multi stack
  100. * Returns: CURLMcode type, general multi error code.
  101. */
  102. CURLMcode curl_multi_add_handle(CURLM *multi_handle,
  103. CURL *curl_handle);
  104. /*
  105. * Name: curl_multi_remove_handle()
  106. *
  107. * Desc: removes a curl handle from the multi stack again
  108. * Returns: CURLMcode type, general multi error code.
  109. */
  110. CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
  111. CURL *curl_handle);
  112. /*
  113. * Name: curl_multi_fdset()
  114. *
  115. * Desc: Ask curl for its fd_set sets. The app can use these to select() or
  116. * poll() on. We want curl_multi_perform() called as soon as one of
  117. * them are ready.
  118. * Returns: CURLMcode type, general multi error code.
  119. */
  120. CURLMcode curl_multi_fdset(CURLM *multi_handle,
  121. fd_set *read_fd_set,
  122. fd_set *write_fd_set,
  123. fd_set *exc_fd_set,
  124. int *max_fd);
  125. /*
  126. * Name: curl_multi_perform()
  127. *
  128. * Desc: When the app thinks there's data available for curl it calls this
  129. * function to read/write whatever there is right now. This returns
  130. * as soon as the reads and writes are done. This function does not
  131. * require that there actually is data available for reading or that
  132. * data can be written, it can be called just in case. It returns
  133. * the number of handles that still transfer data in the second
  134. * argument's integer-pointer.
  135. *
  136. * Returns: CURLMcode type, general multi error code. *NOTE* that this only
  137. * returns errors etc regarding the whole multi stack. There might
  138. * still have occurred problems on invidual transfers even when this
  139. * returns OK.
  140. */
  141. CURLMcode curl_multi_perform(CURLM *multi_handle,
  142. int *running_handles);
  143. /*
  144. * Name: curl_multi_cleanup()
  145. *
  146. * Desc: Cleans up and removes a whole multi stack. It does not free or
  147. * touch any individual easy handles in any way. We need to define
  148. * in what state those handles will be if this function is called
  149. * in the middle of a transfer.
  150. * Returns: CURLMcode type, general multi error code.
  151. */
  152. CURLMcode curl_multi_cleanup(CURLM *multi_handle);
  153. /*
  154. * Name: curl_multi_info_read()
  155. *
  156. * Desc: Ask the multi handle if there's any messages/informationals from
  157. * the individual transfers. Messages include informationals such as
  158. * error code from the transfer or just the fact that a transfer is
  159. * completed. More details on these should be written down as well.
  160. *
  161. * Repeated calls to this function will return a new struct each
  162. * time, until a special "end of msgs" struct is returned as a signal
  163. * that there is no more to get at this point.
  164. *
  165. * The data the returned pointer points to will not survive calling
  166. * curl_multi_cleanup().
  167. *
  168. * The 'CURLMsg' struct is meant to be very simple and only contain
  169. * very basic informations. If more involved information is wanted,
  170. * we will provide the particular "transfer handle" in that struct
  171. * and that should/could/would be used in subsequent
  172. * curl_easy_getinfo() calls (or similar). The point being that we
  173. * must never expose complex structs to applications, as then we'll
  174. * undoubtably get backwards compatibility problems in the future.
  175. *
  176. * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
  177. * of structs. It also writes the number of messages left in the
  178. * queue (after this read) in the integer the second argument points
  179. * to.
  180. */
  181. CURLMsg *curl_multi_info_read(CURLM *multi_handle,
  182. int *msgs_in_queue);
  183. /*
  184. * NAME curl_multi_strerror()
  185. *
  186. * DESCRIPTION
  187. *
  188. * The curl_multi_strerror function may be used to turn a CURLMcode value
  189. * into the equivalent human readable error string. This is useful
  190. * for printing meaningful error messages.
  191. */
  192. const char *curl_multi_strerror(CURLMcode);
  193. #ifdef __cplusplus
  194. } /* end of extern "C" */
  195. #endif
  196. #endif