[][src]Struct vmm_sys_util::epoll::Epoll

pub struct Epoll { /* fields omitted */ }

Wrapper over epoll functionality.

Implementations

impl Epoll[src]

pub fn new() -> Result<Self>[src]

Create a new epoll file descriptor.

pub fn ctl(
    &self,
    operation: ControlOperation,
    fd: RawFd,
    event: EpollEvent
) -> Result<()>
[src]

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 perform operation.
  • event - refers to the epoll_event instance that is linked to fd.

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();

pub fn wait(
    &self,
    max_events: usize,
    timeout: i32,
    events: &mut [EpollEvent]
) -> Result<usize>
[src]

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

  • max_events - the maximum number of events that we want to be returned in events buffer.
  • timeout - specifies for how long the epoll_wait system call will block (measured in milliseconds).
  • events - points to a memory area that will be used for storing the events returned by epoll_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(10, -1, &mut ready_events[..]).unwrap();
assert_eq!(ev_count, 1);

Trait Implementations

impl AsRawFd for Epoll[src]

impl Debug for Epoll[src]

impl Drop for Epoll[src]

Auto Trait Implementations

impl RefUnwindSafe for Epoll

impl Send for Epoll

impl Sync for Epoll

impl Unpin for Epoll

impl UnwindSafe for Epoll

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.