1 | #ifndef HEADER_CURL_CF_SOCKET_H
|
---|
2 | #define HEADER_CURL_CF_SOCKET_H
|
---|
3 | /***************************************************************************
|
---|
4 | * _ _ ____ _
|
---|
5 | * Project ___| | | | _ \| |
|
---|
6 | * / __| | | | |_) | |
|
---|
7 | * | (__| |_| | _ <| |___
|
---|
8 | * \___|\___/|_| \_\_____|
|
---|
9 | *
|
---|
10 | * Copyright (C) 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 | * SPDX-License-Identifier: curl
|
---|
24 | *
|
---|
25 | ***************************************************************************/
|
---|
26 | #include "curl_setup.h"
|
---|
27 |
|
---|
28 | #include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
|
---|
29 | #include "sockaddr.h"
|
---|
30 |
|
---|
31 | struct Curl_addrinfo;
|
---|
32 | struct Curl_cfilter;
|
---|
33 | struct Curl_easy;
|
---|
34 | struct connectdata;
|
---|
35 | struct Curl_sockaddr_ex;
|
---|
36 |
|
---|
37 | #ifndef SIZEOF_CURL_SOCKET_T
|
---|
38 | /* configure and cmake check and set the define */
|
---|
39 | # ifdef _WIN64
|
---|
40 | # define SIZEOF_CURL_SOCKET_T 8
|
---|
41 | # else
|
---|
42 | /* default guess */
|
---|
43 | # define SIZEOF_CURL_SOCKET_T 4
|
---|
44 | # endif
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #if SIZEOF_CURL_SOCKET_T < 8
|
---|
48 | # define CURL_FORMAT_SOCKET_T "d"
|
---|
49 | #else
|
---|
50 | # define CURL_FORMAT_SOCKET_T "qd"
|
---|
51 | #endif
|
---|
52 |
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * The Curl_sockaddr_ex structure is basically libcurl's external API
|
---|
56 | * curl_sockaddr structure with enough space available to directly hold any
|
---|
57 | * protocol-specific address structures. The variable declared here will be
|
---|
58 | * used to pass / receive data to/from the fopensocket callback if this has
|
---|
59 | * been set, before that, it is initialized from parameters.
|
---|
60 | */
|
---|
61 | struct Curl_sockaddr_ex {
|
---|
62 | int family;
|
---|
63 | int socktype;
|
---|
64 | int protocol;
|
---|
65 | unsigned int addrlen;
|
---|
66 | union {
|
---|
67 | struct sockaddr addr;
|
---|
68 | struct Curl_sockaddr_storage buff;
|
---|
69 | } _sa_ex_u;
|
---|
70 | };
|
---|
71 | #define sa_addr _sa_ex_u.addr
|
---|
72 |
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * Create a socket based on info from 'conn' and 'ai'.
|
---|
76 | *
|
---|
77 | * Fill in 'addr' and 'sockfd' accordingly if OK is returned. If the open
|
---|
78 | * socket callback is set, used that!
|
---|
79 | *
|
---|
80 | */
|
---|
81 | CURLcode Curl_socket_open(struct Curl_easy *data,
|
---|
82 | const struct Curl_addrinfo *ai,
|
---|
83 | struct Curl_sockaddr_ex *addr,
|
---|
84 | int transport,
|
---|
85 | curl_socket_t *sockfd);
|
---|
86 |
|
---|
87 | int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,
|
---|
88 | curl_socket_t sock);
|
---|
89 |
|
---|
90 | #ifdef USE_WINSOCK
|
---|
91 | /* When you run a program that uses the Windows Sockets API, you may
|
---|
92 | experience slow performance when you copy data to a TCP server.
|
---|
93 |
|
---|
94 | https://support.microsoft.com/kb/823764
|
---|
95 |
|
---|
96 | Work-around: Make the Socket Send Buffer Size Larger Than the Program Send
|
---|
97 | Buffer Size
|
---|
98 |
|
---|
99 | */
|
---|
100 | void Curl_sndbufset(curl_socket_t sockfd);
|
---|
101 | #else
|
---|
102 | #define Curl_sndbufset(y) Curl_nop_stmt
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Assign the address `ai` to the Curl_sockaddr_ex `dest` and
|
---|
107 | * set the transport used.
|
---|
108 | */
|
---|
109 | void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
|
---|
110 | const struct Curl_addrinfo *ai,
|
---|
111 | int transport);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Creates a cfilter that opens a TCP socket to the given address
|
---|
115 | * when calling its `connect` implementation.
|
---|
116 | * The filter will not touch any connection/data flags and can be
|
---|
117 | * used in happy eyeballing. Once selected for use, its `_active()`
|
---|
118 | * method needs to be called.
|
---|
119 | */
|
---|
120 | CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf,
|
---|
121 | struct Curl_easy *data,
|
---|
122 | struct connectdata *conn,
|
---|
123 | const struct Curl_addrinfo *ai,
|
---|
124 | int transport);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Creates a cfilter that opens a UDP socket to the given address
|
---|
128 | * when calling its `connect` implementation.
|
---|
129 | * The filter will not touch any connection/data flags and can be
|
---|
130 | * used in happy eyeballing. Once selected for use, its `_active()`
|
---|
131 | * method needs to be called.
|
---|
132 | */
|
---|
133 | CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf,
|
---|
134 | struct Curl_easy *data,
|
---|
135 | struct connectdata *conn,
|
---|
136 | const struct Curl_addrinfo *ai,
|
---|
137 | int transport);
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Creates a cfilter that opens a UNIX socket to the given address
|
---|
141 | * when calling its `connect` implementation.
|
---|
142 | * The filter will not touch any connection/data flags and can be
|
---|
143 | * used in happy eyeballing. Once selected for use, its `_active()`
|
---|
144 | * method needs to be called.
|
---|
145 | */
|
---|
146 | CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf,
|
---|
147 | struct Curl_easy *data,
|
---|
148 | struct connectdata *conn,
|
---|
149 | const struct Curl_addrinfo *ai,
|
---|
150 | int transport);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Creates a cfilter that keeps a listening socket.
|
---|
154 | */
|
---|
155 | CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data,
|
---|
156 | struct connectdata *conn,
|
---|
157 | int sockindex,
|
---|
158 | curl_socket_t *s);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Replace the listen socket with the accept()ed one.
|
---|
162 | */
|
---|
163 | CURLcode Curl_conn_tcp_accepted_set(struct Curl_easy *data,
|
---|
164 | struct connectdata *conn,
|
---|
165 | int sockindex,
|
---|
166 | curl_socket_t *s);
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Peek at the socket and remote ip/port the socket filter is using.
|
---|
170 | * The filter owns all returned values.
|
---|
171 | * @param psock pointer to hold socket descriptor or NULL
|
---|
172 | * @param paddr pointer to hold addr reference or NULL
|
---|
173 | * @param pr_ip_str pointer to hold remote addr as string or NULL
|
---|
174 | * @param pr_port pointer to hold remote port number or NULL
|
---|
175 | * @param pl_ip_str pointer to hold local addr as string or NULL
|
---|
176 | * @param pl_port pointer to hold local port number or NULL
|
---|
177 | * Returns error if the filter is of invalid type.
|
---|
178 | */
|
---|
179 | CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
|
---|
180 | struct Curl_easy *data,
|
---|
181 | curl_socket_t *psock,
|
---|
182 | const struct Curl_sockaddr_ex **paddr,
|
---|
183 | const char **pr_ip_str, int *pr_port,
|
---|
184 | const char **pl_ip_str, int *pl_port);
|
---|
185 |
|
---|
186 | extern struct Curl_cftype Curl_cft_tcp;
|
---|
187 | extern struct Curl_cftype Curl_cft_udp;
|
---|
188 | extern struct Curl_cftype Curl_cft_unix;
|
---|
189 | extern struct Curl_cftype Curl_cft_tcp_accept;
|
---|
190 |
|
---|
191 | #endif /* HEADER_CURL_CF_SOCKET_H */
|
---|