Struct SignalFd

pub struct SignalFd(/* private field */);

A helper struct for creating, reading and closing a signalfd instance.

Important: please read the module level documentation about signal discarding before using this struct!

Examples

# use nix::sys::signalfd::*;
// Set the thread to block the SIGUSR1 signal, otherwise the default handler will be used
let mut mask = SigSet::empty();
mask.add(signal::SIGUSR1);
mask.thread_block().unwrap();

// Signals are queued up on the file descriptor
let mut sfd = SignalFd::with_flags(&mask, SfdFlags::SFD_NONBLOCK).unwrap();

match sfd.read_signal() {
    // we caught a signal
    Ok(Some(sig)) => (),
    // there were no signals waiting (only happens when the SFD_NONBLOCK flag is set,
    // otherwise the read_signal call blocks)
    Ok(None) => (),
    Err(err) => (), // some error happend
}

Implementations

impl SignalFd

fn new(mask: &SigSet) -> Result<SignalFd>
fn with_flags(mask: &SigSet, flags: SfdFlags) -> Result<SignalFd>
fn set_mask(&self, mask: &SigSet) -> Result<()>
fn read_signal(&self) -> Result<Option<siginfo>>
unsafe fn from_owned_fd(fd: OwnedFd) -> Self

Constructs a SignalFd wrapping an existing OwnedFd.

Safety

OwnedFd is a valid SignalFd.

Trait Implementations

impl AsFd for SignalFd

fn as_fd(&self) -> BorrowedFd<'_>

impl AsRawFd for SignalFd

fn as_raw_fd(&self) -> RawFd

impl Debug for SignalFd

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

impl Iterator for SignalFd

type Item = signalfd_siginfo;
fn next(&mut self) -> Option<Self::Item>

Auto Trait Implementations

impl Freeze for SignalFd

impl RefUnwindSafe for SignalFd

impl Send for SignalFd

impl Sync for SignalFd

impl Unpin for SignalFd

impl UnsafeUnpin for SignalFd

impl UnwindSafe for SignalFd

Blanket Implementations

impl<I> IntoIterator for SignalFd where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for SignalFd where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for SignalFd where T: ?Sized,

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

impl<T> From<T> for SignalFd

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for SignalFd where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for SignalFd where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for SignalFd where U: TryFrom<T>,

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