[][src]Struct mio_signals::Signals

pub struct Signals { /* fields omitted */ }

Notification of process signals.

Notes

On Android and Linux this will block all signals in the signal set given when creating Signals, using sigprocmask(2). This means that the program is not interrupted, or in any way notified of signal until the assiocated Poll is polled.

On platforms that support kqueue(2) the signal handler action is set to SIG_IGN using sigaction(2), meaning that all signals will be ignored. Same as on Linux based systems; the program is not interrupted, or in any way notified of signal until the assiocated Poll is polled.

Implementation notes

On platforms that support kqueue(2) this will use the EVFILT_SIGNAL event filter. On Android and Linux it uses signalfd(2).

Examples

use std::io;

use mio::{Poll, Events, Interest, Token};
use mio_signals::{Signals, Signal, SignalSet};

const SIGNAL: Token = Token(10);

fn main() -> io::Result<()> {
    let mut poll = Poll::new()?;
    let mut events = Events::with_capacity(128);

    // Create a `Signals` instance that will catch signals for us.
    let mut signals = Signals::new(SignalSet::all())?;
    // And register it with our `Poll` instance.
    poll.registry().register(&mut signals, SIGNAL, Interest::READABLE)?;

    loop {
        poll.poll(&mut events, None)?;

        for event in events.iter() {
            match event.token() {
                // Because we're using edge triggers (default in Mio) we need
                // to keep calling `receive` until it returns `Ok(None)`.
                SIGNAL => loop {
                    match signals.receive()? {
                        Some(Signal::Interrupt) => println!("Got interrupt signal"),
                        Some(Signal::Terminate) => println!("Got terminate signal"),
                        Some(Signal::Quit) => println!("Got quit signal"),
                        None => break,
                    }
                },
                _ => println!("Got unexpected event: {:?}", event),
            }
        }
    }
}

Methods

impl Signals[src]

pub fn new(signals: SignalSet) -> Result<Signals>[src]

Create a new signal notifier.

pub fn receive(&mut self) -> Result<Option<Signal>>[src]

Receive a signal, if any.

If no signal is available this returns Ok(None).

Trait Implementations

impl Debug for Signals[src]

impl Source for Signals[src]

Auto Trait Implementations

impl RefUnwindSafe for Signals

impl Send for Signals

impl Sync for Signals

impl Unpin for Signals

impl UnwindSafe for Signals

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, S> Source for T where
    S: Source + ?Sized,
    T: DerefMut<Target = S>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.