Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::unified::i_transport Interface Referenceabstract

Core interface for data transport abstraction. More...

#include <i_transport.h>

Inheritance diagram for kcenon::network::unified::i_transport:
Inheritance graph
Collaboration diagram for kcenon::network::unified::i_transport:
Collaboration graph

Public Member Functions

virtual ~i_transport ()=default
 Virtual destructor for proper cleanup of derived classes.
 
 i_transport (const i_transport &)=delete
 
i_transportoperator= (const i_transport &)=delete
 
 i_transport (i_transport &&)=default
 
i_transportoperator= (i_transport &&)=default
 
virtual auto send (std::span< const std::byte > data) -> VoidResult=0
 Sends raw data to the remote endpoint.
 
virtual auto send (std::vector< uint8_t > &&data) -> VoidResult=0
 Sends data from a uint8_t vector.
 
virtual auto is_connected () const noexcept -> bool=0
 Checks if the transport is currently connected.
 
virtual auto id () const noexcept -> std::string_view=0
 Gets the unique identifier for this transport/connection.
 
virtual auto remote_endpoint () const noexcept -> endpoint_info=0
 Gets the remote endpoint information.
 
virtual auto local_endpoint () const noexcept -> endpoint_info=0
 Gets the local endpoint information.
 

Protected Member Functions

 i_transport ()=default
 Default constructor (only for derived classes)
 

Detailed Description

Core interface for data transport abstraction.

This interface defines the fundamental operations for sending and receiving data across any network transport. It serves as the base abstraction that all protocol-specific implementations share.

Design Philosophy

The i_transport interface embodies Kent Beck's "Fewest Elements" rule by providing a minimal, protocol-agnostic API for data transfer. Protocol- specific details are handled by factory functions, not interface variations.

Supported Operations

  • Send: Transmit raw bytes to the remote endpoint
  • State Query: Check connection status
  • Endpoint Info: Get remote endpoint information

Thread Safety

All public methods must be thread-safe. Implementations should use appropriate synchronization for internal state.

Usage Example

// Works with any transport implementation
void send_message(i_transport& transport, std::span<const std::byte> data) {
if (!transport.is_connected()) {
return; // Not connected
}
auto result = transport.send(data);
if (!result) {
// Handle error
std::cerr << "Send failed: " << result.error().message << std::endl;
}
}
Core interface for data transport abstraction.
Definition i_transport.h:73
virtual auto send(std::span< const std::byte > data) -> VoidResult=0
Sends raw data to the remote endpoint.
virtual auto is_connected() const noexcept -> bool=0
Checks if the transport is currently connected.
See also
i_connection - Active connection (client-side or accepted)
i_listener - Passive listener (server-side)

Definition at line 73 of file i_transport.h.

Constructor & Destructor Documentation

◆ ~i_transport()

virtual kcenon::network::unified::i_transport::~i_transport ( )
virtualdefault

Virtual destructor for proper cleanup of derived classes.

◆ i_transport() [1/3]

kcenon::network::unified::i_transport::i_transport ( const i_transport & )
delete

◆ i_transport() [2/3]

kcenon::network::unified::i_transport::i_transport ( i_transport && )
default

◆ i_transport() [3/3]

kcenon::network::unified::i_transport::i_transport ( )
protecteddefault

Default constructor (only for derived classes)

Member Function Documentation

◆ id()

virtual auto kcenon::network::unified::i_transport::id ( ) const -> std::string_view
nodiscardpure virtualnoexcept

Gets the unique identifier for this transport/connection.

Returns
A string view of the transport ID

The ID is unique within the application and remains constant for the lifetime of the transport instance.

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.

◆ is_connected()

virtual auto kcenon::network::unified::i_transport::is_connected ( ) const -> bool
nodiscardpure virtualnoexcept

Checks if the transport is currently connected.

Returns
true if connected and ready to send/receive, false otherwise

Thread Safety

Thread-safe. Uses atomic operations internally.

Note

A false return may indicate:

  • Connection not yet established
  • Connection closed by remote peer
  • Connection closed locally
  • Network error occurred

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.

◆ local_endpoint()

virtual auto kcenon::network::unified::i_transport::local_endpoint ( ) const -> endpoint_info
nodiscardpure virtualnoexcept

Gets the local endpoint information.

Returns
endpoint_info of the local side

Returns valid information only when connected/listening. Returns empty endpoint_info if not bound.

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.

◆ operator=() [1/2]

i_transport & kcenon::network::unified::i_transport::operator= ( const i_transport & )
delete

◆ operator=() [2/2]

i_transport & kcenon::network::unified::i_transport::operator= ( i_transport && )
default

◆ remote_endpoint()

virtual auto kcenon::network::unified::i_transport::remote_endpoint ( ) const -> endpoint_info
nodiscardpure virtualnoexcept

Gets the remote endpoint information.

Returns
endpoint_info of the remote peer

Returns valid information only when connected. Returns empty endpoint_info if not connected.

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.

◆ send() [1/2]

virtual auto kcenon::network::unified::i_transport::send ( std::span< const std::byte > data) -> VoidResult
nodiscardpure virtual

Sends raw data to the remote endpoint.

Parameters
dataThe data to send as a span of bytes
Returns
VoidResult indicating success or failure

Error Conditions

  • Returns error if not connected
  • Returns error if send operation fails
  • Returns error if data size exceeds protocol limits

Thread Safety

Thread-safe. Multiple sends may be queued internally.

Performance Note

Data is typically copied to an internal send buffer. For zero-copy sends, see protocol-specific implementations.

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.

◆ send() [2/2]

virtual auto kcenon::network::unified::i_transport::send ( std::vector< uint8_t > && data) -> VoidResult
nodiscardpure virtual

Sends data from a uint8_t vector.

Parameters
dataThe data to send as a vector of uint8_t
Returns
VoidResult indicating success or failure

Convenience overload for compatibility with existing code using std::vector<uint8_t>.

Implemented in kcenon::network::unified::adapters::quic_connection_adapter, kcenon::network::unified::adapters::tcp_connection_adapter, kcenon::network::unified::adapters::udp_connection_adapter, and kcenon::network::unified::adapters::ws_connection_adapter.


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