20#include <idfxx/net/endpoint>
21#include <idfxx/net/error>
22#include <idfxx/net/resolver>
71 bool non_blocking =
false;
73 std::optional<std::chrono::milliseconds> recv_timeout = std::nullopt;
76 std::optional<std::chrono::milliseconds> send_timeout = std::nullopt;
79 bool reuse_address =
false;
82 bool no_delay =
false;
85 bool keep_alive =
false;
88 std::optional<std::chrono::seconds> keep_idle = std::nullopt;
91 std::optional<std::chrono::seconds> keep_interval = std::nullopt;
94 std::optional<uint32_t> keep_count = std::nullopt;
95#ifdef CONFIG_LWIP_IPV6
102 std::optional<std::string_view> bind_to_device = std::nullopt;
107#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
162#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
216#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
257 std::string_view host,
298#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
320 template<
typename Rep,
typename Period>
345 template<
typename Rep,
typename Period>
347 std::string_view host,
349 const std::chrono::duration<Rep, Period>& timeout,
370 template<
typename Rep,
typename Period>
372 connect_to_for(std::string_view host, port_number port,
const std::chrono::duration<Rep, Period>& timeout);
391 template<
typename Rep,
typename Period>
393 std::string_view host,
395 const std::chrono::duration<Rep, Period>& timeout,
399 return _connect_to_for(host, port, std::chrono::ceil<std::chrono::milliseconds>(timeout),
cfg,
opts);
404#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
415 template<
typename Rep,
typename Period>
432 template<
typename Rep,
typename Period>
435 return _try_connect_for(peer, std::chrono::ceil<std::chrono::milliseconds>(
timeout));
440#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
465#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
487#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
507#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
529#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
552#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
569#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
625 template<
typename Rep,
typename Period>
627 _set_keep_idle(std::chrono::ceil<std::chrono::seconds>(
t));
636 template<
typename Rep,
typename Period>
638 _set_keep_interval(std::chrono::ceil<std::chrono::seconds>(
t));
667 : ip_io_socket_base(
fd,
fam) {}
671 _make_and_connect_for(
const endpoint&
ep,
const config&
cfg, std::chrono::milliseconds timeout);
673 std::string_view host,
675 std::chrono::milliseconds timeout,
679 void _set_keep_idle(std::chrono::seconds
s)
noexcept;
680 void _set_keep_interval(std::chrono::seconds
s)
noexcept;
689template<
typename Rep,
typename Period>
691 std::string_view host,
693 const std::chrono::duration<Rep, Period>&
timeout
698#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
699template<
typename Rep,
typename Period>
Address/port pair identifying a transport endpoint.
result< void > try_shutdown(direction dir)
Shuts down one direction on the socket (half-close).
result< void > try_send_all(std::string_view buf)
Sends a string view in full, retrying on partial sends.
void connect_for(const endpoint &peer, const std::chrono::duration< Rep, Period > &timeout)
Connects the socket with a bounded timeout.
void send_all(std::string_view buf)
Sends a string view in full, retrying on partial sends.
result< void > try_shutdown()
Shuts down both directions on the socket.
void send_all(std::span< const std::byte > buf)
Sends buf in full, retrying on partial sends.
result< void > try_connect_for(const endpoint &peer, const std::chrono::duration< Rep, Period > &timeout)
Connects the socket with a bounded timeout.
size_t send(std::string_view buf)
Sends a string view on the connected socket.
result< void > try_send_all(std::span< const std::byte > buf)
Sends buf in full, retrying on partial sends.
static result< stream_socket > make(address_family fam)
Creates a new TCP socket of the given address family.
stream_socket(const config &cfg)
Creates a new TCP socket with the given configuration.
bool get_no_delay() const noexcept
Returns whether Nagle's algorithm is currently disabled on this socket.
static result< stream_socket > connect_to(const endpoint &peer)
Creates a TCP socket and synchronously connects to the peer.
static result< stream_socket > connect_to(const endpoint &peer, const config &cfg)
Creates a TCP socket with the given configuration and connects to the peer.
stream_socket(const endpoint &peer)
Creates a TCP socket and synchronously connects to the peer.
static result< stream_socket > connect_to_for(std::string_view host, port_number port, const std::chrono::duration< Rep, Period > &timeout, const config &cfg, const resolver_options &opts={})
Resolves host : port and connects to the first reachable endpoint, bounding each per-candidate attemp...
size_t send(std::span< const std::byte > buf)
Sends bytes on the connected socket.
void shutdown(direction dir)
Shuts down one direction on the socket (half-close).
stream_socket(std::string_view host, port_number port)
Resolves host : port and connects to the first reachable endpoint, using default socket configuration...
stream_socket(std::string_view host, port_number port, const std::chrono::duration< Rep, Period > &timeout, const config &cfg, const resolver_options &opts={})
Resolves host : port and connects to the first reachable endpoint, bounding each per-candidate attemp...
stream_socket(const endpoint &peer, const config &cfg)
Creates a TCP socket with the given configuration and connects to the peer.
stream_socket(std::string_view host, port_number port, const config &cfg, const resolver_options &opts={})
Resolves host : port and connects to the first reachable endpoint.
void set_keep_idle(const std::chrono::duration< Rep, Period > &t) noexcept
Sets the time the connection must be idle before keep-alive probes start.
result< size_t > try_send(std::string_view buf)
Sends a string view on the connected socket.
static result< stream_socket > connect_to(std::string_view host, port_number port, const config &cfg, const resolver_options &opts={})
Resolves host : port and connects to the first reachable endpoint.
stream_socket(address_family fam)
Creates a new TCP socket of the given address family.
static result< stream_socket > connect_to_for(std::string_view host, port_number port, const std::chrono::duration< Rep, Period > &timeout)
Resolves host : port and connects to the first reachable endpoint, using default socket configuration...
static result< stream_socket > make(const config &cfg)
Creates a new TCP socket with the given configuration.
void set_keep_alive(bool on) noexcept
Toggles TCP keep-alive — periodic probes on idle connections to detect dead peers.
void set_keep_interval(const std::chrono::duration< Rep, Period > &t) noexcept
Sets the interval between successive keep-alive probes.
stream_socket()
Creates a new TCP socket with default configuration (IPv4, blocking).
static result< stream_socket > connect_to(std::string_view host, port_number port)
Resolves host : port and connects to the first reachable endpoint, using default socket configuration...
void set_no_delay(bool on) noexcept
Toggles whether Nagle's algorithm is disabled — when on, small writes are sent immediately rather tha...
static result< stream_socket > make()
Creates a new TCP socket with default configuration (IPv4, blocking).
result< size_t > try_send(std::span< const std::byte > buf)
Sends bytes on the connected socket.
void set_keep_count(uint32_t count) noexcept
Sets the maximum number of unacknowledged keep-alive probes before the connection is dropped.
void shutdown()
Shuts down both directions on the socket.
void recv_exact(std::span< std::byte > buf)
Receives until buf is filled, treating premature close as an error.
result< void > try_recv_exact(std::span< std::byte > buf)
Receives until buf is filled, treating premature close as an error.
address_family
Address family.
direction
One direction of a bidirectional transport.
uint16_t port_number
Port number type for transport endpoints.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ timeout
Operation timed out.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Resolver hints used by the resolution functions.
Stream socket configuration.