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

#include <base_socket.hpp>

Inheritance diagram for fly::net::detail::BaseSocket< EndpointType >:

Public Types

using endpoint_type = EndpointType
 
using address_type = typename EndpointType::address_type
 

Public Member Functions

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
 

Static Public Member Functions

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

 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<fly::net::IPEndpoint EndpointType>
class fly::net::detail::BaseSocket< EndpointType >

Base class to represent a network socket and provide functionality needed by all concrete socket types.

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

Constructor & Destructor Documentation

◆ BaseSocket() [1/3]

template<fly::net::IPEndpoint EndpointType>
fly::net::detail::BaseSocket< EndpointType >::BaseSocket ( std::shared_ptr< fly::net::NetworkConfig config,
socket_type  handle,
fly::net::IOMode  mode 
)
protectednoexcept

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

Parameters
configReference to network configuration.
handleNative socket handle opened by the concrete socket type.
modeIO processing mode to apply to the socket.

◆ BaseSocket() [2/3]

template<fly::net::IPEndpoint EndpointType>
fly::net::detail::BaseSocket< EndpointType >::BaseSocket ( const std::shared_ptr< fly::net::SocketService > &  service,
std::shared_ptr< fly::net::NetworkConfig config,
socket_type  handle 
)
protectednoexcept

Constructor. Initialize the socket in an asynchronous IO processing mode armed with the provided socket service for performing IO operations.

Parameters
serviceThe socket service for performing IO operations.
configReference to network configuration.
handleNative socket handle opened by the concrete socket type.

◆ BaseSocket() [3/3]

template<fly::net::IPEndpoint EndpointType>
fly::net::detail::BaseSocket< EndpointType >::BaseSocket ( BaseSocket< EndpointType > &&  socket)
protectednoexcept

Move constructor. The provided socket is left in an invalid state.

Parameters
socketThe socket instance to move.

◆ ~BaseSocket()

template<fly::net::IPEndpoint EndpointType>
fly::net::detail::BaseSocket< EndpointType >::~BaseSocket
protectedvirtualnoexcept

Destructor. If needed, close the socket.

Member Function Documentation

◆ bind() [1/2]

template<fly::net::IPEndpoint EndpointType>
bool fly::net::detail::BaseSocket< EndpointType >::bind ( const EndpointType &  endpoint,
BindMode  mode 
) const

Bind this socket to a local endpoint.

Parameters
endpointThe local endpoint to bind to.
modeBinding mode to apply to the socket before binding.
Returns
True if the binding was successful.

◆ bind() [2/2]

template<fly::net::IPEndpoint EndpointType>
bool fly::net::detail::BaseSocket< EndpointType >::bind ( std::string_view  hostname,
port_type  port,
BindMode  mode 
) const

Bind this socket to a local endpoint.

Parameters
hostnameThe hostname or IP address string to bind to.
portThe port to bind to.
modeBinding mode to apply to the socket before binding.
Returns
True if the binding was successful.

◆ close()

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

If this socket is valid, close this socket.

◆ handle()

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

◆ hostname_to_address()

template<fly::net::IPEndpoint EndpointType>
auto fly::net::detail::BaseSocket< EndpointType >::hostname_to_address ( std::string_view  hostname)
static

Convert a hostname or IP address string to an IP address.

Parameters
hostnameThe hostname or IP address string to convert.
Returns
If successful, the created IP address. Otherwise, an uninitialized value.

◆ io_mode()

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

◆ is_ipv4()

template<fly::net::IPEndpoint EndpointType>
constexpr bool fly::net::detail::BaseSocket< EndpointType >::is_ipv4
staticconstexpr
Returns
True if this is an IPv4 socket.

◆ is_ipv6()

template<fly::net::IPEndpoint EndpointType>
constexpr bool fly::net::detail::BaseSocket< EndpointType >::is_ipv6
staticconstexpr
Returns
True if this is an IPv6 socket.

◆ is_open()

template<fly::net::IPEndpoint EndpointType>
bool fly::net::detail::BaseSocket< EndpointType >::is_open
Returns
True if the socket handle is opened.

◆ local_endpoint()

template<fly::net::IPEndpoint EndpointType>
std::optional< EndpointType > fly::net::detail::BaseSocket< EndpointType >::local_endpoint

Retrieve the local endpoint to which this socket is bound.

Returns
If successful, the bound endpoint. Otherwise, an uninitialized value.

◆ network_config()

template<fly::net::IPEndpoint EndpointType>
std::shared_ptr< fly::net::NetworkConfig > fly::net::detail::BaseSocket< EndpointType >::network_config
protected
Returns
A strong pointer to the network configuration.

◆ operator=()

template<fly::net::IPEndpoint EndpointType>
BaseSocket< EndpointType > & fly::net::detail::BaseSocket< EndpointType >::operator= ( BaseSocket< EndpointType > &&  socket)
protectednoexcept

Move assignment operator. The provided socket is left in an invalid state.

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

◆ packet_size()

template<fly::net::IPEndpoint EndpointType>
std::size_t fly::net::detail::BaseSocket< EndpointType >::packet_size
protected
Returns
Size of packet to use for IO operations.

◆ set_io_mode()

template<fly::net::IPEndpoint EndpointType>
bool fly::net::detail::BaseSocket< EndpointType >::set_io_mode ( fly::net::IOMode  mode)

Configure the socket to operate in the provided IO processing mode.

Parameters
modeIO processing mode to apply to the socket.
Returns
True if the operation was successful.

◆ socket_id()

template<fly::net::IPEndpoint EndpointType>
std::uint64_t fly::net::detail::BaseSocket< EndpointType >::socket_id
Returns
This socket's unique ID.

◆ socket_service()

template<fly::net::IPEndpoint EndpointType>
std::shared_ptr< fly::net::SocketService > fly::net::detail::BaseSocket< EndpointType >::socket_service
protected
Returns
A strong (possibly null) pointer to the socket service.

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