vmm_sys_util::epoll

Struct Epoll

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

Wrapper over epoll functionality.

Implementations§

source§

impl Epoll

source

pub fn new() -> Result<Self>

Create a new epoll file descriptor.

source

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

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 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(-1, &mut ready_events[..]).unwrap();
assert_eq!(ev_count, 1);

Trait Implementations§

source§

impl AsRawFd for Epoll

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Debug for Epoll

source§

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

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

impl Drop for Epoll

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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.