Struct std::io::signal::Listener[src]

pub struct Listener {
    pub rx: Receiver<Signum>,
    // some fields omitted
}

Listener provides a receiver to listen for registered signals.

Listener automatically unregisters its handles once it is out of scope. However, clients can still unregister signums manually.

Example

fn main() { #![allow(unused_must_use)] use std::io::signal::{Listener, Interrupt}; let mut listener = Listener::new(); listener.register(Interrupt); loop { match listener.rx.recv() { Interrupt => println!("Got Interrupt'ed"), _ => (), } } }
use std::io::signal::{Listener, Interrupt};

let mut listener = Listener::new();
listener.register(Interrupt);

loop {
    match listener.rx.recv() {
        Interrupt => println!("Got Interrupt'ed"),
        _ => (),
    }
}

Fields

rx

Clients of Listener can recv() on this receiver. This is exposed to allow selection over it as well as manipulation of the receiver directly.

Methods

impl Listener

fn new() -> Listener

Creates a new listener for signals. Once created, signals are bound via the register method (otherwise nothing will ever be received)

fn register(&mut self, signum: Signum) -> IoResult<()>

Listen for a signal, returning true when successfully registered for signum. Signals can be received using recv().

Once a signal is registered, this listener will continue to receive notifications of signals until it is unregistered. This occurs regardless of the number of other listeners registered in other tasks (or on this task).

Signals are still received if there is no task actively waiting for a signal, and a later call to recv will return the signal that was received while no task was waiting on it.

Error

If this function fails to register a signal handler, then an error will be returned.

fn unregister(&mut self, signum: Signum)

Unregisters a signal. If this listener currently had a handler registered for the signal, then it will stop receiving any more notification about the signal. If the signal has already been received, it may still be returned by recv.