Struct signal_hook::iterator::backend::SignalDelivery
source · [−]pub struct SignalDelivery<R, E: Exfiltrator> { /* private fields */ }
Expand description
A struct for delivering received signals to the main program flow.
The self-pipe IO type is generic. See the
with_pipe
method for requirements
for the IO type.
Implementations
sourceimpl<R, E: Exfiltrator> SignalDelivery<R, E> where
R: 'static + AsRawFd + Send + Sync,
impl<R, E: Exfiltrator> SignalDelivery<R, E> where
R: 'static + AsRawFd + Send + Sync,
sourcepub fn with_pipe<I, S, W>(
read: R,
write: W,
exfiltrator: E,
signals: I
) -> Result<Self, Error> where
I: IntoIterator<Item = S>,
S: Borrow<c_int>,
W: 'static + AsRawFd + Debug + Send + Sync,
pub fn with_pipe<I, S, W>(
read: R,
write: W,
exfiltrator: E,
signals: I
) -> Result<Self, Error> where
I: IntoIterator<Item = S>,
S: Borrow<c_int>,
W: 'static + AsRawFd + Debug + Send + Sync,
Creates the SignalDelivery
structure.
The read and write arguments must be the ends of a suitable pipe type. These are used for communication between the signal handler and main program flow.
Registers all the signals listed. The same restrictions (panics, errors) apply as with
add_signal
.
Requirements for the pipe type
- Must support
send
for asynchronously writing bytes to the write end - Must support
recv
for reading bytes from the read end
So UnixStream is a good choice for this.
sourcepub fn get_read(&self) -> &R
pub fn get_read(&self) -> &R
Get a reference to the read end of the self pipe
You may use this method to register the underlying file descriptor
with an eventing system (e. g. epoll) to get notified if there are
bytes in the pipe. If the event system reports the file descriptor
ready for reading you can then call pending
to get the arrived signals.
sourcepub fn get_read_mut(&mut self) -> &mut R
pub fn get_read_mut(&mut self) -> &mut R
Get a mutable reference to the read end of the self pipe
See the get_read
method for some additional
information.
sourcepub fn pending(&mut self) -> Pending<E>ⓘNotable traits for Pending<E>impl<E: Exfiltrator> Iterator for Pending<E> type Item = E::Output;
pub fn pending(&mut self) -> Pending<E>ⓘNotable traits for Pending<E>impl<E: Exfiltrator> Iterator for Pending<E> type Item = E::Output;
Returns an iterator of already received signals.
This returns an iterator over all the signal numbers of the signals received since last
time they were read (out of the set registered by this SignalDelivery
instance). Note
that they are returned in arbitrary order and a signal number is returned only once even
if it was received multiple times.
This method returns immediately (does not block) and may produce an empty iterator if there are no signals ready.
sourcepub fn poll_pending<F>(
&mut self,
has_signals: &mut F
) -> Result<Option<Pending<E>>, Error> where
F: FnMut(&mut R) -> Result<bool, Error>,
pub fn poll_pending<F>(
&mut self,
has_signals: &mut F
) -> Result<Option<Pending<E>>, Error> where
F: FnMut(&mut R) -> Result<bool, Error>,
Checks the reading end of the self pipe for available signals.
If there are no signals available or this instance was already closed it returns
Option::None
. If there are some signals it returns a Pending
instance wrapped inside a Option::Some
. However, due to implementation details,
this still can produce an empty iterator.
This method doesn’t check the reading end by itself but uses the passed in callback. This method blocks if and only if the callback blocks trying to read some bytes.
Trait Implementations
Auto Trait Implementations
impl<R, E> !RefUnwindSafe for SignalDelivery<R, E>
impl<R, E> Send for SignalDelivery<R, E> where
R: Send,
impl<R, E> Sync for SignalDelivery<R, E> where
R: Sync,
impl<R, E> Unpin for SignalDelivery<R, E> where
R: Unpin,
impl<R, E> !UnwindSafe for SignalDelivery<R, E>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more