pub struct Signal { /* private fields */ }Expand description
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
Signalstream 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, theSignalstream may only return one signal notification. Specifically, beforepollis called, all signal notifications are coalesced into one item returned frompoll. Oncepollhas 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!
Implementations§
Source§impl Signal
impl Signal
Sourcepub fn new(signal: c_int) -> IoFuture<Signal>
pub fn new(signal: c_int) -> IoFuture<Signal>
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
Sourcepub fn with_handle(signal: c_int, handle: &Handle) -> IoFuture<Signal>
pub fn with_handle(signal: c_int, handle: &Handle) -> IoFuture<Signal>
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§
Source§impl Stream for Signal
impl Stream for Signal
Source§fn poll(&mut self) -> Poll<Option<c_int>, Error>
fn poll(&mut self) -> Poll<Option<c_int>, Error>
None if
the stream is finished. Read moreSource§fn wait(self) -> Wait<Self>where
Self: Sized,
fn wait(self) -> Wait<Self>where
Self: Sized,
Source§fn into_future(self) -> StreamFuture<Self>where
Self: Sized,
fn into_future(self) -> StreamFuture<Self>where
Self: Sized,
Future. Read moreSource§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
Source§fn filter_map<F, B>(self, f: F) -> FilterMap<Self, F>
fn filter_map<F, B>(self, f: F) -> FilterMap<Self, F>
Source§fn then<F, U>(self, f: F) -> Then<Self, F, U>
fn then<F, U>(self, f: F) -> Then<Self, F, U>
f. Read moreSource§fn and_then<F, U>(self, f: F) -> AndThen<Self, F, U>
fn and_then<F, U>(self, f: F) -> AndThen<Self, F, U>
f. Read moreSource§fn or_else<F, U>(self, f: F) -> OrElse<Self, F, U>
fn or_else<F, U>(self, f: F) -> OrElse<Self, F, U>
f. Read moreSource§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Source§fn concat2(self) -> Concat2<Self>
fn concat2(self) -> Concat2<Self>
Source§fn concat(self) -> Concat<Self>
fn concat(self) -> Concat<Self>
Stream::concat2 insteadSource§fn fold<F, T, Fut>(self, init: T, f: F) -> Fold<Self, F, Fut, T>where
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
Self: Sized,
fn fold<F, T, Fut>(self, init: T, f: F) -> Fold<Self, F, Fut, T>where
F: FnMut(T, Self::Item) -> Fut,
Fut: IntoFuture<Item = T>,
Self::Error: From<<Fut as IntoFuture>::Error>,
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn skip_while<P, R>(self, pred: P) -> SkipWhile<Self, P, R>
fn skip_while<P, R>(self, pred: P) -> SkipWhile<Self, P, R>
true. Read moreSource§fn take_while<P, R>(self, pred: P) -> TakeWhile<Self, P, R>
fn take_while<P, R>(self, pred: P) -> TakeWhile<Self, P, R>
true. Read moreSource§fn for_each<F, U>(self, f: F) -> ForEach<Self, F, U>
fn for_each<F, U>(self, f: F) -> ForEach<Self, F, U>
Source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
From for
this stream’s Error, returning a new stream. Read moreSource§fn take(self, amt: u64) -> Take<Self>where
Self: Sized,
fn take(self, amt: u64) -> Take<Self>where
Self: Sized,
amt items of the underlying stream. Read moreSource§fn skip(self, amt: u64) -> Skip<Self>where
Self: Sized,
fn skip(self, amt: u64) -> Skip<Self>where
Self: Sized,
amt items of the underlying stream. Read moreSource§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
finished. Read moreSource§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn buffered(self, amt: usize) -> Buffered<Self>
fn buffered(self, amt: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, amt: usize) -> BufferUnordered<Self>
Source§fn merge<S>(self, other: S) -> Merge<Self, S>
fn merge<S>(self, other: S) -> Merge<Self, S>
select nowSource§fn zip<S>(self, other: S) -> Zip<Self, S>
fn zip<S>(self, other: S) -> Zip<Self, S>
Source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek method. Read more