Struct vmm_sys_util::timerfd::TimerFd [−][src]
pub struct TimerFd(_);
Expand description
A safe wrapper around a Linux
timerfd
.
Implementations
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. Ifinterval
is notNone
, 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
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.