qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::event::timer Struct Reference

Event for handling time-based operations (timers and timeouts). More...

#include <timer.h>

Inheritance diagram for qb::io::async::event::timer:
Collaboration diagram for qb::io::async::event::timer:

Public Types

using base_t = base<ev::timer>
 Base type alias for base<ev::timer>.
Public Types inherited from qb::io::async::event::base< ev::timer >
using ev_t
 Alias for the underlying libev event watcher type.

Public Member Functions

 timer (ev::loop_ref loop)
 Constructor.
Public Member Functions inherited from qb::io::async::event::base< ev::timer >
 base (ev::loop_ref loop)
 Constructor.

Additional Inherited Members

Public Attributes inherited from qb::io::async::event::base< ev::timer >
IRegisteredKernelEvent_interface
 Pointer to the kernel event interface responsible for handling this event.
int _revents
 Stores the event flags (e.g., EV_READ, EV_WRITE) received from libev when the event triggers.

Detailed Description

Event for handling time-based operations (timers and timeouts).

This event extends qb::io::async::event::base<ev::timer> and thus wraps an ev::timer watcher from libev. It provides the ability to schedule callbacks after a certain delay or at regular intervals. It's the foundation for qb::io::async::with_timeout and qb::io::async::callback.

When a handler receives this event, it means the timer has expired. The underlying ev::timer can be configured for one-shot or repeating behavior.

Usage Example (within a class using with_timeout which manages a timer event internally):

class MyTimeoutHandler : public qb::io::async::with_timeout<MyTimeoutHandler> {
public:
MyTimeoutHandler(double timeout_seconds) : with_timeout(timeout_seconds) {}
void onActivity() {
updateTimeout(); // Reset the timer on activity
}
void on(qb::io::async::event::timer &&event) { // Or const timer& if not modifying it
LOG_INFO("Timeout occurred!");
// Handle the timeout, e.g., close a connection, retry an operation.
// If it was a one-shot timer, it stops automatically.
// For periodic, call updateTimeout() or set() then start() on the event watcher to re-arm.
}
};
CRTP base class that adds timeout functionality to derived asynchronous components.
Definition io.h:96
void updateTimeout() noexcept
Updates the last activity timestamp to the current event loop time.
Definition io.h:120
#define LOG_INFO(X)
Info-level log macro (no-op if QB_STDOUT_LOG is not defined)
Definition io.h:229

Constructor & Destructor Documentation

◆ timer()

qb::io::async::event::timer::timer ( ev::loop_ref loop)
inlineexplicit

Constructor.

Parameters
loopReference to the libev event loop (ev::loop_ref) this timer watcher will be associated with.