Struct PollFd

#[repr(transparent)]
pub struct PollFd<'fd> { /* private fields */ }

This is a wrapper around libc::pollfd.

It's meant to be used as an argument to the poll and ppoll functions to specify the events of interest for a specific file descriptor.

After a call to poll or ppoll, the events that occurred can be retrieved by calling revents() on the PollFd object from the array passed to poll.

Implementations

impl<'fd> PollFd<'fd>

fn new(fd: BorrowedFd<'fd>, events: PollFlags) -> PollFd<'fd>

Creates a new PollFd specifying the events of interest for a given file descriptor.

Examples

# use std::os::unix::io::{AsFd, AsRawFd, FromRawFd};
# use nix::{
#     poll::{PollTimeout, PollFd, PollFlags, poll},
#     unistd::{pipe, read}
# };
let (r, w) = pipe().unwrap();
let pfd = PollFd::new(r.as_fd(), PollFlags::POLLIN);

These are placed in an array and passed to poll or ppoll.

fn revents(&self) -> Option<PollFlags>

Returns the events that occurred in the last call to poll or ppoll. Will only return None if the kernel provides status flags that Nix does not know about.

fn any(&self) -> Option<bool>

Returns if any of the events of interest occured in the last call to poll or ppoll. Will only return None if the kernel provides status flags that Nix does not know about.

Equivalent to x.revents()? != PollFlags::empty().

This is marginally more efficient than PollFd::all.

fn all(&self) -> Option<bool>

Returns if all the events of interest occured in the last call to poll or ppoll. Will only return None if the kernel provides status flags that Nix does not know about.

Equivalent to x.revents()? & x.events() == x.events().

This is marginally less efficient than PollFd::any.

fn events(&self) -> PollFlags

The events of interest for this PollFd.

fn set_events(&mut self, events: PollFlags)

Modify the events of interest for this PollFd.

Trait Implementations

impl AsFd for PollFd<'_>

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

impl<'fd> Clone for PollFd<'fd>

fn clone(&self) -> Self

impl<'fd> Debug for PollFd<'fd>

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

impl<'fd> Eq for PollFd<'fd>

impl<'fd> Hash for PollFd<'fd>

fn hash<__H: Hasher>(&self, state: &mut __H)

impl<'fd> PartialEq for PollFd<'fd>

fn eq(&self, other: &Self) -> bool

impl<'fd> StructuralPartialEq for PollFd<'fd>

Auto Trait Implementations

impl<'fd> Freeze for PollFd<'fd>

impl<'fd> RefUnwindSafe for PollFd<'fd>

impl<'fd> Send for PollFd<'fd>

impl<'fd> Sync for PollFd<'fd>

impl<'fd> Unpin for PollFd<'fd>

impl<'fd> UnsafeUnpin for PollFd<'fd>

impl<'fd> UnwindSafe for PollFd<'fd>

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for PollFd<'fd> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for PollFd<'fd> where T: ?Sized,

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

impl<T> CloneToUninit for PollFd<'fd> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for PollFd<'fd>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for PollFd<'fd> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for PollFd<'fd> 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 PollFd<'fd> where U: Into<T>,

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

impl<T, U> TryInto<U> for PollFd<'fd> where U: TryFrom<T>,

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