24 #ifndef SEASTAR_MODULE
29 #include <sys/types.h>
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/iostream.hh>
39 #include <seastar/util/std-compat.hh>
40 #include <seastar/util/program-options.hh>
41 #include <seastar/util/modules.hh>
46 bool is_ip_unspecified(
const ipv4_addr& addr) noexcept {
47 return addr.is_ip_unspecified();
51 bool is_port_unspecified(
const ipv4_addr& addr) noexcept {
52 return addr.is_port_unspecified();
56 socket_address make_ipv4_address(
const ipv4_addr& addr) noexcept {
57 return socket_address(addr);
61 socket_address make_ipv4_address(uint32_t ip, uint16_t port) noexcept {
62 return make_ipv4_address(ipv4_addr(ip, port));
69 std::chrono::seconds idle;
70 std::chrono::seconds interval;
76 std::chrono::seconds interval;
80 using keepalive_params = std::variant<tcp_keepalive_params, sctp_keepalive_params>;
83 class connected_socket_impl;
86 class server_socket_impl;
87 class datagram_channel_impl;
96 virtual uint16_t get_dst_port() = 0;
97 virtual packet& get_data() = 0;
104 std::unique_ptr<datagram_impl> _impl;
106 datagram(std::unique_ptr<datagram_impl>&&
impl) noexcept : _impl(std::move(
impl)) {};
109 uint16_t get_dst_port() {
return _impl->get_dst_port(); }
110 packet& get_data() {
return _impl->get_data(); }
117 std::unique_ptr<datagram_channel_impl> _impl;
131 bool is_closed()
const;
146 class network_interface_impl;
183 friend class net::get_impl;
184 std::unique_ptr<net::connected_socket_impl> _csi;
191 explicit
connected_socket(std::unique_ptr<net::connected_socket_impl> csi) noexcept;
226 void set_sockopt(
int level,
int optname,
const void* data,
size_t len);
230 int get_sockopt(
int level,
int optname,
void* data,
size_t len)
const;
256 explicit operator
bool() const noexcept {
257 return static_cast<bool>(_csi);
283 std::unique_ptr<net::socket_impl> _si;
285 socket() noexcept =
default;
289 explicit socket(std::unique_ptr<net::socket_impl> si) noexcept;
326 std::unique_ptr<net::server_socket_impl> _ssi;
327 bool _aborted =
false;
329 enum class load_balancing_algorithm {
332 connection_distribution,
340 default_ = connection_distribution
345 explicit
server_socket(std::unique_ptr<net::server_socket_impl> ssi) noexcept;
384 explicit operator
bool() const noexcept {
385 return static_cast<bool>(_ssi);
392 bool reuse_address =
false;
393 server_socket::load_balancing_algorithm lba = server_socket::load_balancing_algorithm::default_;
394 transport proto = transport::TCP;
395 int listen_backlog = 100;
396 unsigned fixed_cpu = 0u;
397 void set_fixed_cpu(
unsigned cpu) {
398 lba = server_socket::load_balancing_algorithm::fixed;
413 uint32_t index()
const;
414 uint32_t mtu()
const;
416 const sstring& name()
const;
417 const sstring& display_name()
const;
418 const std::vector<net::inet_address>& addresses()
const;
419 const std::vector<uint8_t> hardware_address()
const;
421 bool is_loopback()
const;
422 bool is_virtual()
const;
424 bool supports_ipv6()
const;
433 virtual ::seastar::socket
socket() = 0;
435 [[deprecated(
"Use `make_[un]bound_datagram_channel` instead")]]
436 virtual net::udp_channel make_udp_channel(
const socket_address& = {}) = 0;
443 virtual bool has_per_core_namespace() = 0;
447 virtual bool supports_ipv6()
const {
463 std::unique_ptr<program_options::option_group> opts;
void set_keepalive(bool keepalive)
Sets SO_KEEPALIVE option (enable keepalive timer on a socket)
output_stream< char > output(size_t buffer_size=8192)
void set_keepalive_parameters(const net::keepalive_params &p)
Sets TCP keepalive parameters.
socket_address local_address() const noexcept
Local address of the socket.
input_stream< char > input(connected_socket_input_stream_config csisc={})
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:1238
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:290
A listening socket, waiting to accept incoming network connections.
Definition: api.hh:325
socket_address local_address() const noexcept
server_socket() noexcept
Constructs a server_socket without being bound to any address.
future< accept_result > accept()
Definition: socket_defs.hh:47
socket(socket &&) noexcept
Moves a seastar::socket object.
future< connected_socket > connect(socket_address sa, socket_address local={}, transport proto=transport::TCP)
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:1934
unsigned min_buffer_size
Definition: api.hh:165
unsigned max_buffer_size
Definition: api.hh:169
socket_address remote_address
The address of the peer that connected to us.
Definition: api.hh:321
connected_socket connection
The newly-accepted connection.
Definition: api.hh:320
unsigned buffer_size
Initial buffer size to use for input buffering.
Definition: api.hh:161
The result of an server_socket::accept() call.
Definition: api.hh:319
Distinguished name.
Definition: api.hh:173
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