Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
13 KiB

  1. #ifndef __CURL_MULTI_H
  2. #define __CURL_MULTI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2007, 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. ***************************************************************************/
  24. /*
  25. This is an "external" header file. Don't give away any internals here!
  26. GOALS
  27. o Enable a "pull" interface. The application that uses libcurl decides where
  28. and when to ask libcurl to get/send data.
  29. o Enable multiple simultaneous transfers in the same thread without making it
  30. complicated for the application.
  31. o Enable the application to select() on its own file descriptors and curl's
  32. file descriptors simultaneous easily.
  33. */
  34. /*
  35. * This header file should not really need to include "curl.h" since curl.h
  36. * itself includes this file and we expect user applications to do #include
  37. * <curl/curl.h> without the need for especially including multi.h.
  38. *
  39. * For some reason we added this include here at one point, and rather than to
  40. * break existing (wrongly written) libcurl applications, we leave it as-is
  41. * but with this warning attached.
  42. */
  43. #include "curl.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. typedef void CURLM;
  48. typedef enum {
  49. CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
  50. curl_multi_socket*() soon */
  51. CURLM_OK,
  52. CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */
  53. CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
  54. CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */
  55. CURLM_INTERNAL_ERROR, /* this is a libcurl bug */
  56. CURLM_BAD_SOCKET, /* the passed in socket argument did not match */
  57. CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
  58. CURLM_LAST
  59. } CURLMcode;
  60. /* just to make code nicer when using curl_multi_socket() you can now check
  61. for CURLM_CALL_MULTI_SOCKET too in the same style it works for
  62. curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
  63. #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
  64. typedef enum {
  65. CURLMSG_NONE, /* first, not used */
  66. CURLMSG_DONE, /* This easy handle has completed. 'result' contains
  67. the CURLcode of the transfer */
  68. CURLMSG_LAST /* last, not used */
  69. } CURLMSG;
  70. struct CURLMsg {
  71. CURLMSG msg; /* what this message means */
  72. CURL *easy_handle; /* the handle it concerns */
  73. union {
  74. void *whatever; /* message-specific data */
  75. CURLcode result; /* return code for transfer */
  76. } data;
  77. };
  78. typedef struct CURLMsg CURLMsg;
  79. /*
  80. * Name: curl_multi_init()
  81. *
  82. * Desc: inititalize multi-style curl usage
  83. *
  84. * Returns: a new CURLM handle to use in all 'curl_multi' functions.
  85. */
  86. CURL_EXTERN CURLM *curl_multi_init(void);
  87. /*
  88. * Name: curl_multi_add_handle()
  89. *
  90. * Desc: add a standard curl handle to the multi stack
  91. *
  92. * Returns: CURLMcode type, general multi error code.
  93. */
  94. CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
  95. CURL *curl_handle);
  96. /*
  97. * Name: curl_multi_remove_handle()
  98. *
  99. * Desc: removes a curl handle from the multi stack again
  100. *
  101. * Returns: CURLMcode type, general multi error code.
  102. */
  103. CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
  104. CURL *curl_handle);
  105. /*
  106. * Name: curl_multi_fdset()
  107. *
  108. * Desc: Ask curl for its fd_set sets. The app can use these to select() or
  109. * poll() on. We want curl_multi_perform() called as soon as one of
  110. * them are ready.
  111. *
  112. * Returns: CURLMcode type, general multi error code.
  113. */
  114. CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
  115. fd_set *read_fd_set,
  116. fd_set *write_fd_set,
  117. fd_set *exc_fd_set,
  118. int *max_fd);
  119. /*
  120. * Name: curl_multi_perform()
  121. *
  122. * Desc: When the app thinks there's data available for curl it calls this
  123. * function to read/write whatever there is right now. This returns
  124. * as soon as the reads and writes are done. This function does not
  125. * require that there actually is data available for reading or that
  126. * data can be written, it can be called just in case. It returns
  127. * the number of handles that still transfer data in the second
  128. * argument's integer-pointer.
  129. *
  130. * Returns: CURLMcode type, general multi error code. *NOTE* that this only
  131. * returns errors etc regarding the whole multi stack. There might
  132. * still have occurred problems on invidual transfers even when this
  133. * returns OK.
  134. */
  135. CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
  136. int *running_handles);
  137. /*
  138. * Name: curl_multi_cleanup()
  139. *
  140. * Desc: Cleans up and removes a whole multi stack. It does not free or
  141. * touch any individual easy handles in any way. We need to define
  142. * in what state those handles will be if this function is called
  143. * in the middle of a transfer.
  144. *
  145. * Returns: CURLMcode type, general multi error code.
  146. */
  147. CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
  148. /*
  149. * Name: curl_multi_info_read()
  150. *
  151. * Desc: Ask the multi handle if there's any messages/informationals from
  152. * the individual transfers. Messages include informationals such as
  153. * error code from the transfer or just the fact that a transfer is
  154. * completed. More details on these should be written down as well.
  155. *
  156. * Repeated calls to this function will return a new struct each
  157. * time, until a special "end of msgs" struct is returned as a signal
  158. * that there is no more to get at this point.
  159. *
  160. * The data the returned pointer points to will not survive calling
  161. * curl_multi_cleanup().
  162. *
  163. * The 'CURLMsg' struct is meant to be very simple and only contain
  164. * very basic informations. If more involved information is wanted,
  165. * we will provide the particular "transfer handle" in that struct
  166. * and that should/could/would be used in subsequent
  167. * curl_easy_getinfo() calls (or similar). The point being that we
  168. * must never expose complex structs to applications, as then we'll
  169. * undoubtably get backwards compatibility problems in the future.
  170. *
  171. * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
  172. * of structs. It also writes the number of messages left in the
  173. * queue (after this read) in the integer the second argument points
  174. * to.
  175. */
  176. CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
  177. int *msgs_in_queue);
  178. /*
  179. * Name: curl_multi_strerror()
  180. *
  181. * Desc: The curl_multi_strerror function may be used to turn a CURLMcode
  182. * value into the equivalent human readable error string. This is
  183. * useful for printing meaningful error messages.
  184. *
  185. * Returns: A pointer to a zero-terminated error message.
  186. */
  187. CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
  188. /*
  189. * Name: curl_multi_socket() and
  190. * curl_multi_socket_all()
  191. *
  192. * Desc: An alternative version of curl_multi_perform() that allows the
  193. * application to pass in one of the file descriptors that have been
  194. * detected to have "action" on them and let libcurl perform.
  195. * See man page for details.
  196. */
  197. #define CURL_POLL_NONE 0
  198. #define CURL_POLL_IN 1
  199. #define CURL_POLL_OUT 2
  200. #define CURL_POLL_INOUT 3
  201. #define CURL_POLL_REMOVE 4
  202. #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
  203. #define CURL_CSELECT_IN 0x01
  204. #define CURL_CSELECT_OUT 0x02
  205. #define CURL_CSELECT_ERR 0x04
  206. typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */
  207. curl_socket_t s, /* socket */
  208. int what, /* see above */
  209. void *userp, /* private callback
  210. pointer */
  211. void *socketp); /* private socket
  212. pointer */
  213. /*
  214. * Name: curl_multi_timer_callback
  215. *
  216. * Desc: Called by libcurl whenever the library detects a change in the
  217. * maximum number of milliseconds the app is allowed to wait before
  218. * curl_multi_socket() or curl_multi_perform() must be called
  219. * (to allow libcurl's timed events to take place).
  220. *
  221. * Returns: The callback should return zero.
  222. */
  223. typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */
  224. long timeout_ms, /* see above */
  225. void *userp); /* private callback
  226. pointer */
  227. CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
  228. int *running_handles);
  229. CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
  230. curl_socket_t s,
  231. int ev_bitmask,
  232. int *running_handles);
  233. CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle,
  234. int *running_handles);
  235. #ifndef CURL_ALLOW_OLD_MULTI_SOCKET
  236. /* This macro below was added in 7.16.3 to push users who recompile to use
  237. the new curl_multi_socket_action() instead of the old curl_multi_socket()
  238. */
  239. #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
  240. #endif
  241. /*
  242. * Name: curl_multi_timeout()
  243. *
  244. * Desc: Returns the maximum number of milliseconds the app is allowed to
  245. * wait before curl_multi_socket() or curl_multi_perform() must be
  246. * called (to allow libcurl's timed events to take place).
  247. *
  248. * Returns: CURLM error code.
  249. */
  250. CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
  251. long *milliseconds);
  252. #undef CINIT /* re-using the same name as in curl.h */
  253. #ifdef CURL_ISOCPP
  254. #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num
  255. #else
  256. /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
  257. #define LONG CURLOPTTYPE_LONG
  258. #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
  259. #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
  260. #define OFF_T CURLOPTTYPE_OFF_T
  261. #define CINIT(name,type,number) CURLMOPT_/**/name = type + number
  262. #endif
  263. typedef enum {
  264. /* This is the socket callback function pointer */
  265. CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1),
  266. /* This is the argument passed to the socket callback */
  267. CINIT(SOCKETDATA, OBJECTPOINT, 2),
  268. /* set to 1 to enable pipelining for this multi handle */
  269. CINIT(PIPELINING, LONG, 3),
  270. /* This is the timer callback function pointer */
  271. CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4),
  272. /* This is the argument passed to the timer callback */
  273. CINIT(TIMERDATA, OBJECTPOINT, 5),
  274. /* maximum number of entries in the connection cache */
  275. CINIT(MAXCONNECTS, LONG, 6),
  276. CURLMOPT_LASTENTRY /* the last unused */
  277. } CURLMoption;
  278. /*
  279. * Name: curl_multi_setopt()
  280. *
  281. * Desc: Sets options for the multi handle.
  282. *
  283. * Returns: CURLM error code.
  284. */
  285. CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
  286. CURLMoption option, ...);
  287. /*
  288. * Name: curl_multi_assign()
  289. *
  290. * Desc: This function sets an association in the multi handle between the
  291. * given socket and a private pointer of the application. This is
  292. * (only) useful for curl_multi_socket uses.
  293. *
  294. * Returns: CURLM error code.
  295. */
  296. CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
  297. curl_socket_t sockfd, void *sockp);
  298. #ifdef __cplusplus
  299. } /* end of extern "C" */
  300. #endif
  301. #endif