vmm_sys_util::eventfd

Struct EventFd

source
pub struct EventFd { /* private fields */ }
Expand description

A safe wrapper around Linux eventfd.

Implementations§

source§

impl EventFd

source

pub fn new(flag: i32) -> Result<EventFd, Error>

Create a new EventFd with an initial value.

§Arguments
  • flag: The initial value used for creating the EventFd. Refer to Linux eventfd.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

EventFd::new(EFD_NONBLOCK).unwrap();
source

pub fn write(&self, v: u64) -> Result<(), Error>

Add a value to the eventfd’s counter.

When the addition causes the counter overflow, this would either block until a read is performed on the file descriptor, or fail with the error EAGAIN if the file descriptor has been made nonblocking.

§Arguments
  • v: the value to be added to the eventfd’s counter.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

let evt = EventFd::new(EFD_NONBLOCK).unwrap();
evt.write(55).unwrap();
source

pub fn read(&self) -> Result<u64, Error>

Read a value from the eventfd.

If the counter is zero, this would either block until the counter becomes nonzero, or fail with the error EAGAIN if the file descriptor has been made nonblocking.

§Examples
extern crate vmm_sys_util;
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

let evt = EventFd::new(EFD_NONBLOCK).unwrap();
evt.write(55).unwrap();
assert_eq!(evt.read().unwrap(), 55);
source

pub fn try_clone(&self) -> Result<EventFd, Error>

Clone this EventFd.

This internally creates a new file descriptor and it will share the same underlying count within the kernel.

§Examples
extern crate vmm_sys_util;
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

let evt = EventFd::new(EFD_NONBLOCK).unwrap();
let evt_clone = evt.try_clone().unwrap();
evt.write(923).unwrap();
assert_eq!(evt_clone.read().unwrap(), 923);

Trait Implementations§

source§

impl AsRawFd for EventFd

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Debug for EventFd

source§

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

Formats the value using the given formatter. Read more
source§

impl FromRawFd for EventFd

source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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 T
where U: TryFrom<T>,

source§

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.