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

CRTP base class that adds timeout functionality to derived asynchronous components. More...

#include <io.h>

Inheritance diagram for qb::io::async::with_timeout< _Derived >:
Collaboration diagram for qb::io::async::with_timeout< _Derived >:

Public Member Functions

 with_timeout (ev_tstamp timeout=3)
 Constructor that initializes the timeout.
void updateTimeout () noexcept
 Updates the last activity timestamp to the current event loop time.
void setTimeout (ev_tstamp timeout) noexcept
 Sets a new timeout value and restarts the timer.
auto getTimeout () const noexcept
 Gets the current configured timeout value.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::base< with_timeout< _Derived >, event::timer >
 base ()
 Constructor that registers the event watcher with the current listener.
 ~base ()
 Destructor that unregisters the event watcher.
Protected Attributes inherited from qb::io::async::base< with_timeout< _Derived >, event::timer >
event::timer & _async_event
 Reference to the registered libev-based event watcher.

Detailed Description

template<typename _Derived>
class qb::io::async::with_timeout< _Derived >

CRTP base class that adds timeout functionality to derived asynchronous components.

This template class extends qb::io::async::base by incorporating an event::timer. It allows the derived class to set a timeout, after which an on(event::timer&) method in the derived class is triggered if no activity (signaled by updateTimeout()) is detected.

Template Parameters
_DerivedThe derived class type (CRTP pattern) that will handle the timeout event.

Constructor & Destructor Documentation

◆ with_timeout()

template<typename _Derived>
qb::io::async::with_timeout< _Derived >::with_timeout ( ev_tstamp timeout = 3)
inlineexplicit

Constructor that initializes the timeout.

Parameters
timeoutInitial timeout value in seconds. A value of 0.0 or less disables the timeout initially. The timer is started if timeout is greater than 0.0.

Member Function Documentation

◆ updateTimeout()

template<typename _Derived>
void qb::io::async::with_timeout< _Derived >::updateTimeout ( )
inlinenoexcept

Updates the last activity timestamp to the current event loop time.

This method should be called by the derived class whenever an activity occurs that should reset the timeout countdown (e.g., receiving data, user input). It sets _last_activity to this->_async_event.loop.now().

◆ setTimeout()

template<typename _Derived>
void qb::io::async::with_timeout< _Derived >::setTimeout ( ev_tstamp timeout)
inlinenoexcept

Sets a new timeout value and restarts the timer.

Parameters
timeoutNew timeout value in seconds. If 0.0 or less, the timer is stopped (disabled). Otherwise, the timer is configured with the new timeout and started. The _last_activity timestamp is also updated to the current event loop time.

◆ getTimeout()

template<typename _Derived>
auto qb::io::async::with_timeout< _Derived >::getTimeout ( ) const
inlinenoexcept

Gets the current configured timeout value.

Returns
Current timeout value in seconds.