FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::venues::CountdownSwitch Class Reference

Refresh clock for a countdown dead man's switch. More...

#include <fastmm/venues/dead_mans_switch.hpp>

Public Member Functions

 CountdownSwitch ()=default
 
 CountdownSwitch (std::int64_t window_ms, std::int64_t refresh_numerator=1, std::int64_t refresh_denominator=3) noexcept
 window_ms is what the venue is told; 0 disables the switch.
 
bool enabled () const noexcept
 
std::int64_t window_ms () const noexcept
 
std::int64_t refresh_period_ns () const noexcept
 
bool due (std::int64_t now_ns) const noexcept
 True when a refresh has to go out now.
 
void attempted (std::int64_t now_ns) noexcept
 A refresh was written to the venue.
 
void armed (std::int64_t now_ns) noexcept
 The venue accepted the refresh: the countdown is running from here.
 
bool expired (std::int64_t now_ns) const noexcept
 The window has run out since the last refresh the venue confirmed: it has cancelled our orders, or is about to.
 
bool ever_armed () const noexcept
 
void disarm () noexcept
 The session ended, or the kill already fired: the next due() starts from scratch.
 

Static Public Attributes

static constexpr std::int64_t kMinPeriodNs = 500'000'000
 A refresh sent more often than this is wasted rate limit whatever the window is.
 

Detailed Description

Refresh clock for a countdown dead man's switch.

Holds no venue detail: the connector asks due() from its housekeeping timer, sends its own request, reports attempted(), and reports armed() when the venue answers.

The two clocks are separate on purpose. attempted paces retries, so a refresh that never reaches the venue is tried again next period instead of every tick. armed is what the window is measured from, so a request that goes out and comes back an error does not pretend the countdown was pushed out. If this process is what broke, neither clock moves, the venue's countdown runs out and it cancels — which is the point.

Constructor & Destructor Documentation

◆ CountdownSwitch() [1/2]

fastmm::venues::CountdownSwitch::CountdownSwitch ( )
default

◆ CountdownSwitch() [2/2]

fastmm::venues::CountdownSwitch::CountdownSwitch ( std::int64_t  window_ms,
std::int64_t  refresh_numerator = 1,
std::int64_t  refresh_denominator = 3 
)
inlineexplicitnoexcept

window_ms is what the venue is told; 0 disables the switch.

refresh_numerator / refresh_denominator is the fraction of the window at which the refresh goes out (1/3 by default: two refreshes may be lost before the venue acts).

Member Function Documentation

◆ enabled()

bool fastmm::venues::CountdownSwitch::enabled ( ) const
inlinenoexcept

◆ window_ms()

std::int64_t fastmm::venues::CountdownSwitch::window_ms ( ) const
inlinenoexcept

◆ refresh_period_ns()

std::int64_t fastmm::venues::CountdownSwitch::refresh_period_ns ( ) const
inlinenoexcept

◆ due()

bool fastmm::venues::CountdownSwitch::due ( std::int64_t  now_ns) const
inlinenoexcept

True when a refresh has to go out now.

Also true for the first arm, and true again a refresh period after an attempt that the venue did not confirm, so a failure is retried.

◆ attempted()

void fastmm::venues::CountdownSwitch::attempted ( std::int64_t  now_ns)
inlinenoexcept

A refresh was written to the venue.

Only stops due() from firing again immediately; it does not mean the countdown is running.

◆ armed()

void fastmm::venues::CountdownSwitch::armed ( std::int64_t  now_ns)
inlinenoexcept

The venue accepted the refresh: the countdown is running from here.

◆ expired()

bool fastmm::venues::CountdownSwitch::expired ( std::int64_t  now_ns) const
inlinenoexcept

The window has run out since the last refresh the venue confirmed: it has cancelled our orders, or is about to.

This process is still alive (it is asking), so something between it and the venue is broken. It must not simply put back the quotes the venue just pulled — that is a quoter racing a kill switch it cannot see. A switch that was up and has lapsed is a kill. One that was never up is not: the connector is loud about those failures instead, because a venue that refuses the request outright must not stop the session dead.

◆ ever_armed()

bool fastmm::venues::CountdownSwitch::ever_armed ( ) const
inlinenoexcept

◆ disarm()

void fastmm::venues::CountdownSwitch::disarm ( )
inlinenoexcept

The session ended, or the kill already fired: the next due() starts from scratch.

Member Data Documentation

◆ kMinPeriodNs

constexpr std::int64_t fastmm::venues::CountdownSwitch::kMinPeriodNs = 500'000'000
staticconstexpr

A refresh sent more often than this is wasted rate limit whatever the window is.