multi.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef __CURL_MULTI_H
  2. #define __CURL_MULTI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2002, 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. Example sources using this interface is here: ../multi/
  42. */
  43. #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
  44. #include <winsock.h>
  45. #else
  46. #include <sys/socket.h>
  47. #include <sys/time.h>
  48. #endif
  49. #include "curl.h"
  50. typedef void CURLM;
  51. typedef enum {
  52. CURLM_CALL_MULTI_PERFORM=-1, /* please call curl_multi_perform() soon */
  53. CURLM_OK,
  54. CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
  55. CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
  56. CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
  57. CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
  58. CURLM_LAST
  59. } CURLMcode;
  60. typedef enum {
  61. CURLMSG_NONE, /* first, not used */
  62. CURLMSG_DONE, /* This easy handle has completed. 'whatever' points to
  63. the CURLcode of the transfer */
  64. CURLMSG_LAST /* last, not used */
  65. } CURLMSG;
  66. struct CURLMsg {
  67. CURLMSG msg; /* what this message means */
  68. CURL *easy_handle; /* the handle it concerns */
  69. union {
  70. void *whatever; /* message-specific data */
  71. CURLcode result; /* return code for transfer */
  72. } data;
  73. };
  74. typedef struct CURLMsg CURLMsg;
  75. /*
  76. * Name: curl_multi_init()
  77. *
  78. * Desc: inititalize multi-style curl usage
  79. * Returns: a new CURLM handle to use in all 'curl_multi' functions.
  80. */
  81. CURLM *curl_multi_init(void);
  82. /*
  83. * Name: curl_multi_add_handle()
  84. *
  85. * Desc: add a standard curl handle to the multi stack
  86. * Returns: CURLMcode type, general multi error code.
  87. */
  88. CURLMcode curl_multi_add_handle(CURLM *multi_handle,
  89. CURL *curl_handle);
  90. /*
  91. * Name: curl_multi_remove_handle()
  92. *
  93. * Desc: removes a curl handle from the multi stack again
  94. * Returns: CURLMcode type, general multi error code.
  95. */
  96. CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
  97. CURL *curl_handle);
  98. /*
  99. * Name: curl_multi_fdset()
  100. *
  101. * Desc: Ask curl for its fd_set sets. The app can use these to select() or
  102. * poll() on. We want curl_multi_perform() called as soon as one of
  103. * them are ready.
  104. * Returns: CURLMcode type, general multi error code.
  105. */
  106. CURLMcode curl_multi_fdset(CURLM *multi_handle,
  107. fd_set *read_fd_set,
  108. fd_set *write_fd_set,
  109. fd_set *exc_fd_set,
  110. int *max_fd);
  111. /*
  112. * Name: curl_multi_perform()
  113. *
  114. * Desc: When the app thinks there's data available for curl it calls this
  115. * function to read/write whatever there is right now. This returns
  116. * as soon as the reads and writes are done. This function does not
  117. * require that there actually is data available for reading or that
  118. * data can be written, it can be called just in case. It returns
  119. * the number of handles that still transfer data in the second
  120. * argument's integer-pointer.
  121. *
  122. * Returns: CURLMcode type, general multi error code. *NOTE* that this only
  123. * returns errors etc regarding the whole multi stack. There might
  124. * still have occurred problems on invidual transfers even when this
  125. * returns OK.
  126. */
  127. CURLMcode curl_multi_perform(CURLM *multi_handle,
  128. int *running_handles);
  129. /*
  130. * Name: curl_multi_cleanup()
  131. *
  132. * Desc: Cleans up and removes a whole multi stack. It does not free or
  133. * touch any individual easy handles in any way. We need to define
  134. * in what state those handles will be if this function is called
  135. * in the middle of a transfer.
  136. * Returns: CURLMcode type, general multi error code.
  137. */
  138. CURLMcode curl_multi_cleanup(CURLM *multi_handle);
  139. /*
  140. * Name: curl_multi_info_read()
  141. *
  142. * Desc: Ask the multi handle if there's any messages/informationals from
  143. * the individual transfers. Messages include informationals such as
  144. * error code from the transfer or just the fact that a transfer is
  145. * completed. More details on these should be written down as well.
  146. *
  147. * Repeated calls to this function will return a new struct each
  148. * time, until a special "end of msgs" struct is returned as a signal
  149. * that there is no more to get at this point.
  150. *
  151. * The data the returned pointer points to will not survive calling
  152. * curl_multi_cleanup().
  153. *
  154. * The 'CURLMsg' struct is meant to be very simple and only contain
  155. * very basic informations. If more involved information is wanted,
  156. * we will provide the particular "transfer handle" in that struct
  157. * and that should/could/would be used in subsequent
  158. * curl_easy_getinfo() calls (or similar). The point being that we
  159. * must never expose complex structs to applications, as then we'll
  160. * undoubtably get backwards compatibility problems in the future.
  161. *
  162. * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
  163. * of structs. It also writes the number of messages left in the
  164. * queue (after this read) in the integer the second argument points
  165. * to.
  166. */
  167. CURLMsg *curl_multi_info_read(CURLM *multi_handle,
  168. int *msgs_in_queue);
  169. #endif