Module signal_hook::iterator [−][src]
An iterator over incoming signals.
This provides a higher abstraction over the signals, providing a structure
(Signals
) able to iterate over the incoming signals.
In the future, there will be support for asynchronous frameworks (mio
, futures
).
Depending on the features the crate is compiled with, integration with mio
and futures
is
provided. For now it is mostly usable when there's a dedicated signal handling thread.
Examples
extern crate libc; extern crate signal_hook; use std::io::Error; use signal_hook::iterator::Signals; fn main() -> Result<(), Error> { let signals = Signals::new(&[ libc::SIGHUP, libc::SIGTERM, libc::SIGINT, libc::SIGQUIT, ])?; 'outer: loop { // Pick up signals that arrived since last time for signal in signals.pending() { match signal as libc::c_int { libc::SIGHUP => { // Reload configuration // Reopen the log file } libc::SIGTERM | libc::SIGINT | libc::SIGQUIT => break 'outer, libc::SIGUSR1 => return Ok(()), _ => unreachable!(), } } // Do some bit of work ‒ something with upper limit on waiting, so we don't block // forever with a SIGTERM already waiting. } println!("Terminating. Bye bye"); Ok(()) }
Structs
Forever |
The infinite iterator of signals. |
Pending |
The iterator of one batch of signals. |
Signals |
The main structure of the module, representing interest in some signals. |