pub struct TimerFd(/* private fields */);
Expand description
A safe wrapper around a Linux
timerfd
.
Implementations§
source§impl TimerFd
impl TimerFd
sourcepub fn reset(&mut self, dur: Duration, interval: Option<Duration>) -> Result<()>
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. 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();
sourcepub fn wait(&mut self) -> Result<u64>
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);
sourcepub fn is_armed(&self) -> Result<bool>
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());
sourcepub fn clear(&mut self) -> Result<()>
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 FromRawFd for TimerFd
impl FromRawFd for TimerFd
source§unsafe fn from_raw_fd(fd: RawFd) -> Self
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.