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