[][src]Struct gaea::os::signals::Signals

pub struct Signals { /* fields omitted */ }

Notifications of process signals.

Notes

This will block all signals in the signal set given when creating Signals, using sigprocmask. This means that the program is not interrupt, or in any way notified of signal until the assiocated OsQueue is polled.

Implementation notes

On platforms that support kqueue this will use the EVFILT_SIGNAL event filter, see implementation notes of the os module to see what platform supports kqueue. On Linux it uses signalfd.

Examples

use std::io;

use gaea::{event, OsQueue, poll};
use gaea::os::{Signal, Signals, SignalSet};

const SIGNAL_ID: event::Id = event::Id(10);

fn main() -> io::Result<()> {
    let mut os_queue = OsQueue::new()?;
    let mut events = Vec::new();

    // Create a `Signals` instance that will catch signals for us.
    let mut signals = Signals::new(&mut os_queue, SignalSet::all(), SIGNAL_ID)?;

    loop {
        poll::<_, io::Error>(&mut [&mut os_queue], &mut events, None)?;

        for event in &mut events {
            match event.id() {
                // Receive the signal send.
                SIGNAL_ID => match signals.receive()? {
                    Some(Signal::Interrupt) => println!("Got interrupt signal"),
                    Some(Signal::Terminate) => println!("Got terminate signal"),
                    Some(Signal::Quit) => println!("Got quit signal"),
                    _ => println!("Got unknown signal event: {:?}", event),
                },
                _ => println!("Got unexpected event: {:?}", event),
            }
        }
    }
}

Methods

impl Signals[src]

pub fn new(
    os_queue: &mut OsQueue,
    signals: SignalSet,
    id: Id
) -> Result<Signals>
[src]

Create a new signal notifier.

This will cause the associated OsQueue instance to receive events when the process receives one of the signals in the signal set.

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

Receive a signal, if any.

Trait Implementations

impl Debug for Signals[src]

Auto Trait Implementations

impl Send for Signals

impl Sync for Signals

Blanket Implementations

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

impl<T> From<T> for T[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.

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

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

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