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