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

Represents a network endpoint, serving as a base class for both clients and servers. More...

#include <endpoint.hxx>

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

Public Member Functions

 EndPoint (const Connection::Protocol &protocol, std::shared_ptr< Connection::Handler > handler, std::shared_ptr< Logger > logger) noexcept
 Constructs an EndPoint with the specified protocol, handler, and logger.
 
 EndPoint (const EndPoint &other)=delete
 Deleted copy constructor to prevent copying.
 
 EndPoint (EndPoint &&other) noexcept=default
 Defaulted move constructor.
 
virtual ~EndPoint () noexcept
 Virtual destructor for proper cleanup in derived classes.
 
EndPointoperator= (const EndPoint &other)=delete
 Deleted copy assignment operator to prevent copying.
 
EndPointoperator= (EndPoint &&other) noexcept=default
 Defaulted move assignment operator.
 
virtual ExpectedVoid Connect (const std::string &host, const unsigned short &port) noexcept=0
 Starts the endpoint (client or server) and connects/binds to the specified host and port.
 
virtual void Disconnect () noexcept
 Stops the endpoint (client or server) and disconnects.
 
const Connection::Protocol & Protocol () const noexcept
 Retrieves the protocol used by the endpoint.
 
Connection::Status Status () const noexcept
 Retrieves the current connection status of the endpoint.
 

Protected Member Functions

virtual ExpectedVoid Handshake (Socket::Client &client) noexcept
 Sets up the connection handler for the endpoint.
 
virtual ExpectedVoid Authenticate (Socket::Client &client) noexcept
 Authenticates the client connection.
 
ExpectedPacket Receive (Socket::Client &client) noexcept
 Receives packet from the client processing pipeline before constructing packet.
 
ExpectedPacket RawReceive (Socket::Client &client) noexcept
 Receives packet from the client without processing pipeline before constructing packet.
 
ExpectedVoid Send (Socket::Client &client, const Packet &packet) noexcept
 Sends a packet to the client processing pipeline before sending packet.
 
ExpectedVoid RawSend (Socket::Client &client, const Packet &packet) noexcept
 Sends a packet to the client without processing pipeline before sending packet.
 

Protected Attributes

Connection::Protocol m_protocol
 The protocol used by the endpoint (e.g., IPv4, IPv6).
 
std::shared_ptr< Connection::Handlerm_handler
 Shared pointer to the connection handler.
 
std::shared_ptr< Logger > m_logger
 Shared pointer to the logger instance.
 
std::atomic< Connection::Status > m_status
 The current connection status of the endpoint.
 
Socket::Socket * m_socket
 Unique pointer to the socket instance.
 
Buffer::Pipeline m_input_pipeline
 
Buffer::Pipeline m_output_pipeline
 The input/output pipeline for processing data.
 

Detailed Description

Represents a network endpoint, serving as a base class for both clients and servers.

Constructor & Destructor Documentation

◆ EndPoint()

StormByte::Network::EndPoint::EndPoint ( const Connection::Protocol &  protocol,
std::shared_ptr< Connection::Handler handler,
std::shared_ptr< Logger >  logger 
)
noexcept

Constructs an EndPoint with the specified protocol, handler, and logger.

Parameters
protocolThe protocol to use (e.g., IPv4, IPv6).
handlerA shared pointer to the connection handler.
loggerA shared pointer to the logger instance.

Member Function Documentation

◆ Authenticate()

virtual ExpectedVoid StormByte::Network::EndPoint::Authenticate ( Socket::Client &  client)
protectedvirtualnoexcept

Authenticates the client connection.

Parameters
clientA reference to the client socket.
Returns
An expected void or error.

◆ Connect()

virtual ExpectedVoid StormByte::Network::EndPoint::Connect ( const std::string &  host,
const unsigned short &  port 
)
pure virtualnoexcept

Starts the endpoint (client or server) and connects/binds to the specified host and port.

Parameters
hostThe hostname or IP address to connect to.
portThe port number to connect to.
Returns
An expected void or error.

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

◆ Disconnect()

virtual void StormByte::Network::EndPoint::Disconnect ( )
virtualnoexcept

Stops the endpoint (client or server) and disconnects.

Reimplemented in StormByte::Network::Server.

◆ Handshake()

virtual ExpectedVoid StormByte::Network::EndPoint::Handshake ( Socket::Client &  client)
protectedvirtualnoexcept

Sets up the connection handler for the endpoint.

Parameters
clientA reference to the client socket.
Returns
An expected void or error.

◆ Protocol()

const Connection::Protocol & StormByte::Network::EndPoint::Protocol ( ) const
noexcept

Retrieves the protocol used by the endpoint.

Returns
A constant reference to the protocol.

◆ RawReceive()

ExpectedPacket StormByte::Network::EndPoint::RawReceive ( Socket::Client &  client)
protectednoexcept

Receives packet from the client without processing pipeline before constructing packet.

Parameters
clientA reference to the client socket.
Returns
An expected packet or error.

◆ RawSend()

ExpectedVoid StormByte::Network::EndPoint::RawSend ( Socket::Client &  client,
const Packet packet 
)
protectednoexcept

Sends a packet to the client without processing pipeline before sending packet.

Parameters
clientA reference to the client socket.
packetThe packet to send.
Returns
An expected void or error.

◆ Receive()

ExpectedPacket StormByte::Network::EndPoint::Receive ( Socket::Client &  client)
protectednoexcept

Receives packet from the client processing pipeline before constructing packet.

Parameters
clientA reference to the client socket.
pifThe packet instance function to create a packet.
Returns
An expected packet or error.

◆ Send()

ExpectedVoid StormByte::Network::EndPoint::Send ( Socket::Client &  client,
const Packet packet 
)
protectednoexcept

Sends a packet to the client processing pipeline before sending packet.

Parameters
clientA reference to the client socket.
packetThe packet to send.
Returns
An expected void or error.

◆ Status()

Connection::Status StormByte::Network::EndPoint::Status ( ) const
noexcept

Retrieves the current connection status of the endpoint.

Returns
The current connection status.

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