multihandle.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef HEADER_CURL_MULTIHANDLE_H
  2. #define HEADER_CURL_MULTIHANDLE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 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 https://curl.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. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "llist.h"
  27. #include "hash.h"
  28. #include "conncache.h"
  29. #include "psl.h"
  30. #include "socketpair.h"
  31. struct connectdata;
  32. struct Curl_message {
  33. struct Curl_llist_node list;
  34. /* the 'CURLMsg' is the part that is visible to the external user */
  35. struct CURLMsg extmsg;
  36. };
  37. /* NOTE: if you add a state here, add the name to the statename[] array as
  38. well!
  39. */
  40. typedef enum {
  41. MSTATE_INIT, /* 0 - start in this state */
  42. MSTATE_PENDING, /* 1 - no connections, waiting for one */
  43. MSTATE_SETUP, /* 2 - start a new transfer */
  44. MSTATE_CONNECT, /* 3 - resolve/connect has been sent off */
  45. MSTATE_RESOLVING, /* 4 - awaiting the resolve to finalize */
  46. MSTATE_CONNECTING, /* 5 - awaiting the TCP connect to finalize */
  47. MSTATE_TUNNELING, /* 6 - awaiting HTTPS proxy SSL initialization to
  48. complete and/or proxy CONNECT to finalize */
  49. MSTATE_PROTOCONNECT, /* 7 - initiate protocol connect procedure */
  50. MSTATE_PROTOCONNECTING, /* 8 - completing the protocol-specific connect
  51. phase */
  52. MSTATE_DO, /* 9 - start send off the request (part 1) */
  53. MSTATE_DOING, /* 10 - sending off the request (part 1) */
  54. MSTATE_DOING_MORE, /* 11 - send off the request (part 2) */
  55. MSTATE_DID, /* 12 - done sending off request */
  56. MSTATE_PERFORMING, /* 13 - transfer data */
  57. MSTATE_RATELIMITING, /* 14 - wait because limit-rate exceeded */
  58. MSTATE_DONE, /* 15 - post data transfer operation */
  59. MSTATE_COMPLETED, /* 16 - operation complete */
  60. MSTATE_MSGSENT, /* 17 - the operation complete message is sent */
  61. MSTATE_LAST /* 18 - not a true state, never use this */
  62. } CURLMstate;
  63. /* we support N sockets per easy handle. Set the corresponding bit to what
  64. action we should wait for */
  65. #define MAX_SOCKSPEREASYHANDLE 5
  66. #define GETSOCK_READABLE (0x00ff)
  67. #define GETSOCK_WRITABLE (0xff00)
  68. #define CURLPIPE_ANY (CURLPIPE_MULTIPLEX)
  69. #if !defined(CURL_DISABLE_SOCKETPAIR)
  70. #define ENABLE_WAKEUP
  71. #endif
  72. /* value for MAXIMUM CONCURRENT STREAMS upper limit */
  73. #define INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
  74. /* This is the struct known as CURLM on the outside */
  75. struct Curl_multi {
  76. /* First a simple identifier to easier detect if a user mix up
  77. this multi handle with an easy handle. Set this to CURL_MULTI_HANDLE. */
  78. unsigned int magic;
  79. unsigned int num_easy; /* amount of entries in the linked list above. */
  80. unsigned int num_alive; /* amount of easy handles that are added but have
  81. not yet reached COMPLETE state */
  82. struct Curl_llist msglist; /* a list of messages from completed transfers */
  83. /* Each added easy handle is added to ONE of these three lists */
  84. struct Curl_llist process; /* not in PENDING or MSGSENT */
  85. struct Curl_llist pending; /* in PENDING */
  86. struct Curl_llist msgsent; /* in MSGSENT */
  87. curl_off_t next_easy_mid; /* next multi-id for easy handle added */
  88. /* callback function and user data pointer for the *socket() API */
  89. curl_socket_callback socket_cb;
  90. void *socket_userp;
  91. /* callback function and user data pointer for server push */
  92. curl_push_callback push_cb;
  93. void *push_userp;
  94. /* Hostname cache */
  95. struct Curl_hash hostcache;
  96. #ifdef USE_LIBPSL
  97. /* PSL cache. */
  98. struct PslCache psl;
  99. #endif
  100. /* timetree points to the splay-tree of time nodes to figure out expire
  101. times of all currently set timers */
  102. struct Curl_tree *timetree;
  103. /* buffer used for transfer data, lazy initialized */
  104. char *xfer_buf; /* the actual buffer */
  105. size_t xfer_buf_len; /* the allocated length */
  106. /* buffer used for upload data, lazy initialized */
  107. char *xfer_ulbuf; /* the actual buffer */
  108. size_t xfer_ulbuf_len; /* the allocated length */
  109. /* buffer used for socket I/O operations, lazy initialized */
  110. char *xfer_sockbuf; /* the actual buffer */
  111. size_t xfer_sockbuf_len; /* the allocated length */
  112. /* 'sockhash' is the lookup hash for socket descriptor => easy handles (note
  113. the pluralis form, there can be more than one easy handle waiting on the
  114. same actual socket) */
  115. struct Curl_hash sockhash;
  116. /* `proto_hash` is a general key-value store for protocol implementations
  117. * with the lifetime of the multi handle. The number of elements kept here
  118. * should be in the order of supported protocols (and sub-protocols like
  119. * TLS), *not* in the order of connections or current transfers!
  120. * Elements need to be added with their own destructor to be invoked when
  121. * the multi handle is cleaned up (see Curl_hash_add2()).*/
  122. struct Curl_hash proto_hash;
  123. /* Shared connection cache (bundles)*/
  124. struct cpool cpool;
  125. long max_host_connections; /* if >0, a fixed limit of the maximum number
  126. of connections per host */
  127. long max_total_connections; /* if >0, a fixed limit of the maximum number
  128. of connections in total */
  129. long max_shutdown_connections; /* if >0, a fixed limit of the maximum number
  130. of connections in shutdown handling */
  131. /* timer callback and user data pointer for the *socket() API */
  132. curl_multi_timer_callback timer_cb;
  133. void *timer_userp;
  134. long last_timeout_ms; /* the last timeout value set via timer_cb */
  135. struct curltime last_expire_ts; /* timestamp of last expiry */
  136. #ifdef USE_WINSOCK
  137. WSAEVENT wsa_event; /* Winsock event used for waits */
  138. #else
  139. #ifdef ENABLE_WAKEUP
  140. curl_socket_t wakeup_pair[2]; /* eventfd()/pipe()/socketpair() used for
  141. wakeup 0 is used for read, 1 is used
  142. for write */
  143. #endif
  144. #endif
  145. unsigned int max_concurrent_streams;
  146. unsigned int maxconnects; /* if >0, a fixed limit of the maximum number of
  147. entries we are allowed to grow the connection
  148. cache to */
  149. #define IPV6_UNKNOWN 0
  150. #define IPV6_DEAD 1
  151. #define IPV6_WORKS 2
  152. unsigned char ipv6_up; /* IPV6_* defined */
  153. BIT(multiplexing); /* multiplexing wanted */
  154. BIT(recheckstate); /* see Curl_multi_connchanged */
  155. BIT(in_callback); /* true while executing a callback */
  156. #ifdef USE_OPENSSL
  157. BIT(ssl_seeded);
  158. #endif
  159. BIT(dead); /* a callback returned error, everything needs to crash and
  160. burn */
  161. BIT(xfer_buf_borrowed); /* xfer_buf is currently being borrowed */
  162. BIT(xfer_ulbuf_borrowed); /* xfer_ulbuf is currently being borrowed */
  163. BIT(xfer_sockbuf_borrowed); /* xfer_sockbuf is currently being borrowed */
  164. #ifdef DEBUGBUILD
  165. BIT(warned); /* true after user warned of DEBUGBUILD */
  166. #endif
  167. };
  168. #endif /* HEADER_CURL_MULTIHANDLE_H */