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