Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmcurl/lib/cf-socket.h
5016 views
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 "sockaddr.h" /* required for Curl_sockaddr_storage */
29
30
struct Curl_addrinfo;
31
struct Curl_cfilter;
32
struct Curl_easy;
33
struct connectdata;
34
struct Curl_sockaddr_ex;
35
struct ip_quadruple;
36
37
/*
38
* The Curl_sockaddr_ex structure is basically libcurl's external API
39
* curl_sockaddr structure with enough space available to directly hold any
40
* protocol-specific address structures. The variable declared here will be
41
* used to pass / receive data to/from the fopensocket callback if this has
42
* been set, before that, it is initialized from parameters.
43
*/
44
struct Curl_sockaddr_ex {
45
int family;
46
int socktype;
47
int protocol;
48
unsigned int addrlen;
49
union {
50
struct sockaddr sa;
51
struct Curl_sockaddr_storage buf;
52
} addr;
53
};
54
#define curl_sa_addr addr.sa
55
#define curl_sa_addrbuf addr.buf
56
57
/*
58
* Parse interface option, and return the interface name and the host part.
59
*/
60
CURLcode Curl_parse_interface(const char *input,
61
char **dev, char **iface, char **host);
62
63
/*
64
* Create a socket based on info from 'conn' and 'ai'.
65
*
66
* Fill in 'addr' and 'sockfd' accordingly if OK is returned. If the open
67
* socket callback is set, used that!
68
*
69
*/
70
CURLcode Curl_socket_open(struct Curl_easy *data,
71
const struct Curl_addrinfo *ai,
72
struct Curl_sockaddr_ex *addr,
73
uint8_t transport,
74
curl_socket_t *sockfd);
75
76
int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,
77
curl_socket_t sock);
78
79
#ifdef USE_WINSOCK
80
/* When you run a program that uses the Windows Sockets API, you may
81
experience slow performance when you copy data to a TCP server.
82
83
https://learn.microsoft.com/troubleshoot/windows-server/networking/slow-performance-copy-data-tcp-server-sockets-api
84
85
Work-around: Make the Socket Send Buffer Size Larger Than the Program Send
86
Buffer Size
87
88
*/
89
void Curl_sndbuf_init(curl_socket_t sockfd);
90
#else
91
#define Curl_sndbuf_init(y) Curl_nop_stmt
92
#endif
93
94
/**
95
* Creates a cfilter that opens a TCP socket to the given address
96
* when calling its `connect` implementation.
97
* The filter will not touch any connection/data flags and can be
98
* used in happy eyeballing. Once selected for use, its `_active()`
99
* method needs to be called.
100
*/
101
CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf,
102
struct Curl_easy *data,
103
struct connectdata *conn,
104
const struct Curl_addrinfo *ai,
105
uint8_t transport);
106
107
/**
108
* Creates a cfilter that opens a UDP socket to the given address
109
* when calling its `connect` implementation.
110
* The filter will not touch any connection/data flags and can be
111
* used in happy eyeballing. Once selected for use, its `_active()`
112
* method needs to be called.
113
*/
114
CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf,
115
struct Curl_easy *data,
116
struct connectdata *conn,
117
const struct Curl_addrinfo *ai,
118
uint8_t transport);
119
120
/**
121
* Creates a cfilter that opens a UNIX socket to the given address
122
* when calling its `connect` implementation.
123
* The filter will not touch any connection/data flags and can be
124
* used in happy eyeballing. Once selected for use, its `_active()`
125
* method needs to be called.
126
*/
127
CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf,
128
struct Curl_easy *data,
129
struct connectdata *conn,
130
const struct Curl_addrinfo *ai,
131
uint8_t transport);
132
133
/**
134
* Creates a cfilter that keeps a listening socket.
135
*/
136
CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data,
137
struct connectdata *conn,
138
int sockindex,
139
curl_socket_t *s);
140
141
/**
142
* Return TRUE iff the last filter at `sockindex` was set via
143
* Curl_conn_tcp_listen_set().
144
*/
145
bool Curl_conn_is_tcp_listen(struct Curl_easy *data,
146
int sockindex);
147
148
/**
149
* Peek at the socket and remote ip/port the socket filter is using.
150
* The filter owns all returned values.
151
* @param psock pointer to hold socket descriptor or NULL
152
* @param paddr pointer to hold addr reference or NULL
153
* @param pip pointer to get IP quadruple or NULL
154
* Returns error if the filter is of invalid type.
155
*/
156
CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
157
struct Curl_easy *data,
158
curl_socket_t *psock,
159
const struct Curl_sockaddr_ex **paddr,
160
struct ip_quadruple *pip) WARN_UNUSED_RESULT;
161
162
extern struct Curl_cftype Curl_cft_tcp;
163
extern struct Curl_cftype Curl_cft_udp;
164
extern struct Curl_cftype Curl_cft_unix;
165
extern struct Curl_cftype Curl_cft_tcp_accept;
166
167
#endif /* HEADER_CURL_CF_SOCKET_H */
168
169