qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::tcp::client< _Derived, _Transport, _Server > Class Template Reference

Server-associated asynchronous TCP client. More...

#include <client.h>

Inheritance diagram for qb::io::async::tcp::client< _Derived, _Transport, _Server >:
Collaboration diagram for qb::io::async::tcp::client< _Derived, _Transport, _Server >:

Public Types

using base_io_t = io<_Derived>
 Base I/O type.
using transport_io_type
 Transport I/O type.
using IOServer = _Server
 Type alias for the server type.
Public Types inherited from qb::io::async::io< _Derived >
typedef io< _Derived > base_io_t
 Base I/O type alias for CRTP.

Public Member Functions

 client ()=delete
 Default constructor (deleted)
 client (_Server &server)
 Constructor with server reference.
 ~client ()=default
 Destructor.
_Server & server ()
 Get the associated server.
_Server & server () const
 Get the associated server (const version)
uuid const & id () const noexcept
 Get the client's unique identifier.
auto shared () const
 Get the client as a shared pointer.
auto ip () const
 Get the client's IP address.
auto port () const
 Get the client's port.
template<typename... _Args>
auto & publish (_Args &&...args) noexcept
 < Import the transport method from the transport
Public Member Functions inherited from qb::io::async::io< _Derived >
 io ()=default
 Default constructor.
 io (IProtocol *protocol) noexcept
 Constructor with an initial protocol instance.
 io (io const &)=delete
 Deleted copy constructor.
 ~io () noexcept
 Destructor.
template<typename _Protocol, typename... _Args>
_Protocol * switch_protocol (_Args &&...args)
 Switches to a new protocol for I/O processing, taking ownership.
void clear_protocols ()
 Clears all owned protocol instances.
IProtocolprotocol ()
 Gets a pointer to the current active protocol instance.
void start () noexcept
 Starts bidirectional asynchronous I/O operations.
void ready_to_read () noexcept
 Ensures the I/O watcher is listening for read events (EV_READ).
void ready_to_write () noexcept
 Ensures the I/O watcher is listening for write events (EV_WRITE).
void close_after_deliver () const noexcept
 Requests connection closure after all pending output data is delivered.
template<typename... _Args>
auto & publish (_Args &&...args) noexcept
 Publishes data to the output buffer and ensures write readiness.
template<typename T>
auto & operator<< (T &&data)
 Stream operator for publishing data.
void disconnect (int reason=1)
 Initiates a graceful disconnection.

Static Public Attributes

static constexpr const bool has_server
 Flag indicating server association.
Static Public Attributes inherited from qb::io::async::io< _Derived >
static constexpr const bool has_server = false
 Indicates this component is not inherently a server.

Protected Attributes

const uuid _uuid
 < Import the publish method from the base class
_Server & _server
 Reference to the associated server.
Protected Attributes inherited from qb::io::async::base< io< _Derived >, event::io >
event::io & _async_event
 Reference to the registered libev-based event watcher.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::io< _Derived >
void dispose ()
 Disposes of resources and finalizes disconnection for the I/O component.
Protected Member Functions inherited from qb::io::async::base< io< _Derived >, event::io >
 base ()
 Constructor that registers the event watcher with the current listener.
 ~base ()
 Destructor that unregisters the event watcher.

Detailed Description

template<typename _Derived, typename _Transport, typename _Server = void>
class qb::io::async::tcp::client< _Derived, _Transport, _Server >

Server-associated asynchronous TCP client.

Standalone asynchronous TCP client specialization without server association.

This specialization of the client template is used for clients that are associated with a server, typically created when a connection is accepted. It maintains a reference to the server and has a unique identifier.

Template Parameters
_DerivedThe derived class type (CRTP pattern)
_TransportThe transport class type
_ServerThe server class type

This specialization of the client template is used for standalone clients that are not associated with any server, typically for outgoing connections. It includes all the basic functionality of the generic client but without server-specific features.

Template Parameters
_DerivedThe derived class type (CRTP pattern)
_TransportThe transport layer implementation type

Member Typedef Documentation

◆ transport_io_type

template<typename _Derived, typename _Transport, typename _Server = void>
using qb::io::async::tcp::client< _Derived, _Transport, _Server >::transport_io_type
Initial value:
typename _Transport::transport_io_type

Transport I/O type.

Constructor & Destructor Documentation

◆ client()

template<typename _Derived, typename _Transport, typename _Server = void>
qb::io::async::tcp::client< _Derived, _Transport, _Server >::client ( _Server & server)
inlineexplicit

Constructor with server reference.

Creates a new client associated with the given server. If the derived class defines a Protocol type that is not void, an instance of that protocol is created and attached to the client.

Parameters
serverReference to the associated server

Member Function Documentation

◆ server() [1/2]

template<typename _Derived, typename _Transport, typename _Server = void>
_Server & qb::io::async::tcp::client< _Derived, _Transport, _Server >::server ( )
inline

Get the associated server.

Returns
Reference to the associated server

◆ server() [2/2]

template<typename _Derived, typename _Transport, typename _Server = void>
_Server & qb::io::async::tcp::client< _Derived, _Transport, _Server >::server ( ) const
inline

Get the associated server (const version)

Returns
Const reference to the associated server

◆ id()

template<typename _Derived, typename _Transport, typename _Server = void>
uuid const & qb::io::async::tcp::client< _Derived, _Transport, _Server >::id ( ) const
inlinenoexcept

Get the client's unique identifier.

Returns
Const reference to the UUID

◆ shared()

template<typename _Derived, typename _Transport, typename _Server = void>
auto qb::io::async::tcp::client< _Derived, _Transport, _Server >::shared ( ) const
inline

Get the client as a shared pointer.

Returns
Shared pointer to the client

◆ ip()

template<typename _Derived, typename _Transport, typename _Server = void>
auto qb::io::async::tcp::client< _Derived, _Transport, _Server >::ip ( ) const
inline

Get the client's IP address.

Returns
IP address

◆ port()

template<typename _Derived, typename _Transport, typename _Server = void>
auto qb::io::async::tcp::client< _Derived, _Transport, _Server >::port ( ) const
inline

Get the client's port.

Returns
Port

Member Data Documentation

◆ _uuid

template<typename _Derived, typename _Transport, typename _Server = void>
const uuid qb::io::async::tcp::client< _Derived, _Transport, _Server >::_uuid
protected

< Import the publish method from the base class

Unique identifier for this client

◆ has_server

template<typename _Derived, typename _Transport, typename _Server = void>
const bool qb::io::async::tcp::client< _Derived, _Transport, _Server >::has_server
staticconstexpr
Initial value:
=
true

Flag indicating server association.