Struct vmm_sys_util::timerfd::TimerFd[][src]

pub struct TimerFd(_);
Expand description

A safe wrapper around a Linux timerfd.

Implementations

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.

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

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

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

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

Extracts the raw file descriptor. Read more

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.

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.