ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy::network::Endpoint Class Referenceabstract

Abstract base for a network endpoint (hostname and port). More...

Public Member Functions

virtual ~Endpoint () noexcept
constexpr uint16_t port () const noexcept
 Returns the port number.
constexpr void setPort (uint16_t port) noexcept
 Sets the port number.
virtual bool setHostname (const char *name) noexcept=0
 Sets the hostname; resolution is implementation-defined.
virtual bool isLocalHost () const noexcept=0
 Returns whether the endpoint represents the local host.
virtual void setLocalHost () noexcept=0
 Sets the endpoint to the local host.
virtual const char * hostnameAsText () const noexcept=0
 Returns the hostname as a C string.

Protected Member Functions

constexpr Endpoint () noexcept=default
 Default constructor.

Private Attributes

uint16_t _port = 0
 Port in host byte order.

Detailed Description

Abstract base for a network endpoint (hostname and port).

Subclasses provide platform-specific storage and resolution. port() and setPort() operate on the stored port; hostname and resolution are handled by virtual methods.

Key Features

Usage Example

#include "network.hpp"
void configureEndpoint(toy::network::Endpoint * ep) {
ep->setPort(8080);
if (ep->setHostname("example.com")) {
const char* host = ep->hostnameAsText();
(void)host;
}
}
Abstract base for a network endpoint (hostname and port).
Definition endpoint.hpp:74
virtual bool setHostname(const char *name) noexcept=0
Sets the hostname; resolution is implementation-defined.
constexpr void setPort(uint16_t port) noexcept
Sets the port number.
Definition endpoint.inl:36
virtual const char * hostnameAsText() const noexcept=0
Returns the hostname as a C string.
Umbrella header for the network module.

Performance Characteristics

  • port() / setPort(): O(1).
  • Virtual methods: Platform-dependent (resolution, allocation).

Safety Guarantees

  • hostnameAsText(): Returned pointer valid until the endpoint is modified or destroyed.
  • setHostname(name): name must point to valid memory for the duration of the call.
See also
toy::network::SocketType

Constructor & Destructor Documentation

◆ ~Endpoint()

toy::network::Endpoint::~Endpoint ( )
virtualdefaultnoexcept

◆ Endpoint()

toy::network::Endpoint::Endpoint ( )
constexprprotecteddefaultnoexcept

Default constructor.

Member Function Documentation

◆ hostnameAsText()

virtual const char * toy::network::Endpoint::hostnameAsText ( ) const
nodiscardpure virtualnoexcept

Returns the hostname as a C string.

Returns
Null-terminated hostname, or empty string if none set. Valid until the endpoint is modified or destroyed.

◆ isLocalHost()

virtual bool toy::network::Endpoint::isLocalHost ( ) const
nodiscardpure virtualnoexcept

Returns whether the endpoint represents the local host.

Returns
true if local host, false otherwise.

◆ port()

uint16_t toy::network::Endpoint::port ( ) const
nodiscardconstexprnoexcept

Returns the port number.

Returns
The port in host byte order.

◆ setHostname()

virtual bool toy::network::Endpoint::setHostname ( const char * name)
pure virtualnoexcept

Sets the hostname; resolution is implementation-defined.

Parameters
nameNull-terminated hostname string.
Precondition
name != nullptr.
Postcondition
On success, hostnameAsText() returns a string equal to name and the object is in a valid state.
Returns
true on success; false on invalid input or resolution failure. Caller should check before using hostnameAsText().

◆ setLocalHost()

virtual void toy::network::Endpoint::setLocalHost ( )
pure virtualnoexcept

Sets the endpoint to the local host.

◆ setPort()

void toy::network::Endpoint::setPort ( uint16_t port)
constexprnoexcept

Sets the port number.

Parameters
portPort in host byte order.

Member Data Documentation

◆ _port

uint16_t toy::network::Endpoint::_port = 0
private

Port in host byte order.


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