algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::runner::SignalStop Class Reference

Routes SIGINT and SIGTERM to a StopSource as a quiesce, and ignores SIGHUP where it exists (POSIX); only when install is called. More...

#include <algotradelib/src/runner/signal_stop.hpp>

Static Public Member Functions

static void install (StopSource &source) noexcept
 Installs the handlers: SIGINT and SIGTERM request a quiesce on source; SIGHUP, where it exists, is ignored.
static void uninstall () noexcept
 Restores the default disposition of SIGINT, SIGTERM and (POSIX) SIGHUP, and forgets the source.
static StopSource * installed () noexcept
 Returns the installed source.

Detailed Description

Routes SIGINT and SIGTERM to a StopSource as a quiesce, and ignores SIGHUP where it exists (POSIX); only when install is called.

Both signals mean StopIntent::QUIESCE, never a flatten, since they arrive for routine reasons (a reboot, a deploy, Ctrl+C). SIGHUP is ignored so a dropped SSH session does not stop a process holding positions; Windows has no SIGHUP.

Situation What arrives
tmux send-keys -t sess:0.0 C-c SIGINT to the foreground process
kill -TERM <pid> SIGTERM
host reboot under systemd SIGTERM, then SIGKILL after TimeoutStopSec
docker stop SIGTERM, then SIGKILL after ten seconds
Warning
A supervisor's grace period must exceed one loop iteration plus one request timeout. Otherwise its SIGKILL can kill the process mid-request, leaving an order of unknown outcome that must be reconciled from the broker's order list before trading again.

Definition at line 30 of file signal_stop.hpp.

Member Function Documentation

◆ install()

void algotradelib::runner::SignalStop::install ( StopSource & source)
inlinestaticnoexcept

Installs the handlers: SIGINT and SIGTERM request a quiesce on source; SIGHUP, where it exists, is ignored.

Only one source can be installed at a time.

Parameters
sourceThe stop source; it must outlive the handlers (until uninstall).

Definition at line 40 of file signal_stop.hpp.

◆ installed()

StopSource * algotradelib::runner::SignalStop::installed ( )
inlinestaticnoexcept

Returns the installed source.

Returns
The source, or nullptr if none is installed.

Definition at line 64 of file signal_stop.hpp.

◆ uninstall()

void algotradelib::runner::SignalStop::uninstall ( )
inlinestaticnoexcept

Restores the default disposition of SIGINT, SIGTERM and (POSIX) SIGHUP, and forgets the source.

Definition at line 51 of file signal_stop.hpp.


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