Type Alias signal_hook::iterator::Signals
source · pub type Signals = SignalsInfo<SignalOnly>;
Expand description
A type alias for an iterator returning just the signal numbers.
This is the simplified version for most of the use cases. For advanced usages, the
SignalsInfo
with explicit Exfiltrator
type can be used.
Aliased Type§
struct Signals(/* private fields */);
Implementations§
source§impl<E: Exfiltrator> SignalsInfo<E>
impl<E: Exfiltrator> SignalsInfo<E>
sourcepub fn new<I, S>(signals: I) -> Result<Self, Error>where
I: IntoIterator<Item = S>,
S: Borrow<c_int>,
E: Default,
pub fn new<I, S>(signals: I) -> Result<Self, Error>where I: IntoIterator<Item = S>, S: Borrow<c_int>, E: Default,
Creates the Signals
structure.
This registers all the signals listed. The same restrictions (panics, errors) apply as
for the Handle::add_signal
method.
sourcepub fn with_exfiltrator<I, S>(signals: I, exfiltrator: E) -> Result<Self, Error>where
I: IntoIterator<Item = S>,
S: Borrow<c_int>,
pub fn with_exfiltrator<I, S>(signals: I, exfiltrator: E) -> Result<Self, Error>where I: IntoIterator<Item = S>, S: Borrow<c_int>,
An advanced constructor with explicit Exfiltrator
.
sourcepub fn add_signal(&self, signal: c_int) -> Result<(), Error>
pub fn add_signal(&self, signal: c_int) -> Result<(), Error>
Registers another signal to the set watched by this Signals
instance.
The same restrictions (panics, errors) apply as for the Handle::add_signal
method.
sourcepub fn pending(&mut self) -> Pending<E> ⓘ
pub fn pending(&mut self) -> Pending<E> ⓘ
Returns an iterator of already received signals.
This returns an iterator over all the signal numbers of the signals received since last
time they were read (out of the set registered by this Signals
instance). Note that they
are returned in arbitrary order and a signal instance may returned only once even if it was
received multiple times.
This method returns immediately (does not block) and may produce an empty iterator if there are no signals ready.
sourcepub fn wait(&mut self) -> Pending<E> ⓘ
pub fn wait(&mut self) -> Pending<E> ⓘ
Waits for some signals to be available and returns an iterator.
This is similar to pending
. If there are no signals available, it
tries to wait for some to arrive. However, due to implementation details, this still can
produce an empty iterator.
This can block for arbitrary long time. If the Handle::close
method is used in
another thread this method will return immediately.
Note that the blocking is done in this method, not in the iterator.
sourcepub fn forever(&mut self) -> Forever<'_, E> ⓘ
pub fn forever(&mut self) -> Forever<'_, E> ⓘ
Get an infinite iterator over arriving signals.
The iterator’s next()
blocks as necessary to wait for signals to arrive. This is adequate
if you want to designate a thread solely to handling signals. If multiple signals come at
the same time (between two values produced by the iterator), they will be returned in
arbitrary order. Multiple instances of the same signal may be collated.
This is also the iterator returned by IntoIterator
implementation on &mut Signals
.
This iterator terminates only if explicitly closed.
Examples
use signal_hook::consts::signal::*;
use signal_hook::iterator::Signals;
let mut signals = Signals::new(&[SIGUSR1, SIGUSR2])?;
let handle = signals.handle();
thread::spawn(move || {
for signal in signals.forever() {
match signal {
SIGUSR1 => {},
SIGUSR2 => {},
_ => unreachable!(),
}
}
});
handle.close();