1 | #ifndef HEADER_CURL_CONNECT_H
|
---|
2 | #define HEADER_CURL_CONNECT_H
|
---|
3 | /***************************************************************************
|
---|
4 | * _ _ ____ _
|
---|
5 | * Project ___| | | | _ \| |
|
---|
6 | * / __| | | | |_) | |
|
---|
7 | * | (__| |_| | _ <| |___
|
---|
8 | * \___|\___/|_| \_\_____|
|
---|
9 | *
|
---|
10 | * Copyright (C) 1998 - 2021, Daniel Stenberg, <[email protected]>, 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 | #include "curl_setup.h"
|
---|
25 |
|
---|
26 | #include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
|
---|
27 | #include "sockaddr.h"
|
---|
28 | #include "timeval.h"
|
---|
29 |
|
---|
30 | CURLcode Curl_is_connected(struct Curl_easy *data,
|
---|
31 | struct connectdata *conn,
|
---|
32 | int sockindex,
|
---|
33 | bool *connected);
|
---|
34 |
|
---|
35 | CURLcode Curl_connecthost(struct Curl_easy *data,
|
---|
36 | struct connectdata *conn,
|
---|
37 | const struct Curl_dns_entry *host);
|
---|
38 |
|
---|
39 | /* generic function that returns how much time there's left to run, according
|
---|
40 | to the timeouts set */
|
---|
41 | timediff_t Curl_timeleft(struct Curl_easy *data,
|
---|
42 | struct curltime *nowp,
|
---|
43 | bool duringconnect);
|
---|
44 |
|
---|
45 | #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * Used to extract socket and connectdata struct for the most recent
|
---|
49 | * transfer on the given Curl_easy.
|
---|
50 | *
|
---|
51 | * The returned socket will be CURL_SOCKET_BAD in case of failure!
|
---|
52 | */
|
---|
53 | curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
|
---|
54 | struct connectdata **connp);
|
---|
55 |
|
---|
56 | bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
|
---|
57 | char *addr, int *port);
|
---|
58 |
|
---|
59 | /*
|
---|
60 | * Check if a connection seems to be alive.
|
---|
61 | */
|
---|
62 | bool Curl_connalive(struct connectdata *conn);
|
---|
63 |
|
---|
64 | #ifdef USE_WINSOCK
|
---|
65 | /* When you run a program that uses the Windows Sockets API, you may
|
---|
66 | experience slow performance when you copy data to a TCP server.
|
---|
67 |
|
---|
68 | https://support.microsoft.com/kb/823764
|
---|
69 |
|
---|
70 | Work-around: Make the Socket Send Buffer Size Larger Than the Program Send
|
---|
71 | Buffer Size
|
---|
72 |
|
---|
73 | */
|
---|
74 | void Curl_sndbufset(curl_socket_t sockfd);
|
---|
75 | #else
|
---|
76 | #define Curl_sndbufset(y) Curl_nop_stmt
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | void Curl_updateconninfo(struct Curl_easy *data, struct connectdata *conn,
|
---|
80 | curl_socket_t sockfd);
|
---|
81 | void Curl_conninfo_remote(struct Curl_easy *data, struct connectdata *conn,
|
---|
82 | curl_socket_t sockfd);
|
---|
83 | void Curl_conninfo_local(struct Curl_easy *data, curl_socket_t sockfd,
|
---|
84 | char *local_ip, int *local_port);
|
---|
85 | void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn,
|
---|
86 | char *local_ip, int local_port);
|
---|
87 | int Curl_closesocket(struct Curl_easy *data, struct connectdata *conn,
|
---|
88 | curl_socket_t sock);
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * The Curl_sockaddr_ex structure is basically libcurl's external API
|
---|
92 | * curl_sockaddr structure with enough space available to directly hold any
|
---|
93 | * protocol-specific address structures. The variable declared here will be
|
---|
94 | * used to pass / receive data to/from the fopensocket callback if this has
|
---|
95 | * been set, before that, it is initialized from parameters.
|
---|
96 | */
|
---|
97 | struct Curl_sockaddr_ex {
|
---|
98 | int family;
|
---|
99 | int socktype;
|
---|
100 | int protocol;
|
---|
101 | unsigned int addrlen;
|
---|
102 | union {
|
---|
103 | struct sockaddr addr;
|
---|
104 | struct Curl_sockaddr_storage buff;
|
---|
105 | } _sa_ex_u;
|
---|
106 | };
|
---|
107 | #define sa_addr _sa_ex_u.addr
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Create a socket based on info from 'conn' and 'ai'.
|
---|
111 | *
|
---|
112 | * Fill in 'addr' and 'sockfd' accordingly if OK is returned. If the open
|
---|
113 | * socket callback is set, used that!
|
---|
114 | *
|
---|
115 | */
|
---|
116 | CURLcode Curl_socket(struct Curl_easy *data,
|
---|
117 | const struct Curl_addrinfo *ai,
|
---|
118 | struct Curl_sockaddr_ex *addr,
|
---|
119 | curl_socket_t *sockfd);
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * Curl_conncontrol() marks the end of a connection/stream. The 'closeit'
|
---|
123 | * argument specifies if it is the end of a connection or a stream.
|
---|
124 | *
|
---|
125 | * For stream-based protocols (such as HTTP/2), a stream close will not cause
|
---|
126 | * a connection close. Other protocols will close the connection for both
|
---|
127 | * cases.
|
---|
128 | *
|
---|
129 | * It sets the bit.close bit to TRUE (with an explanation for debug builds),
|
---|
130 | * when the connection will close.
|
---|
131 | */
|
---|
132 |
|
---|
133 | #define CONNCTRL_KEEP 0 /* undo a marked closure */
|
---|
134 | #define CONNCTRL_CONNECTION 1
|
---|
135 | #define CONNCTRL_STREAM 2
|
---|
136 |
|
---|
137 | void Curl_conncontrol(struct connectdata *conn,
|
---|
138 | int closeit
|
---|
139 | #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
---|
140 | , const char *reason
|
---|
141 | #endif
|
---|
142 | );
|
---|
143 |
|
---|
144 | #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
---|
145 | #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y)
|
---|
146 | #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)
|
---|
147 | #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y)
|
---|
148 | #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */
|
---|
149 | #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM)
|
---|
150 | #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION)
|
---|
151 | #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP)
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | bool Curl_conn_data_pending(struct connectdata *conn, int sockindex);
|
---|
155 |
|
---|
156 | #endif /* HEADER_CURL_CONNECT_H */
|
---|