#ifndef HEADER_CURL_CF_SOCKET_H1#define HEADER_CURL_CF_SOCKET_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/nonblock.h" /* for curlx_nonblock() */28#include "sockaddr.h"2930struct Curl_addrinfo;31struct Curl_cfilter;32struct Curl_easy;33struct connectdata;34struct Curl_sockaddr_ex;35struct ip_quadruple;3637/*38* The Curl_sockaddr_ex structure is basically libcurl's external API39* curl_sockaddr structure with enough space available to directly hold any40* protocol-specific address structures. The variable declared here will be41* used to pass / receive data to/from the fopensocket callback if this has42* been set, before that, it is initialized from parameters.43*/44struct Curl_sockaddr_ex {45int family;46int socktype;47int protocol;48unsigned int addrlen;49union {50struct sockaddr sa;51struct Curl_sockaddr_storage buf;52} addr;53};54#define curl_sa_addr addr.sa55#define curl_sa_addrbuf addr.buf5657/*58* Parse interface option, and return the interface name and the host part.59*/60CURLcode Curl_parse_interface(const char *input,61char **dev, char **iface, char **host);6263/*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 open67* socket callback is set, used that!68*69*/70CURLcode Curl_socket_open(struct Curl_easy *data,71const struct Curl_addrinfo *ai,72struct Curl_sockaddr_ex *addr,73int transport,74curl_socket_t *sockfd);7576int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,77curl_socket_t sock);7879#ifdef USE_WINSOCK80/* When you run a program that uses the Windows Sockets API, you may81experience slow performance when you copy data to a TCP server.8283https://learn.microsoft.com/troubleshoot/windows-server/networking/slow-performance-copy-data-tcp-server-sockets-api8485Work-around: Make the Socket Send Buffer Size Larger Than the Program Send86Buffer Size8788*/89void Curl_sndbuf_init(curl_socket_t sockfd);90#else91#define Curl_sndbuf_init(y) Curl_nop_stmt92#endif9394/**95* Creates a cfilter that opens a TCP socket to the given address96* when calling its `connect` implementation.97* The filter will not touch any connection/data flags and can be98* used in happy eyeballing. Once selected for use, its `_active()`99* method needs to be called.100*/101CURLcode Curl_cf_tcp_create(struct Curl_cfilter **pcf,102struct Curl_easy *data,103struct connectdata *conn,104const struct Curl_addrinfo *ai,105int transport);106107/**108* Creates a cfilter that opens a UDP socket to the given address109* when calling its `connect` implementation.110* The filter will not touch any connection/data flags and can be111* used in happy eyeballing. Once selected for use, its `_active()`112* method needs to be called.113*/114CURLcode Curl_cf_udp_create(struct Curl_cfilter **pcf,115struct Curl_easy *data,116struct connectdata *conn,117const struct Curl_addrinfo *ai,118int transport);119120/**121* Creates a cfilter that opens a UNIX socket to the given address122* when calling its `connect` implementation.123* The filter will not touch any connection/data flags and can be124* used in happy eyeballing. Once selected for use, its `_active()`125* method needs to be called.126*/127CURLcode Curl_cf_unix_create(struct Curl_cfilter **pcf,128struct Curl_easy *data,129struct connectdata *conn,130const struct Curl_addrinfo *ai,131int transport);132133/**134* Creates a cfilter that keeps a listening socket.135*/136CURLcode Curl_conn_tcp_listen_set(struct Curl_easy *data,137struct connectdata *conn,138int sockindex,139curl_socket_t *s);140141/**142* Return TRUE iff the last filter at `sockindex` was set via143* Curl_conn_tcp_listen_set().144*/145bool Curl_conn_is_tcp_listen(struct Curl_easy *data,146int sockindex);147148/**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 NULL152* @param paddr pointer to hold addr reference or NULL153* @param pip pointer to get IP quadruple or NULL154* Returns error if the filter is of invalid type.155*/156CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,157struct Curl_easy *data,158curl_socket_t *psock,159const struct Curl_sockaddr_ex **paddr,160struct ip_quadruple *pip) WARN_UNUSED_RESULT;161162extern struct Curl_cftype Curl_cft_tcp;163extern struct Curl_cftype Curl_cft_udp;164extern struct Curl_cftype Curl_cft_unix;165extern struct Curl_cftype Curl_cft_tcp_accept;166167#endif /* HEADER_CURL_CF_SOCKET_H */168169170