pub struct EventFd { /* private fields */ }
Expand description
A safe wrapper around Linux
eventfd
.
Implementations§
source§impl EventFd
impl EventFd
sourcepub fn write(&self, v: u64) -> Result<(), Error>
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();
sourcepub fn read(&self) -> Result<u64, Error>
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);
sourcepub fn try_clone(&self) -> Result<EventFd, Error>
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§
Auto Trait Implementations§
impl Freeze for EventFd
impl RefUnwindSafe for EventFd
impl Send for EventFd
impl Sync for EventFd
impl Unpin for EventFd
impl UnwindSafe for EventFd
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more