Skip to main content

Module stop

Module stop 

Source
Expand description

Stop fan-in for a daemon host (issue #375): one StopSource that several inputs may trigger (an OS stop signal, the parent closing this process’s stdin, or the program itself), and StopTokens that the host’s threads wait on. The first cause wins and later triggers are ignored.

Signals: stop_on_signals installs handlers for SIGINT and SIGTERM on Unix and the console control handler on Windows (Ctrl+C, Ctrl+Break, close). The handler only records the event in a static atomic (the one thing a signal handler may do here); a watcher thread turns that into a trigger, polling every 50 ms, and exits once the source is stopped. Other platforms return Unsupported.

Stdin: stop_on_stdin_close triggers the source when stdin reaches end of file (see crate::private::watch_stdin_eof).

Structs§

ParentFence
A parent-process identity fence: the parent’s pid pinned to its OS start marker, so a different process that later reuses the pid is never mistaken for the parent. A child whose parent cannot hold its stdin open (or must not rely on it alone) captures this at start and stops itself when parent_gone turns true; conversely a reused pid alone can neither keep the child alive nor claim to be its parent.
StopSource
The trigger side. Clone it to give inputs their own handle; every clone triggers the same stop.
StopToken
The waiting side. Cheap to clone; it sees the stop that its source triggers.

Enums§

StopCause
Why the stop was triggered. The first trigger’s cause is the one reported.

Functions§

stop_on_signals
Install OS stop-signal handlers that trigger source (see the module docs). The watcher thread ends when the source is stopped by any input.
stop_on_stdin_close
Trigger source when this process’s stdin reaches end of file.
stop_when_parent_gone
Trigger source with StopCause::ParentGone once fence’s parent is gone. Polls every poll (raised to at least 10 ms); the watcher thread ends when the source is stopped by any input.