32#include <seastar/core/future.hh>
33#include <seastar/net/byteorder.hh>
34#include <seastar/net/socket_defs.hh>
35#include <seastar/net/packet.hh>
36#include <seastar/core/internal/api-level.hh>
37#include <seastar/core/temporary_buffer.hh>
38#include <seastar/core/file-types.hh>
39#include <seastar/core/iostream.hh>
40#include <seastar/util/std-compat.hh>
41#include <seastar/util/program-options.hh>
42#include <seastar/util/modules.hh>
47bool is_ip_unspecified(
const ipv4_addr& addr)
noexcept {
48 return addr.is_ip_unspecified();
52bool is_port_unspecified(
const ipv4_addr& addr)
noexcept {
53 return addr.is_port_unspecified();
57socket_address make_ipv4_address(
const ipv4_addr& addr)
noexcept {
58 return socket_address(addr);
62socket_address make_ipv4_address(uint32_t ip, uint16_t port)
noexcept {
63 return make_ipv4_address(ipv4_addr(ip, port));
70 std::chrono::seconds idle;
71 std::chrono::seconds interval;
77 std::chrono::seconds interval;
81using keepalive_params = std::variant<tcp_keepalive_params, sctp_keepalive_params>;
84class connected_socket_impl;
87class server_socket_impl;
88class datagram_channel_impl;
97 virtual uint16_t get_dst_port() = 0;
98 virtual packet& get_data() = 0;
105 std::unique_ptr<datagram_impl> _impl;
107 datagram(std::unique_ptr<datagram_impl>&&
impl) noexcept : _impl(std::move(
impl)) {};
110 uint16_t get_dst_port() {
return _impl->get_dst_port(); }
111 packet& get_data() {
return _impl->get_data(); }
118 std::unique_ptr<datagram_channel_impl> _impl;
132 bool is_closed()
const;
147class network_interface_impl;
184 friend class net::get_impl;
185 std::unique_ptr<net::connected_socket_impl> _csi;
227 void set_sockopt(
int level,
int optname,
const void* data,
size_t len);
231 int get_sockopt(
int level,
int optname,
void* data,
size_t len)
const;
257 explicit operator
bool() const noexcept {
258 return static_cast<bool>(_csi);
284 std::unique_ptr<net::socket_impl> _si;
286 socket()
noexcept =
default;
290 explicit socket(std::unique_ptr<net::socket_impl> si)
noexcept;
327 std::unique_ptr<net::server_socket_impl> _ssi;
328 bool _aborted =
false;
330 enum class load_balancing_algorithm {
333 connection_distribution,
341 default_ = connection_distribution
346 explicit
server_socket(
std::unique_ptr<net::server_socket_impl> ssi) noexcept;
385 explicit operator
bool() const noexcept {
386 return static_cast<bool>(_ssi);
398 bool reuse_address =
false;
399 server_socket::load_balancing_algorithm lba = server_socket::load_balancing_algorithm::default_;
400 transport proto = transport::TCP;
401 int listen_backlog = 100;
402 unsigned fixed_cpu = 0u;
403 std::optional<file_permissions> unix_domain_socket_permissions;
417 void set_fixed_cpu(
unsigned cpu) {
418 lba = server_socket::load_balancing_algorithm::fixed;
433 uint32_t index()
const;
434 uint32_t mtu()
const;
436 const sstring& name()
const;
437 const sstring& display_name()
const;
438 const std::vector<net::inet_address>& addresses()
const;
439 const std::vector<uint8_t> hardware_address()
const;
441 bool is_loopback()
const;
442 bool is_virtual()
const;
444 bool supports_ipv6()
const;
453 virtual ::seastar::socket
socket() = 0;
455 [[deprecated(
"Use `make_[un]bound_datagram_channel` instead")]]
463 virtual bool has_per_core_namespace() = 0;
467 virtual bool supports_ipv6()
const {
483 std::unique_ptr<program_options::option_group> opts;
output_stream< char > output(size_t buffer_size=8192)
void set_keepalive(bool keepalive)
Sets SO_KEEPALIVE option (enable keepalive timer on a socket)
input_stream< char > input(connected_socket_input_stream_config csisc={})
void set_keepalive_parameters(const net::keepalive_params &p)
Sets TCP keepalive parameters.
socket_address local_address() const noexcept
Local address of the socket.
int get_sockopt(int level, int optname, void *data, size_t len) const
void set_sockopt(int level, int optname, const void *data, size_t len)
bool get_keepalive() const
void set_nodelay(bool nodelay)
Sets the TCP_NODELAY option (disabling Nagle's algorithm)
socket_address remote_address() const noexcept
Remote address of the socket.
connected_socket() noexcept
Constructs a connected_socket not corresponding to a connection.
net::keepalive_params get_keepalive_parameters() const
Get TCP keepalive parameters.
future wait_input_shutdown()
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
void shutdown_output()
Causes a pending send() to complete (possibly with an exception)
void shutdown_input()
Causes a pending receive() to complete (possibly with an exception)
virtual std::vector< network_interface > network_interfaces()
Definition: program-options.hh:293
A listening socket, waiting to accept incoming network connections.
Definition: api.hh:326
socket_address local_address() const noexcept
future< accept_result > accept()
server_socket() noexcept
Constructs a server_socket without being bound to any address.
Definition: socket_defs.hh:47
future< connected_socket > connect(socket_address sa, socket_address local={}, transport proto=transport::TCP)
socket(socket &&) noexcept
Moves a seastar::socket object.
void set_reuseaddr(bool reuseaddr)
Sets SO_REUSEADDR option (enable reuseaddr option on a socket)
bool get_reuseaddr() const
future< T > make_ready_future(A &&... value) noexcept
Creates a future in an available, value state.
Definition: future.hh:1943
unsigned min_buffer_size
Definition: api.hh:166
unsigned max_buffer_size
Definition: api.hh:170
socket_address remote_address
The address of the peer that connected to us.
Definition: api.hh:322
connected_socket connection
The newly-accepted connection.
Definition: api.hh:321
unsigned buffer_size
Initial buffer size to use for input buffering.
Definition: api.hh:162
The result of an server_socket::accept() call.
Definition: api.hh:320
Distinguished name.
Definition: api.hh:174
holds the implementation parts of the metrics layer, do not use directly.
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: noncopyable_function.hh:37
std::optional< int > so_rcvbuf
Definition: api.hh:415
std::optional< int > so_sndbuf
Definition: api.hh:409