pub struct Epoll { /* private fields */ }
Expand description
Wrapper over epoll functionality.
Implementations§
source§impl Epoll
impl Epoll
sourcepub fn ctl(
&self,
operation: ControlOperation,
fd: RawFd,
event: EpollEvent,
) -> Result<()>
pub fn ctl( &self, operation: ControlOperation, fd: RawFd, event: EpollEvent, ) -> Result<()>
Wrapper for libc::epoll_ctl
.
This can be used for adding, modifying or removing a file descriptor in the interest list of the epoll instance.
§Arguments
operation
- refers to the action to be performed on the file descriptor.fd
- the file descriptor on which we want to performoperation
.event
- refers to theepoll_event
instance that is linked tofd
.
§Examples
extern crate vmm_sys_util;
use std::os::unix::io::AsRawFd;
use vmm_sys_util::epoll::{ControlOperation, Epoll, EpollEvent, EventSet};
use vmm_sys_util::eventfd::EventFd;
let epoll = Epoll::new().unwrap();
let event_fd = EventFd::new(libc::EFD_NONBLOCK).unwrap();
epoll
.ctl(
ControlOperation::Add,
event_fd.as_raw_fd() as i32,
EpollEvent::new(EventSet::OUT, event_fd.as_raw_fd() as u64),
)
.unwrap();
epoll
.ctl(
ControlOperation::Modify,
event_fd.as_raw_fd() as i32,
EpollEvent::new(EventSet::IN, 4),
)
.unwrap();
sourcepub fn wait(&self, timeout: i32, events: &mut [EpollEvent]) -> Result<usize>
pub fn wait(&self, timeout: i32, events: &mut [EpollEvent]) -> Result<usize>
Wrapper for libc::epoll_wait
.
Returns the number of file descriptors in the interest list that became ready
for I/O or errno
if an error occurred.
§Arguments
timeout
- specifies for how long theepoll_wait
system call will block (measured in milliseconds).events
- points to a memory area that will be used for storing the events returned byepoll_wait()
call.
§Examples
extern crate vmm_sys_util;
use std::os::unix::io::AsRawFd;
use vmm_sys_util::epoll::{ControlOperation, Epoll, EpollEvent, EventSet};
use vmm_sys_util::eventfd::EventFd;
let epoll = Epoll::new().unwrap();
let event_fd = EventFd::new(libc::EFD_NONBLOCK).unwrap();
let mut ready_events = vec![EpollEvent::default(); 10];
epoll
.ctl(
ControlOperation::Add,
event_fd.as_raw_fd() as i32,
EpollEvent::new(EventSet::OUT, 4),
)
.unwrap();
let ev_count = epoll.wait(-1, &mut ready_events[..]).unwrap();
assert_eq!(ev_count, 1);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Epoll
impl RefUnwindSafe for Epoll
impl Send for Epoll
impl Sync for Epoll
impl Unpin for Epoll
impl UnwindSafe for Epoll
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