#ifndef HEADER_CURL_CONNECT_H1#define HEADER_CURL_CONNECT_H2/***************************************************************************3* _ _ ____ _4* Project ___| | | | _ \| |5* / __| | | | |_) | |6* | (__| |_| | _ <| |___7* \___|\___/|_| \_\_____|8*9* Copyright (C) Daniel Stenberg, <[email protected]>, et al.10*11* This software is licensed as described in the file COPYING, which12* you should have received as part of this distribution. The terms13* are also available at https://curl.se/docs/copyright.html.14*15* You may opt to use, copy, modify, merge, publish, distribute and/or sell16* copies of the Software, and permit persons to whom the Software is17* furnished to do so, under the terms of the COPYING file.18*19* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20* KIND, either express or implied.21*22* SPDX-License-Identifier: curl23*24***************************************************************************/25#include "curl_setup.h"2627#include "curlx/nonblock.h" /* for curlx_nonblock() */28#include "sockaddr.h"29#include "curlx/timeval.h"3031struct Curl_dns_entry;32struct ip_quadruple;3334enum alpnid Curl_alpn2alpnid(const char *name, size_t len);3536/* generic function that returns how much time there is left to run, according37to the timeouts set */38timediff_t Curl_timeleft(struct Curl_easy *data,39struct curltime *nowp,40bool duringconnect);4142#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */4344#define DEFAULT_SHUTDOWN_TIMEOUT_MS (2 * 1000)4546void Curl_shutdown_start(struct Curl_easy *data, int sockindex,47int timeout_ms, struct curltime *nowp);4849/* return how much time there is left to shutdown the connection at50* sockindex. Returns 0 if there is no limit or shutdown has not started. */51timediff_t Curl_shutdown_timeleft(struct connectdata *conn, int sockindex,52struct curltime *nowp);5354/* return how much time there is left to shutdown the connection.55* Returns 0 if there is no limit or shutdown has not started. */56timediff_t Curl_conn_shutdown_timeleft(struct connectdata *conn,57struct curltime *nowp);5859void Curl_shutdown_clear(struct Curl_easy *data, int sockindex);6061/* TRUE iff shutdown has been started */62bool Curl_shutdown_started(struct Curl_easy *data, int sockindex);6364/*65* Used to extract socket and connectdata struct for the most recent66* transfer on the given Curl_easy.67*68* The returned socket will be CURL_SOCKET_BAD in case of failure!69*/70curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,71struct connectdata **connp);7273bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,74char *addr, int *port);7576/*77* Curl_conncontrol() marks the end of a connection/stream. The 'closeit'78* argument specifies if it is the end of a connection or a stream.79*80* For stream-based protocols (such as HTTP/2), a stream close will not cause81* a connection close. Other protocols will close the connection for both82* cases.83*84* It sets the bit.close bit to TRUE (with an explanation for debug builds),85* when the connection will close.86*/8788#define CONNCTRL_KEEP 0 /* undo a marked closure */89#define CONNCTRL_CONNECTION 190#define CONNCTRL_STREAM 29192void Curl_conncontrol(struct connectdata *conn,93int closeit94#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)95, const char *reason96#endif97);9899#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)100#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y)101#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)102#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y)103#else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */104#define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM)105#define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION)106#define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP)107#endif108109/**110* Create a cfilter for making an "ip" connection to the111* given address, using parameters from `conn`. The "ip" connection112* can be a TCP socket, a UDP socket or even a QUIC connection.113*114* It MUST use only the supplied `ai` for its connection attempt.115*116* Such a filter may be used in "happy eyeball" scenarios, and its117* `connect` implementation needs to support non-blocking. Once connected,118* it MAY be installed in the connection filter chain to serve transfers.119*/120typedef CURLcode cf_ip_connect_create(struct Curl_cfilter **pcf,121struct Curl_easy *data,122struct connectdata *conn,123const struct Curl_addrinfo *ai,124int transport);125126CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at,127struct Curl_easy *data,128int transport,129int ssl_mode);130131/**132* Setup the cfilters at `sockindex` in connection `conn`.133* If no filter chain is installed yet, inspects the configuration134* in `data` and `conn? to install a suitable filter chain.135*/136CURLcode Curl_conn_setup(struct Curl_easy *data,137struct connectdata *conn,138int sockindex,139struct Curl_dns_entry *dns,140int ssl_mode);141142extern struct Curl_cftype Curl_cft_happy_eyeballs;143extern struct Curl_cftype Curl_cft_setup;144145#ifdef UNITTESTS146void Curl_debug_set_transport_provider(int transport,147cf_ip_connect_create *cf_create);148#endif149150#endif /* HEADER_CURL_CONNECT_H */151152153