vmm_sys_util::timerfd

Struct TimerFd

source
pub struct TimerFd(/* private fields */);
Expand description

A safe wrapper around a Linux timerfd.

Implementations§

source§

impl TimerFd

source

pub fn new() -> Result<TimerFd>

Create a new TimerFd.

This creates a nonsettable monotonically increasing clock that does not change after system startup. The timer is initally disarmed and must be armed by calling reset.

source

pub fn reset(&mut self, dur: Duration, interval: Option<Duration>) -> Result<()>

Arm the TimerFd.

Set the timer to expire after dur.

§Arguments
  • dur: Specify the initial expiration of the timer.
  • interval: Specify the period for repeated expirations, depending on the value passed. If interval is not None, it represents the period after the initial expiration. Otherwise the timer will expire just once. Cancels any existing duration and repeating interval.
§Examples
extern crate vmm_sys_util;
use vmm_sys_util::timerfd::TimerFd;

let mut timer = TimerFd::new().unwrap();
let dur = Duration::from_millis(100);
let interval = Duration::from_millis(100);

timer.reset(dur, Some(interval)).unwrap();
source

pub fn wait(&mut self) -> Result<u64>

Wait until the timer expires.

The return value represents the number of times the timer has expired since the last time wait was called. If the timer has not yet expired once, this call will block until it does.

§Examples
extern crate vmm_sys_util;
use vmm_sys_util::timerfd::TimerFd;

let mut timer = TimerFd::new().unwrap();
let dur = Duration::from_millis(100);
let interval = Duration::from_millis(100);
timer.reset(dur, Some(interval)).unwrap();

sleep(dur * 3);
let count = timer.wait().unwrap();
assert!(count >= 3);
source

pub fn is_armed(&self) -> Result<bool>

Tell if the timer is armed.

Returns Ok(true) if the timer is currently armed, otherwise the errno set by timerfd_gettime.

§Examples
extern crate vmm_sys_util;
use vmm_sys_util::timerfd::TimerFd;

let mut timer = TimerFd::new().unwrap();
let dur = Duration::from_millis(100);

timer.reset(dur, None).unwrap();
assert!(timer.is_armed().unwrap());
source

pub fn clear(&mut self) -> Result<()>

Disarm the timer.

Set zero to disarm the timer, referring to timerfd_settime.

§Examples
extern crate vmm_sys_util;
use vmm_sys_util::timerfd::TimerFd;

let mut timer = TimerFd::new().unwrap();
let dur = Duration::from_millis(100);

timer.reset(dur, None).unwrap();
timer.clear().unwrap();

Trait Implementations§

source§

impl AsRawFd for TimerFd

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl Debug for TimerFd

source§

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

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

impl FromRawFd for TimerFd

source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

This function is unsafe as the primitives currently returned have the contract that they are the sole owner of the file descriptor they are wrapping. Usage of this function could accidentally allow violating this contract which can cause memory unsafety in code that relies on it being true.

source§

impl IntoRawFd for TimerFd

source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying 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.