CRTP base class for managing asynchronous input operations with protocol processing.
More...
|
| input ()=default |
| Default constructor.
|
| input (IProtocol *protocol) noexcept |
| Constructor with an initial protocol instance.
|
| input (input const &)=delete |
| Deleted copy constructor to prevent unintended copying of I/O state and resources.
|
| ~input () noexcept |
| Destructor.
|
template<typename _Protocol, typename... _Args> |
_Protocol * | switch_protocol (_Args &&...args) |
| Switches to a new protocol for processing input, taking ownership of the new protocol.
|
void | clear_protocols () |
| Clears all owned protocol instances.
|
IProtocol * | protocol () |
| Gets a pointer to the current active protocol instance.
|
void | start () noexcept |
| Starts asynchronous input operations.
|
void | ready_to_read () noexcept |
| Ensures the I/O watcher is listening for read events (EV_READ).
|
void | disconnect (int reason=1) |
| Initiates a graceful disconnection of the input component.
|
template<typename _Derived>
class qb::io::async::input< _Derived >
CRTP base class for managing asynchronous input operations with protocol processing.
This template class provides functionality for asynchronous input. It uses an event::io watcher to monitor a file descriptor for read readiness. Data read from the transport (provided by _Derived::transport()) is processed using an AProtocol instance.
- Template Parameters
-
_Derived | The derived class type (CRTP pattern) that provides the transport (e.g., a socket wrapper) and handles protocol messages and I/O events. |
template<typename _Derived>
template<typename _Protocol, typename... _Args>
Switches to a new protocol for processing input, taking ownership of the new protocol.
- Template Parameters
-
_Protocol | The concrete AProtocol type to instantiate. |
_Args | Argument types for the _Protocol constructor. |
- Parameters
-
args | Arguments to forward to the _Protocol constructor. |
- Returns
- Pointer to the newly created and activated protocol instance if successful (protocol's ok() returns true), otherwise nullptr (and the created protocol instance is deleted).
The new protocol instance is added to an internal list and will be cleaned up by this input component's destructor. The current active protocol is set to this new instance. Previous protocols in the list are not deleted by this call.
template<typename _Derived>
Disposes of resources and finalizes disconnection for the input 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 the _is_disposed flag. If _Derived implements on(event::disconnected&), this method is called with the stored _reason. If _Derived::has_server is true (typically for server-side sessions), it notifies the server of the disconnection. Otherwise, if _Derived implements on(event::dispose&), that method is called as a final cleanup hook. The base class (async::base) destructor will handle unregistering the event::io watcher.