Seastar
High performance C++ framework for concurrent servers
Public Member Functions | List of all members
seastar::connected_socket Class Reference

Detailed Description

A TCP (or other stream-based protocol) connection.

A connected_socket represents a full-duplex stream between two endpoints, a local endpoint and a remote endpoint.

#include <seastar/net/api.hh>

Public Member Functions

 connected_socket () noexcept
 Constructs a connected_socket not corresponding to a connection.
 
 connected_socket (connected_socket &&cs) noexcept
 Moves a connected_socket object.
 
connected_socketoperator= (connected_socket &&cs) noexcept
 Move-assigns a connected_socket object.
 
input_stream< char > input (connected_socket_input_stream_config csisc={})
 
output_stream< char > output (size_t buffer_size=8192)
 
void set_nodelay (bool nodelay)
 Sets the TCP_NODELAY option (disabling Nagle's algorithm)
 
bool get_nodelay () const
 
void set_keepalive (bool keepalive)
 Sets SO_KEEPALIVE option (enable keepalive timer on a socket)
 
bool get_keepalive () const
 
void set_keepalive_parameters (const net::keepalive_params &p)
 Sets TCP keepalive parameters.
 
net::keepalive_params get_keepalive_parameters () const
 Get TCP keepalive parameters.
 
void set_sockopt (int level, int optname, const void *data, size_t len)
 
int get_sockopt (int level, int optname, void *data, size_t len) const
 
socket_address local_address () const noexcept
 Local address of the socket.
 
socket_address remote_address () const noexcept
 Remote address of the socket.
 
void shutdown_output ()
 
void shutdown_input ()
 
 operator bool () const noexcept
 
future wait_input_shutdown ()
 

Member Function Documentation

◆ get_keepalive()

bool seastar::connected_socket::get_keepalive ( ) const

Gets O_KEEPALIVE option

Returns
whether the keepalive option is enabled or not

◆ get_nodelay()

bool seastar::connected_socket::get_nodelay ( ) const

Gets the TCP_NODELAY option (Nagle's algorithm)

Returns
whether the nodelay option is enabled or not

◆ get_sockopt()

int seastar::connected_socket::get_sockopt ( int  level,
int  optname,
void *  data,
size_t  len 
) const

Gets custom socket options. Based on getsockopt function. Linux users should refer to protocol-specific manuals to see available options, e.g. tcp(7), ip(7), etc.

◆ input()

input_stream<char> seastar::connected_socket::input ( connected_socket_input_stream_config  csisc = {})

Gets the input stream.

Parameters
csiscConfiguration for the input_stream returned

Gets an object returning data sent from the remote endpoint.

◆ operator bool()

seastar::connected_socket::operator bool ( ) const
inlineexplicitnoexcept

Check whether the connected_socket is initialized.

Returns
true if this connected_socket socket_address is bound initialized false otherwise.
See also
connect(socket_address sa)
connect(socket_address sa, socket_address local, transport proto)

◆ output()

output_stream<char> seastar::connected_socket::output ( size_t  buffer_size = 8192)

Gets the output stream.

Gets an object that sends data to the remote endpoint.

Parameters
buffer_sizehow much data to buffer

◆ set_sockopt()

void seastar::connected_socket::set_sockopt ( int  level,
int  optname,
const void *  data,
size_t  len 
)

Sets custom socket options. Based on setsockopt function. Linux users should refer to protocol-specific manuals to see available options, e.g. tcp(7), ip(7), etc.

◆ shutdown_input()

void seastar::connected_socket::shutdown_input ( )

Disables input from the socket.

Current or future reads will immediately fail with an error. This is useful to abort operations on a socket that is not making progress due to a peer failure.

◆ shutdown_output()

void seastar::connected_socket::shutdown_output ( )

Disables output to the socket.

Current or future writes that have not been successfully flushed will immediately fail with an error. This is useful to abort operations on a socket that is not making progress due to a peer failure.

◆ wait_input_shutdown()

future seastar::connected_socket::wait_input_shutdown ( )

Waits for the peer of this socket to disconnect

Returns
future that resolves when the peer closes connection or shuts it down for writing or when local socket is called shutdown_input().

Note, that when the returned future is resolved for whatever reason socket may still be readable from, so the caller may want to wait for both events – this one and EOF from read.

Calling it several times per socket is not allowed (undefined behavior)

See also
poll(2) about POLLRDHUP for more details

The documentation for this class was generated from the following file: