[][src]Struct tokio_signal::unix::Signal

pub struct Signal { /* fields omitted */ }

An implementation of Stream for receiving a particular type of signal.

This structure implements the Stream trait and represents notifications of the current process receiving a particular signal. The signal being listened for is passed to Signal::new, and the same signal number is then yielded as each element for the stream.

In general signal handling on Unix is a pretty tricky topic, and this structure is no exception! There are some important limitations to keep in mind when using Signal streams:

  • Signals handling in Unix already necessitates coalescing signals together sometimes. This Signal stream is also no exception here in that it will also coalesce signals. That is, even if the signal handler for this process runs multiple times, the Signal stream may only return one signal notification. Specifically, before poll is called, all signal notifications are coalesced into one item returned from poll. Once poll has been called, however, a further signal is guaranteed to be yielded as an item.

    Put another way, any element pulled off the returned stream corresponds to at least one signal, but possibly more.

  • Signal handling in general is relatively inefficient. Although some improvements are possible in this crate, it's recommended to not plan on having millions of signal channels open.

  • Currently the "driver task" to process incoming signals never exits. This driver task runs in the background of the event loop provided, and in general you shouldn't need to worry about it.

If you've got any questions about this feel free to open an issue on the repo, though, as I'd love to chat about this! In other words, I'd love to alleviate some of these limitations if possible!

Methods

impl Signal[src]

pub fn new(signal: c_int) -> IoFuture<Signal>[src]

Creates a new stream which will receive notifications when the current process receives the signal signal.

This function will create a new stream which binds to the default event loop. This function returns a future which will then resolve to the signal stream, if successful.

The Signal stream is an infinite stream which will receive notifications whenever a signal is received. More documentation can be found on Signal itself, but to reiterate:

  • Signals may be coalesced beyond what the kernel already does.
  • Once a signal handler is registered with the process the underlying libc signal handler is never unregistered.

A Signal stream can be created for a particular signal number multiple times. When a signal is received then all the associated channels will receive the signal notification.

Errors

  • If the lower-level C functions fail for some reason.
  • If the previous initialization of this specific signal failed.
  • If the signal is one of signal_hook::FORBIDDEN

pub fn with_handle(signal: c_int, handle: &Handle) -> IoFuture<Signal>[src]

Creates a new stream which will receive notifications when the current process receives the signal signal.

This function will create a new stream which may be based on the event loop handle provided. This function returns a future which will then resolve to the signal stream, if successful.

The Signal stream is an infinite stream which will receive notifications whenever a signal is received. More documentation can be found on Signal itself, but to reiterate:

  • Signals may be coalesced beyond what the kernel already does.
  • Once a signal handler is registered with the process the underlying libc signal handler is never unregistered.

A Signal stream can be created for a particular signal number multiple times. When a signal is received then all the associated channels will receive the signal notification.

Trait Implementations

impl Drop for Signal[src]

impl Stream for Signal[src]

type Item = c_int

The type of item this stream will yield on success.

type Error = Error

The type of error this stream may generate.

Auto Trait Implementations

impl !RefUnwindSafe for Signal

impl Send for Signal

impl Sync for Signal

impl Unpin for Signal

impl !UnwindSafe for Signal

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