qb
2.0.0.0
C++17 Actor Framework
|
CRTP base class for managing bidirectional asynchronous I/O operations with protocol processing. More...
#include <io.h>
Public Types | |
typedef io< _Derived > | base_io_t |
Base I/O type alias for CRTP. |
Public Member Functions | |
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. | |
IProtocol * | protocol () |
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 = false |
Indicates this component is not inherently a server. |
Protected Member Functions | |
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. |
Additional Inherited Members | |
Protected Attributes inherited from qb::io::async::base< io< _Derived >, event::io > | |
event::io & | _async_event |
Reference to the registered libev-based event watcher. |
CRTP base class for managing bidirectional asynchronous I/O operations with protocol processing.
This template class combines input and output capabilities. It uses a single event::io watcher to monitor a file descriptor for both read and write readiness. Data is read into an input buffer and processed by a protocol, while outgoing data is buffered and written to the transport when ready.
_Derived | The derived class type (CRTP pattern) that provides the transport and handles protocol messages and I/O events. |
|
default |
Default constructor.
Initializes the I/O component without a specific protocol.
|
inlinenoexcept |
Constructor with an initial protocol instance.
protocol | Pointer to an existing protocol instance. This io component will use it and take ownership by adding it to its internal list of protocols. |
|
inlinenoexcept |
Destructor.
Cleans up owned protocols via clear_protocols(). Base class handles watcher unregistration.
|
inline |
Switches to a new protocol for I/O processing, taking ownership.
_Protocol | The concrete AProtocol type to instantiate. |
_Args | Argument types for the _Protocol constructor. |
args | Arguments to forward to the _Protocol constructor. |
|
inline |
Clears all owned protocol instances.
Deletes protocols in _protocol_list and resets _protocol pointer to nullptr.
|
inline |
Gets a pointer to the current active protocol instance.
|
inlinenoexcept |
Starts bidirectional asynchronous I/O operations.
Sets the transport to non-blocking and starts listening for read events (EV_READ). Resets disconnection reason.
|
inlinenoexcept |
Ensures the I/O watcher is listening for read events (EV_READ).
Modifies the event watcher flags to include EV_READ if not already set.
|
inlinenoexcept |
Ensures the I/O watcher is listening for write events (EV_WRITE).
Modifies the event watcher flags to include EV_WRITE if not already set.
|
inlinenoexcept |
|
inlinenoexcept |
Publishes data to the output buffer and ensures write readiness.
_Args | Types of data to publish. |
args | Data arguments to stream into _Derived::out(). |
|
inline |
Stream operator for publishing data.
T | Type of data. |
data | Data to publish. |
|
inline |
Initiates a graceful disconnection.
reason | Optional reason code for disconnection. |
Triggers the dispose() mechanism via an EV_UNDEF event sent to the event loop.
|
inlineprotected |
Disposes of resources and finalizes disconnection for the I/O component.
Ensures cleanup happens only once (via _is_disposed). Triggers _Derived::on(event::disconnected&) (with _reason) or _Derived::on(event::dispose&) based on derived class capabilities and server association. This is the primary cleanup point before the async::base destructor unregisters the watcher.