pub struct SignalDelivery<R, E: Exfiltrator> { /* private fields */ }
Available on non-Windows and crate feature iterator only.
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§

source§

impl<R, E: Exfiltrator> SignalDelivery<R, E>where R: 'static + AsRawFd + Send + Sync,

source

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.

source

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.

source

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.

source

pub fn pending(&mut self) -> Pending<E>

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.

source

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.

source

pub fn handle(&self) -> Handle

Get a Handle for this SignalDelivery instance.

This can be used to add further signals or close the whole signal delivery mechanism.

Trait Implementations§

source§

impl<R: Debug, E: Debug + Exfiltrator> Debug for SignalDelivery<R, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.