libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
fly::net::ListenSocket< EndpointType > Class Template Reference

#include <listen_socket.hpp>

Inheritance diagram for fly::net::ListenSocket< EndpointType >:
Collaboration diagram for fly::net::ListenSocket< EndpointType >:

Public Member Functions

 ListenSocket (std::shared_ptr< NetworkConfig > config) noexcept
 
 ListenSocket (std::shared_ptr< NetworkConfig > config, IOMode mode) noexcept
 
 ListenSocket (ListenSocket &&socket) noexcept
 
ListenSocketoperator= (ListenSocket &&socket) noexcept
 
bool listen ()
 
bool is_listening () const
 
std::optional< TcpSocket< EndpointType > > accept ()
 
bool accept_async (AcceptCompletion &&callback)
 
void close ()
 
socket_type handle () const
 
fly::net::IOMode io_mode () const
 
- Public Member Functions inherited from fly::net::detail::BaseSocket< EndpointType >
bool is_open () const
 
socket_type handle () const
 
std::uint64_t socket_id () const
 
bool set_io_mode (fly::net::IOMode mode)
 
fly::net::IOMode io_mode () const
 
std::optional< EndpointType > local_endpoint () const
 
void close ()
 
bool bind (const EndpointType &endpoint, BindMode mode) const
 
bool bind (std::string_view hostname, port_type port, BindMode mode) const
 

Additional Inherited Members

- Public Types inherited from fly::net::detail::BaseSocket< EndpointType >
using endpoint_type = EndpointType
 
using address_type = typename EndpointType::address_type
 
- Static Public Member Functions inherited from fly::net::detail::BaseSocket< EndpointType >
static constexpr bool is_ipv4 ()
 
static constexpr bool is_ipv6 ()
 
static std::optional< address_type > hostname_to_address (std::string_view hostname)
 
- Protected Member Functions inherited from fly::net::detail::BaseSocket< EndpointType >
 BaseSocket (std::shared_ptr< fly::net::NetworkConfig > config, socket_type handle, fly::net::IOMode mode) noexcept
 
 BaseSocket (const std::shared_ptr< fly::net::SocketService > &service, std::shared_ptr< fly::net::NetworkConfig > config, socket_type handle) noexcept
 
 BaseSocket (BaseSocket &&socket) noexcept
 
virtual ~BaseSocket () noexcept
 
BaseSocketoperator= (BaseSocket &&socket) noexcept
 
std::shared_ptr< fly::net::SocketServicesocket_service () const
 
std::shared_ptr< fly::net::NetworkConfignetwork_config () const
 
std::size_t packet_size () const
 

Detailed Description

template<IPEndpoint EndpointType>
class fly::net::ListenSocket< EndpointType >

Class to represent a listening socket for accepting incoming network connection requests from connection-oriented sockets.

Author
Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
Version
February 13, 2021

Constructor & Destructor Documentation

◆ ListenSocket() [1/3]

template<IPEndpoint EndpointType>
fly::net::ListenSocket< EndpointType >::ListenSocket ( std::shared_ptr< NetworkConfig config)
explicitnoexcept

Constructor. Open the socket in a synchronous IO processing mode.

Parameters
configReference to network configuration.

◆ ListenSocket() [2/3]

template<IPEndpoint EndpointType>
fly::net::ListenSocket< EndpointType >::ListenSocket ( std::shared_ptr< NetworkConfig config,
IOMode  mode 
)
noexcept

Constructor. Open the socket in the provided IO processing mode.

Parameters
configReference to network configuration.
modeIO processing mode to apply to the socket.

◆ ListenSocket() [3/3]

template<IPEndpoint EndpointType>
fly::net::ListenSocket< EndpointType >::ListenSocket ( ListenSocket< EndpointType > &&  socket)
noexcept

Move constructor. The provided socket is left in a non-listening, invalid state.

Parameters
socketThe socket instance to move.

Member Function Documentation

◆ accept()

template<IPEndpoint EndpointType>
std::optional< TcpSocket< EndpointType > > fly::net::ListenSocket< EndpointType >::accept

Accept an incoming connection on this listening socket. If an error occurs on the socket, the socket will be closed.

Returns
If successful, the accepted socket. Otherwise, an uninitialized value.

◆ accept_async()

template<IPEndpoint EndpointType>
bool fly::net::ListenSocket< EndpointType >::accept_async ( AcceptCompletion &&  callback)

Asynchronously accept an incoming connection on this listening socket. May only be used if this socket was created through a socket service.

If successful, the provided callback will be invoked with the accepted socket upon completion. Otherwise, the provided callback will be invoked with an uninitialized value, and the socket will be closed before the invocation.

Parameters
callbackThe callback to invoke when the operation has completed.
Returns
True if the socket service and the provided callback are valid.

◆ close()

template<IPEndpoint EndpointType>
void fly::net::detail::BaseSocket< EndpointType >::close

If this socket is valid, close this socket.

◆ handle()

template<IPEndpoint EndpointType>
socket_type fly::net::detail::BaseSocket< EndpointType >::handle
Returns
This socket's native handle.

◆ io_mode()

template<IPEndpoint EndpointType>
fly::net::IOMode fly::net::detail::BaseSocket< EndpointType >::io_mode
Returns
This socket's IO processing mode.

◆ is_listening()

template<IPEndpoint EndpointType>
bool fly::net::ListenSocket< EndpointType >::is_listening
Returns
True if this socket is listening for incoming connections.

◆ listen()

template<IPEndpoint EndpointType>
bool fly::net::ListenSocket< EndpointType >::listen

Configure this socket to be used to accept incoming connections.

Returns
True if the operation was successful.

◆ operator=()

template<IPEndpoint EndpointType>
ListenSocket< EndpointType > & fly::net::ListenSocket< EndpointType >::operator= ( ListenSocket< EndpointType > &&  socket)
noexcept

Move assignment operator. The provided socket is left in a non-listening, invalid state.

Parameters
socketThe socket instance to move.
Returns
A reference to this socket.

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