multihandle.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_element 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_CONNECT, /* 2 - resolve/connect has been sent off */
  44. MSTATE_RESOLVING, /* 3 - awaiting the resolve to finalize */
  45. MSTATE_CONNECTING, /* 4 - awaiting the TCP connect to finalize */
  46. MSTATE_TUNNELING, /* 5 - awaiting HTTPS proxy SSL initialization to
  47. complete and/or proxy CONNECT to finalize */
  48. MSTATE_PROTOCONNECT, /* 6 - initiate protocol connect procedure */
  49. MSTATE_PROTOCONNECTING, /* 7 - completing the protocol-specific connect
  50. phase */
  51. MSTATE_DO, /* 8 - start send off the request (part 1) */
  52. MSTATE_DOING, /* 9 - sending off the request (part 1) */
  53. MSTATE_DOING_MORE, /* 10 - send off the request (part 2) */
  54. MSTATE_DID, /* 11 - done sending off request */
  55. MSTATE_PERFORMING, /* 12 - transfer data */
  56. MSTATE_RATELIMITING, /* 13 - wait because limit-rate exceeded */
  57. MSTATE_DONE, /* 14 - post data transfer operation */
  58. MSTATE_COMPLETED, /* 15 - operation complete */
  59. MSTATE_MSGSENT, /* 16 - the operation complete message is sent */
  60. MSTATE_LAST /* 17 - not a true state, never use this */
  61. } CURLMstate;
  62. /* we support N sockets per easy handle. Set the corresponding bit to what
  63. action we should wait for */
  64. #define MAX_SOCKSPEREASYHANDLE 5
  65. #define GETSOCK_READABLE (0x00ff)
  66. #define GETSOCK_WRITABLE (0xff00)
  67. #define CURLPIPE_ANY (CURLPIPE_MULTIPLEX)
  68. #if !defined(CURL_DISABLE_SOCKETPAIR)
  69. #define ENABLE_WAKEUP
  70. #endif
  71. /* value for MAXIMUM CONCURRENT STREAMS upper limit */
  72. #define INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1)
  73. /* Curl_multi SSL backend-specific data; declared differently by each SSL
  74. backend */
  75. struct multi_ssl_backend_data;
  76. /* This is the struct known as CURLM on the outside */
  77. struct Curl_multi {
  78. /* First a simple identifier to easier detect if a user mix up
  79. this multi handle with an easy handle. Set this to CURL_MULTI_HANDLE. */
  80. unsigned int magic;
  81. /* We have a doubly-linked list with easy handles */
  82. struct Curl_easy *easyp;
  83. struct Curl_easy *easylp; /* last node */
  84. int num_easy; /* amount of entries in the linked list above. */
  85. int num_alive; /* amount of easy handles that are added but have not yet
  86. reached COMPLETE state */
  87. struct Curl_llist msglist; /* a list of messages from completed transfers */
  88. struct Curl_llist pending; /* Curl_easys that are in the
  89. MSTATE_PENDING state */
  90. struct Curl_llist msgsent; /* Curl_easys that are in the
  91. MSTATE_MSGSENT state */
  92. /* callback function and user data pointer for the *socket() API */
  93. curl_socket_callback socket_cb;
  94. void *socket_userp;
  95. /* callback function and user data pointer for server push */
  96. curl_push_callback push_cb;
  97. void *push_userp;
  98. /* Hostname cache */
  99. struct Curl_hash hostcache;
  100. #ifdef USE_LIBPSL
  101. /* PSL cache. */
  102. struct PslCache psl;
  103. #endif
  104. /* timetree points to the splay-tree of time nodes to figure out expire
  105. times of all currently set timers */
  106. struct Curl_tree *timetree;
  107. #if defined(USE_SSL)
  108. struct multi_ssl_backend_data *ssl_backend_data;
  109. #endif
  110. /* 'sockhash' is the lookup hash for socket descriptor => easy handles (note
  111. the pluralis form, there can be more than one easy handle waiting on the
  112. same actual socket) */
  113. struct Curl_hash sockhash;
  114. /* Shared connection cache (bundles)*/
  115. struct conncache conn_cache;
  116. long maxconnects; /* if >0, a fixed limit of the maximum number of entries
  117. we're allowed to grow the connection cache to */
  118. long max_host_connections; /* if >0, a fixed limit of the maximum number
  119. of connections per host */
  120. long max_total_connections; /* if >0, a fixed limit of the maximum number
  121. of connections in total */
  122. /* timer callback and user data pointer for the *socket() API */
  123. curl_multi_timer_callback timer_cb;
  124. void *timer_userp;
  125. struct curltime timer_lastcall; /* the fixed time for the timeout for the
  126. previous callback */
  127. unsigned int max_concurrent_streams;
  128. #ifdef USE_WINSOCK
  129. WSAEVENT wsa_event; /* winsock event used for waits */
  130. #else
  131. #ifdef ENABLE_WAKEUP
  132. curl_socket_t wakeup_pair[2]; /* socketpair() used for wakeup
  133. 0 is used for read, 1 is used for write */
  134. #endif
  135. #endif
  136. #define IPV6_UNKNOWN 0
  137. #define IPV6_DEAD 1
  138. #define IPV6_WORKS 2
  139. unsigned char ipv6_up; /* IPV6_* defined */
  140. BIT(multiplexing); /* multiplexing wanted */
  141. BIT(recheckstate); /* see Curl_multi_connchanged */
  142. BIT(in_callback); /* true while executing a callback */
  143. #ifdef USE_OPENSSL
  144. BIT(ssl_seeded);
  145. #endif
  146. BIT(dead); /* a callback returned error, everything needs to crash and
  147. burn */
  148. #ifdef DEBUGBUILD
  149. BIT(warned); /* true after user warned of DEBUGBUILD */
  150. #endif
  151. };
  152. #endif /* HEADER_CURL_MULTIHANDLE_H */