#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/timeval.h"2829struct Curl_dns_entry;30struct ip_quadruple;31struct Curl_str;3233enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len);34enum alpnid Curl_str2alpnid(const struct Curl_str *str);3536/* generic function that returns how much time there is left to run, according37to the timeouts set */38timediff_t Curl_timeleft_ms(struct Curl_easy *data,39bool duringconnect);40timediff_t Curl_timeleft_now_ms(struct Curl_easy *data,41const struct curltime *pnow,42bool duringconnect);4344#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */4546#define DEFAULT_SHUTDOWN_TIMEOUT_MS (2 * 1000)4748void Curl_shutdown_start(struct Curl_easy *data, int sockindex,49int timeout_ms);5051/* return how much time there is left to shutdown the connection at52* sockindex. Returns 0 if there is no limit or shutdown has not started. */53timediff_t Curl_shutdown_timeleft(struct Curl_easy *data,54struct connectdata *conn,55int sockindex);5657/* return how much time there is left to shutdown the connection.58* Returns 0 if there is no limit or shutdown has not started. */59timediff_t Curl_conn_shutdown_timeleft(struct Curl_easy *data,60struct connectdata *conn);6162void Curl_shutdown_clear(struct Curl_easy *data, int sockindex);6364/* TRUE iff shutdown has been started */65bool Curl_shutdown_started(struct Curl_easy *data, int sockindex);6667/*68* Used to extract socket and connectdata struct for the most recent69* transfer on the given Curl_easy.70*71* The returned socket will be CURL_SOCKET_BAD in case of failure!72*/73curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,74struct connectdata **connp);7576bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,77char *addr, uint16_t *port);7879/*80* Curl_conncontrol() marks the end of a connection/stream. The 'closeit'81* argument specifies if it is the end of a connection or a stream.82*83* For stream-based protocols (such as HTTP/2), a stream close will not cause84* a connection close. Other protocols will close the connection for both85* cases.86*87* It sets the bit.close bit to TRUE (with an explanation for debug builds),88* when the connection will close.89*/9091#define CONNCTRL_KEEP 0 /* undo a marked closure */92#define CONNCTRL_CONNECTION 193#define CONNCTRL_STREAM 29495void Curl_conncontrol(struct connectdata *conn,96int closeit97#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)98, const char *reason99#endif100);101102#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)103#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM, y)104#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)105#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP, y)106#else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */107#define streamclose(x, y) Curl_conncontrol(x, CONNCTRL_STREAM)108#define connclose(x, y) Curl_conncontrol(x, CONNCTRL_CONNECTION)109#define connkeep(x, y) Curl_conncontrol(x, CONNCTRL_KEEP)110#endif111112CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at,113struct Curl_easy *data,114uint8_t transport,115int ssl_mode);116117/**118* Setup the cfilters at `sockindex` in connection `conn`.119* If no filter chain is installed yet, inspects the configuration120* in `data` and `conn? to install a suitable filter chain.121*/122CURLcode Curl_conn_setup(struct Curl_easy *data,123struct connectdata *conn,124int sockindex,125struct Curl_dns_entry *dns,126int ssl_mode);127128/* Set conn to allow multiplexing. */129void Curl_conn_set_multiplex(struct connectdata *conn);130131extern struct Curl_cftype Curl_cft_setup;132133#endif /* HEADER_CURL_CONNECT_H */134135136