113498266Sopenharmony_ci#ifndef HEADER_CURL_MULTIHANDLE_H 213498266Sopenharmony_ci#define HEADER_CURL_MULTIHANDLE_H 313498266Sopenharmony_ci/*************************************************************************** 413498266Sopenharmony_ci * _ _ ____ _ 513498266Sopenharmony_ci * Project ___| | | | _ \| | 613498266Sopenharmony_ci * / __| | | | |_) | | 713498266Sopenharmony_ci * | (__| |_| | _ <| |___ 813498266Sopenharmony_ci * \___|\___/|_| \_\_____| 913498266Sopenharmony_ci * 1013498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 1113498266Sopenharmony_ci * 1213498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which 1313498266Sopenharmony_ci * you should have received as part of this distribution. The terms 1413498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html. 1513498266Sopenharmony_ci * 1613498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell 1713498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is 1813498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file. 1913498266Sopenharmony_ci * 2013498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 2113498266Sopenharmony_ci * KIND, either express or implied. 2213498266Sopenharmony_ci * 2313498266Sopenharmony_ci * SPDX-License-Identifier: curl 2413498266Sopenharmony_ci * 2513498266Sopenharmony_ci ***************************************************************************/ 2613498266Sopenharmony_ci 2713498266Sopenharmony_ci#include "llist.h" 2813498266Sopenharmony_ci#include "hash.h" 2913498266Sopenharmony_ci#include "conncache.h" 3013498266Sopenharmony_ci#include "psl.h" 3113498266Sopenharmony_ci#include "socketpair.h" 3213498266Sopenharmony_ci 3313498266Sopenharmony_cistruct connectdata; 3413498266Sopenharmony_ci 3513498266Sopenharmony_cistruct Curl_message { 3613498266Sopenharmony_ci struct Curl_llist_element list; 3713498266Sopenharmony_ci /* the 'CURLMsg' is the part that is visible to the external user */ 3813498266Sopenharmony_ci struct CURLMsg extmsg; 3913498266Sopenharmony_ci}; 4013498266Sopenharmony_ci 4113498266Sopenharmony_ci/* NOTE: if you add a state here, add the name to the statename[] array as 4213498266Sopenharmony_ci well! 4313498266Sopenharmony_ci*/ 4413498266Sopenharmony_citypedef enum { 4513498266Sopenharmony_ci MSTATE_INIT, /* 0 - start in this state */ 4613498266Sopenharmony_ci MSTATE_PENDING, /* 1 - no connections, waiting for one */ 4713498266Sopenharmony_ci MSTATE_CONNECT, /* 2 - resolve/connect has been sent off */ 4813498266Sopenharmony_ci MSTATE_RESOLVING, /* 3 - awaiting the resolve to finalize */ 4913498266Sopenharmony_ci MSTATE_CONNECTING, /* 4 - awaiting the TCP connect to finalize */ 5013498266Sopenharmony_ci MSTATE_TUNNELING, /* 5 - awaiting HTTPS proxy SSL initialization to 5113498266Sopenharmony_ci complete and/or proxy CONNECT to finalize */ 5213498266Sopenharmony_ci MSTATE_PROTOCONNECT, /* 6 - initiate protocol connect procedure */ 5313498266Sopenharmony_ci MSTATE_PROTOCONNECTING, /* 7 - completing the protocol-specific connect 5413498266Sopenharmony_ci phase */ 5513498266Sopenharmony_ci MSTATE_DO, /* 8 - start send off the request (part 1) */ 5613498266Sopenharmony_ci MSTATE_DOING, /* 9 - sending off the request (part 1) */ 5713498266Sopenharmony_ci MSTATE_DOING_MORE, /* 10 - send off the request (part 2) */ 5813498266Sopenharmony_ci MSTATE_DID, /* 11 - done sending off request */ 5913498266Sopenharmony_ci MSTATE_PERFORMING, /* 12 - transfer data */ 6013498266Sopenharmony_ci MSTATE_RATELIMITING, /* 13 - wait because limit-rate exceeded */ 6113498266Sopenharmony_ci MSTATE_DONE, /* 14 - post data transfer operation */ 6213498266Sopenharmony_ci MSTATE_COMPLETED, /* 15 - operation complete */ 6313498266Sopenharmony_ci MSTATE_MSGSENT, /* 16 - the operation complete message is sent */ 6413498266Sopenharmony_ci MSTATE_LAST /* 17 - not a true state, never use this */ 6513498266Sopenharmony_ci} CURLMstate; 6613498266Sopenharmony_ci 6713498266Sopenharmony_ci/* we support N sockets per easy handle. Set the corresponding bit to what 6813498266Sopenharmony_ci action we should wait for */ 6913498266Sopenharmony_ci#define MAX_SOCKSPEREASYHANDLE 5 7013498266Sopenharmony_ci#define GETSOCK_READABLE (0x00ff) 7113498266Sopenharmony_ci#define GETSOCK_WRITABLE (0xff00) 7213498266Sopenharmony_ci 7313498266Sopenharmony_ci#define CURLPIPE_ANY (CURLPIPE_MULTIPLEX) 7413498266Sopenharmony_ci 7513498266Sopenharmony_ci#if !defined(CURL_DISABLE_SOCKETPAIR) 7613498266Sopenharmony_ci#define ENABLE_WAKEUP 7713498266Sopenharmony_ci#endif 7813498266Sopenharmony_ci 7913498266Sopenharmony_ci/* value for MAXIMUM CONCURRENT STREAMS upper limit */ 8013498266Sopenharmony_ci#define INITIAL_MAX_CONCURRENT_STREAMS ((1U << 31) - 1) 8113498266Sopenharmony_ci 8213498266Sopenharmony_ci/* Curl_multi SSL backend-specific data; declared differently by each SSL 8313498266Sopenharmony_ci backend */ 8413498266Sopenharmony_cistruct multi_ssl_backend_data; 8513498266Sopenharmony_ci 8613498266Sopenharmony_ci/* This is the struct known as CURLM on the outside */ 8713498266Sopenharmony_cistruct Curl_multi { 8813498266Sopenharmony_ci /* First a simple identifier to easier detect if a user mix up 8913498266Sopenharmony_ci this multi handle with an easy handle. Set this to CURL_MULTI_HANDLE. */ 9013498266Sopenharmony_ci unsigned int magic; 9113498266Sopenharmony_ci 9213498266Sopenharmony_ci /* We have a doubly-linked list with easy handles */ 9313498266Sopenharmony_ci struct Curl_easy *easyp; 9413498266Sopenharmony_ci struct Curl_easy *easylp; /* last node */ 9513498266Sopenharmony_ci 9613498266Sopenharmony_ci unsigned int num_easy; /* amount of entries in the linked list above. */ 9713498266Sopenharmony_ci unsigned int num_alive; /* amount of easy handles that are added but have 9813498266Sopenharmony_ci not yet reached COMPLETE state */ 9913498266Sopenharmony_ci 10013498266Sopenharmony_ci struct Curl_llist msglist; /* a list of messages from completed transfers */ 10113498266Sopenharmony_ci 10213498266Sopenharmony_ci struct Curl_llist pending; /* Curl_easys that are in the 10313498266Sopenharmony_ci MSTATE_PENDING state */ 10413498266Sopenharmony_ci struct Curl_llist msgsent; /* Curl_easys that are in the 10513498266Sopenharmony_ci MSTATE_MSGSENT state */ 10613498266Sopenharmony_ci 10713498266Sopenharmony_ci /* callback function and user data pointer for the *socket() API */ 10813498266Sopenharmony_ci curl_socket_callback socket_cb; 10913498266Sopenharmony_ci void *socket_userp; 11013498266Sopenharmony_ci 11113498266Sopenharmony_ci /* callback function and user data pointer for server push */ 11213498266Sopenharmony_ci curl_push_callback push_cb; 11313498266Sopenharmony_ci void *push_userp; 11413498266Sopenharmony_ci 11513498266Sopenharmony_ci /* Hostname cache */ 11613498266Sopenharmony_ci struct Curl_hash hostcache; 11713498266Sopenharmony_ci 11813498266Sopenharmony_ci#ifdef USE_LIBPSL 11913498266Sopenharmony_ci /* PSL cache. */ 12013498266Sopenharmony_ci struct PslCache psl; 12113498266Sopenharmony_ci#endif 12213498266Sopenharmony_ci 12313498266Sopenharmony_ci /* timetree points to the splay-tree of time nodes to figure out expire 12413498266Sopenharmony_ci times of all currently set timers */ 12513498266Sopenharmony_ci struct Curl_tree *timetree; 12613498266Sopenharmony_ci 12713498266Sopenharmony_ci#if defined(USE_SSL) 12813498266Sopenharmony_ci struct multi_ssl_backend_data *ssl_backend_data; 12913498266Sopenharmony_ci#endif 13013498266Sopenharmony_ci 13113498266Sopenharmony_ci /* 'sockhash' is the lookup hash for socket descriptor => easy handles (note 13213498266Sopenharmony_ci the pluralis form, there can be more than one easy handle waiting on the 13313498266Sopenharmony_ci same actual socket) */ 13413498266Sopenharmony_ci struct Curl_hash sockhash; 13513498266Sopenharmony_ci 13613498266Sopenharmony_ci /* Shared connection cache (bundles)*/ 13713498266Sopenharmony_ci struct conncache conn_cache; 13813498266Sopenharmony_ci 13913498266Sopenharmony_ci long max_host_connections; /* if >0, a fixed limit of the maximum number 14013498266Sopenharmony_ci of connections per host */ 14113498266Sopenharmony_ci 14213498266Sopenharmony_ci long max_total_connections; /* if >0, a fixed limit of the maximum number 14313498266Sopenharmony_ci of connections in total */ 14413498266Sopenharmony_ci 14513498266Sopenharmony_ci /* timer callback and user data pointer for the *socket() API */ 14613498266Sopenharmony_ci curl_multi_timer_callback timer_cb; 14713498266Sopenharmony_ci void *timer_userp; 14813498266Sopenharmony_ci struct curltime timer_lastcall; /* the fixed time for the timeout for the 14913498266Sopenharmony_ci previous callback */ 15013498266Sopenharmony_ci#ifdef USE_WINSOCK 15113498266Sopenharmony_ci WSAEVENT wsa_event; /* winsock event used for waits */ 15213498266Sopenharmony_ci#else 15313498266Sopenharmony_ci#ifdef ENABLE_WAKEUP 15413498266Sopenharmony_ci curl_socket_t wakeup_pair[2]; /* socketpair() used for wakeup 15513498266Sopenharmony_ci 0 is used for read, 1 is used for write */ 15613498266Sopenharmony_ci#endif 15713498266Sopenharmony_ci#endif 15813498266Sopenharmony_ci unsigned int max_concurrent_streams; 15913498266Sopenharmony_ci unsigned int maxconnects; /* if >0, a fixed limit of the maximum number of 16013498266Sopenharmony_ci entries we're allowed to grow the connection 16113498266Sopenharmony_ci cache to */ 16213498266Sopenharmony_ci#define IPV6_UNKNOWN 0 16313498266Sopenharmony_ci#define IPV6_DEAD 1 16413498266Sopenharmony_ci#define IPV6_WORKS 2 16513498266Sopenharmony_ci unsigned char ipv6_up; /* IPV6_* defined */ 16613498266Sopenharmony_ci BIT(multiplexing); /* multiplexing wanted */ 16713498266Sopenharmony_ci BIT(recheckstate); /* see Curl_multi_connchanged */ 16813498266Sopenharmony_ci BIT(in_callback); /* true while executing a callback */ 16913498266Sopenharmony_ci#ifdef USE_OPENSSL 17013498266Sopenharmony_ci BIT(ssl_seeded); 17113498266Sopenharmony_ci#endif 17213498266Sopenharmony_ci BIT(dead); /* a callback returned error, everything needs to crash and 17313498266Sopenharmony_ci burn */ 17413498266Sopenharmony_ci#ifdef DEBUGBUILD 17513498266Sopenharmony_ci BIT(warned); /* true after user warned of DEBUGBUILD */ 17613498266Sopenharmony_ci#endif 17713498266Sopenharmony_ci}; 17813498266Sopenharmony_ci 17913498266Sopenharmony_ci#endif /* HEADER_CURL_MULTIHANDLE_H */ 180