Struct signal_hook::iterator::Signals[][src]

pub struct Signals { /* fields omitted */ }

The main structure of the module, representing interest in some signals.

Unlike the helpers in other modules, this registers the signals when created and unregisters them on drop. It provides the pending signals during its lifetime, either in batches or as an infinite iterator.

Multiple consumers

You may have noticed this structure can be used simultaneously by multiple threads. If it is done, a signal arrives to one of the threads (on the first come, first serve basis). The signal is not broadcasted to all currently active threads.

Examples

let signals = signal_hook::iterator::Signals::new(&[libc::SIGUSR1, libc::SIGUSR2])?;
thread::spawn(move || {
    for signal in &signals {
        match signal {
            libc::SIGUSR1 => {},
            libc::SIGUSR2 => {},
            _ => unreachable!(),
        }
    }
});

Methods

impl Signals
[src]

Creates the Signals structure.

This registers all the signals listed. The same restrictions (panics, errors) apply as with register.

Important traits for Pending<'a>

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 number is 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.

Important traits for Pending<'a>

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 length.

Note that the blocking is done in this method, not in the iterator.

Important traits for Forever<'a>

Returns 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 &Signals.

Examples

let signals = signal_hook::iterator::Signals::new(&[libc::SIGUSR1, libc::SIGUSR2])?;
thread::spawn(move || {
    for signal in signals.forever() {
        match signal {
            libc::SIGUSR1 => {},
            libc::SIGUSR2 => {},
            _ => unreachable!(),
        }
    }
});

Trait Implementations

impl Clone for Signals
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Signals
[src]

Formats the value using the given formatter. Read more

impl Drop for Signals
[src]

Executes the destructor for this type. Read more

impl<'a> IntoIterator for &'a Signals
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for Forever<'a>

Creates an iterator from a value. Read more

Auto Trait Implementations

impl Send for Signals

impl Sync for Signals