Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::server::TimerManager Class Reference

Manages timers for connection timeouts. More...

#include <TimerManager.hpp>

Classes

struct  LiveTimer
 

Public Member Functions

 TimerManager ()
 Constructs a TimerManager.
 
uint64_t add_timer (int fd, std::chrono::milliseconds timeout)
 Adds a timer for a given file descriptor.
 
void cancel_timer (uint64_t timer_id)
 Cancels a timer by ID.
 
int get_next_timeout ()
 Gets the time remaining until the next timeout.
 
void handle_expired_timers (std::function< void(int)> on_timeout)
 Processes all expired timers.
 
size_t pending_entries ()
 
size_t live_timers ()
 Timers that have been added and neither fired nor been cancelled.
 

Private Member Functions

void drop_cancelled_front_locked ()
 
void compact_if_needed_locked ()
 

Private Attributes

std::priority_queue< TimerEvent, std::vector< TimerEvent >, std::greater< TimerEvent > > timers_
 
std::unordered_map< uint64_t, LiveTimer > live_
 
uint64_t next_timer_id_ {1}
 
std::mutex mutex_
 

Detailed Description

Manages timers for connection timeouts.

Constructor & Destructor Documentation

◆ TimerManager()

orbit::server::TimerManager::TimerManager ( )

Constructs a TimerManager.

Member Function Documentation

◆ add_timer()

uint64_t orbit::server::TimerManager::add_timer ( int  fd,
std::chrono::milliseconds  timeout 
)

Adds a timer for a given file descriptor.

Parameters
fdThe file descriptor.
timeoutThe timeout duration.
Returns
The timer ID.

◆ cancel_timer()

void orbit::server::TimerManager::cancel_timer ( uint64_t  timer_id)

Cancels a timer by ID.

Parameters
timer_idThe timer ID.

◆ compact_if_needed_locked()

void orbit::server::TimerManager::compact_if_needed_locked ( )
private

◆ drop_cancelled_front_locked()

void orbit::server::TimerManager::drop_cancelled_front_locked ( )
private

◆ get_next_timeout()

int orbit::server::TimerManager::get_next_timeout ( )

Gets the time remaining until the next timeout.

Returns
Milliseconds until the next timeout, or -1 if none.

◆ handle_expired_timers()

void orbit::server::TimerManager::handle_expired_timers ( std::function< void(int)>  on_timeout)

Processes all expired timers.

Parameters
on_timeoutCallback invoked for each expired timer with its file descriptor.

◆ live_timers()

size_t orbit::server::TimerManager::live_timers ( )

Timers that have been added and neither fired nor been cancelled.

◆ pending_entries()

size_t orbit::server::TimerManager::pending_entries ( )

Entries held in the deadline queue, live or cancelled. Bounded by a small multiple of the live timers however often they are re-armed; exposed for tests and diagnostics.

Member Data Documentation

◆ live_

std::unordered_map<uint64_t, LiveTimer> orbit::server::TimerManager::live_
private

◆ mutex_

std::mutex orbit::server::TimerManager::mutex_
private

◆ next_timer_id_

uint64_t orbit::server::TimerManager::next_timer_id_ {1}
private

◆ timers_

std::priority_queue<TimerEvent, std::vector<TimerEvent>, std::greater<TimerEvent> > orbit::server::TimerManager::timers_
private

The documentation for this class was generated from the following file: