qb
2.0.0.0
C++17 Actor Framework
|
CRTP base class for managing asynchronous output operations. More...
#include <io.h>
Public Types | |
using | base_io_t = output<_Derived> |
Base I/O type alias for CRTP. |
Public Member Functions | |
output ()=default | |
Default constructor. | |
output (output const &)=delete | |
Deleted copy constructor to prevent unintended copying of I/O state and resources. | |
~output ()=default | |
Destructor. | |
void | start () noexcept |
Starts asynchronous output operations. | |
void | ready_to_write () noexcept |
Ensures the I/O watcher is listening for write events (EV_WRITE). | |
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, equivalent to publish(std::forward<T>(data)). | |
void | disconnect (int reason=1) |
Initiates a graceful disconnection of the output component. |
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 output component. | |
Protected Member Functions inherited from qb::io::async::base< output< _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< output< _Derived >, event::io > | |
event::io & | _async_event |
Reference to the registered libev-based event watcher. |
CRTP base class for managing asynchronous output operations.
This template class provides functionality for asynchronous output. It uses an event::io watcher to monitor a file descriptor for write readiness. Data to be sent is buffered and then written to the transport (provided by _Derived::transport()) when ready.
_Derived | The derived class type (CRTP pattern) that provides the transport and handles I/O events like eos (end of stream) or pending_write. |
|
default |
Destructor.
The base class destructor will handle unregistering the event::io watcher.
|
inlinenoexcept |
Starts asynchronous output operations.
Sets the underlying transport (obtained via _Derived::transport()) to non-blocking mode and starts the event::io watcher to listen for write events (EV_WRITE). Resets any previous disconnection reason (_reason = 0).
|
inlinenoexcept |
Ensures the I/O watcher is listening for write events (EV_WRITE).
If the internal event::io watcher (from the base class) is not currently set to listen for EV_WRITE, this method reconfigures it to include EV_WRITE in its watched events. This is often called implicitly by publish() or operator<< to signal that there is data ready to be written.
|
inlinenoexcept |
Publishes data to the output buffer and ensures write readiness.
_Args | Variadic template arguments for the data to be published. |
args | Data arguments to stream into _Derived::out() buffer (typically a qb::allocator::pipe<char>). |
Calls ready_to_write() to ensure the event loop is monitoring for write readiness, then streams all args into the output buffer provided by _Derived::out().
|
inline |
Stream operator for publishing data, equivalent to publish(std::forward<T>(data)).
T | Type of data to publish. |
data | Data to publish. |
|
inline |
Initiates a graceful disconnection of the output component.
reason | An optional integer code indicating the reason for disconnection. |
Sets an internal flag (_reason) and feeds an EV_UNDEF event to the listener. This typically causes the on(event::io&) handler to enter its error path, leading to the invocation of dispose() for cleanup.
|
inlineprotected |
Disposes of resources and finalizes disconnection for the output component.
This method is called internally when an I/O error occurs or when disconnect() is explicitly initiated. It ensures cleanup happens only once by checking _is_disposed. If _Derived implements on(event::disconnected&), this method is called with the stored _reason. If _Derived::has_server is true, it notifies the server. Otherwise, if _Derived implements on(event::dispose&), that method is called for final cleanup. The base class (async::base) destructor handles unregistering the event::io watcher.