Abstract base for a network endpoint (hostname and port).
More...
|
| 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.
|
|
| constexpr | Endpoint () noexcept=default |
| | Default constructor.
|
|
| uint16_t | _port = 0 |
| | Port in host byte order.
|
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
(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
◆ ~Endpoint()
| toy::network::Endpoint::~Endpoint |
( |
| ) |
|
|
virtualdefaultnoexcept |
◆ Endpoint()
| toy::network::Endpoint::Endpoint |
( |
| ) |
|
|
constexprprotecteddefaultnoexcept |
◆ 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
-
| name | Null-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
-
| port | Port in host byte order. |
◆ _port
| uint16_t toy::network::Endpoint::_port = 0 |
|
private |
The documentation for this class was generated from the following files: