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

pub struct TimerFd(_);

A safe wrapper around a Linux timerfd.

Implementations

impl TimerFd[src]

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

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.

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

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

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

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

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

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

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

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

impl AsRawFd for TimerFd[src]

impl FromRawFd for TimerFd[src]

impl IntoRawFd for TimerFd[src]

Auto Trait Implementations

impl RefUnwindSafe for TimerFd

impl Send for TimerFd

impl Sync for TimerFd

impl Unpin for TimerFd

impl UnwindSafe for TimerFd

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.