StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StormByte::Network::Endpoint Class Referenceabstract

Abstract base for network endpoints (clients/servers). More...

#include <endpoint.hxx>

Inheritance diagram for StormByte::Network::Endpoint:
Inheritance graph
[legend]

Public Member Functions

 Endpoint (const DeserializePacketFunction &deserialize_packet_function, std::shared_ptr< Logger::Log > logger) noexcept
 Constructs an Endpoint.
 
 Endpoint (const Endpoint &other)=delete
 Copy constructor (deleted).
 
 Endpoint (Endpoint &&other) noexcept=default
 Move constructor.
 
virtual ~Endpoint () noexcept=default
 Virtual destructor.
 
Endpointoperator= (const Endpoint &other)=delete
 Copy-assignment operator (deleted).
 
Endpointoperator= (Endpoint &&other) noexcept=default
 Move-assignment operator.
 
virtual bool Connect (const Connection::Protocol &protocol, const std::string &address, const unsigned short &port)=0
 Establish a connection to a server.
 
virtual void Disconnect () noexcept=0
 Disconnect from the server, if connected.
 
virtual Connection::Status Status () const noexcept=0
 Gets the current connection status.
 

Protected Member Functions

std::shared_ptr< Connection::Client > CreateConnection (std::shared_ptr< Socket::Client > socket) noexcept
 Create a Connection::Client wrapper for an accepted socket.
 
virtual Buffer::Pipeline InputPipeline () const noexcept=0
 Provide the input Buffer::Pipeline for incoming data.
 
virtual Buffer::Pipeline OutputPipeline () const noexcept=0
 Provide the output Buffer::Pipeline for outgoing data.
 
PacketPointer Send (std::shared_ptr< Connection::Client > client_connection, const Transport::Packet &packet) noexcept
 Send a transport packet over the specified connection and obtains the response.
 
bool Reply (std::shared_ptr< Connection::Client > client_connection, const Transport::Packet &packet) noexcept
 Send a transport packet as a reply over the specified connection.
 

Protected Attributes

DeserializePacketFunction m_deserialize_packet_function
 The packet deserialization function.
 
std::shared_ptr< Logger::Log > m_logger
 The logger instance.
 

Detailed Description

Abstract base for network endpoints (clients/servers).

Provides common functionality shared by concrete endpoint implementations such as Client and Server. This class is exported from the library but is not intended to be instantiated directly; implementors should derive from Endpoint and override the protected hooks as required.

Constructor & Destructor Documentation

◆ Endpoint() [1/3]

StormByte::Network::Endpoint::Endpoint ( const DeserializePacketFunction deserialize_packet_function,
std::shared_ptr< Logger::Log >  logger 
)
noexcept

Constructs an Endpoint.

Parameters
deserialize_packet_functionFunction used to deserialize incoming transport packets into domain Packet objects.
loggerLogger instance used by the endpoint for diagnostic messages (copied into the endpoint).

◆ Endpoint() [2/3]

StormByte::Network::Endpoint::Endpoint ( const Endpoint other)
delete

Copy constructor (deleted).

Copying is disabled to avoid accidental sharing of connection state.

◆ Endpoint() [3/3]

StormByte::Network::Endpoint::Endpoint ( Endpoint &&  other)
defaultnoexcept

Move constructor.

Move semantics are supported to allow transfer of ownership of non-copyable members.

◆ ~Endpoint()

virtual StormByte::Network::Endpoint::~Endpoint ( )
virtualdefaultnoexcept

Virtual destructor.

Declared pure to make Endpoint an abstract base. Concrete subclasses must provide an implementation for the destructor (even if defaulted) in their translation unit.

Member Function Documentation

◆ Connect()

virtual bool StormByte::Network::Endpoint::Connect ( const Connection::Protocol &  protocol,
const std::string &  address,
const unsigned short &  port 
)
pure virtual

Establish a connection to a server.

Parameters
protocolThe protocol to use for the connection.
portThe port to connect to.
Returns
True if the connection was successful, false otherwise.

Implemented in StormByte::Network::Client, and StormByte::Network::Server.

◆ CreateConnection()

std::shared_ptr< Connection::Client > StormByte::Network::Endpoint::CreateConnection ( std::shared_ptr< Socket::Client >  socket)
protectednoexcept

Create a Connection::Client wrapper for an accepted socket.

Parameters
socketShared pointer to the underlying client socket.
Returns
Shared pointer to the created Connection::Client instance.

◆ Disconnect()

virtual void StormByte::Network::Endpoint::Disconnect ( )
pure virtualnoexcept

Disconnect from the server, if connected.

Implemented in StormByte::Network::Client, and StormByte::Network::Server.

◆ InputPipeline()

virtual Buffer::Pipeline StormByte::Network::Endpoint::InputPipeline ( ) const
protectedpure virtualnoexcept

Provide the input Buffer::Pipeline for incoming data.

Override this hook in derived classes to return a custom pipeline that will be applied to inbound buffers.

Returns
A Buffer::Pipeline instance for input processing.

◆ operator=() [1/2]

Endpoint & StormByte::Network::Endpoint::operator= ( const Endpoint other)
delete

Copy-assignment operator (deleted).

Copy assignment is disabled for the same reasons as copy construction.

◆ operator=() [2/2]

Endpoint & StormByte::Network::Endpoint::operator= ( Endpoint &&  other)
defaultnoexcept

Move-assignment operator.

Provides move-assignment for transfer of ownership of internal resources.

◆ OutputPipeline()

virtual Buffer::Pipeline StormByte::Network::Endpoint::OutputPipeline ( ) const
protectedpure virtualnoexcept

Provide the output Buffer::Pipeline for outgoing data.

Override this hook to return a pipeline that will be applied to buffers before they are transmitted.

Returns
A Buffer::Pipeline instance for output processing.

◆ Reply()

bool StormByte::Network::Endpoint::Reply ( std::shared_ptr< Connection::Client >  client_connection,
const Transport::Packet packet 
)
protectednoexcept

Send a transport packet as a reply over the specified connection.

The packet is prepared (e.g. serialized/enqueued) and handed to the transport for transmission. This function does not expect a response packet.

Parameters
client_connectionConnection to use for sending the packet.
packetThe transport-level packet to send.
Returns
True if the packet was sent successfully, false otherwise.

◆ Send()

PacketPointer StormByte::Network::Endpoint::Send ( std::shared_ptr< Connection::Client >  client_connection,
const Transport::Packet packet 
)
protectednoexcept

Send a transport packet over the specified connection and obtains the response.

The packet is prepared (e.g. serialized/enqueued) and handed to the transport for transmission. Implementations should return a pointer to the packet representation used by the transport, or nullptr on failure.

Parameters
client_connectionConnection to use for sending the packet.
packetThe transport-level packet to send.
Returns
A PacketPointer to the enqueued/sent packet, or nullptr if sending failed.

◆ Status()

virtual Connection::Status StormByte::Network::Endpoint::Status ( ) const
pure virtualnoexcept

Gets the current connection status.

Returns
The current connection status.

Implemented in StormByte::Network::Client, and StormByte::Network::Server.


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