pub struct TimerFd { /* private fields */ }
Expand description
A timerfd which can be used to create mio-compatible timers on linux targets.
Implementations§
Source§impl TimerFd
impl TimerFd
Sourcepub fn new(clockid: ClockId) -> Result<Self>
pub fn new(clockid: ClockId) -> Result<Self>
Create a new timerfd using the given clock; if you’re not sure
what clock to use read timerfd(7) for more details, or know
that ClockId::Monotonic
is a good default for most programs.
Sourcepub fn set_timeout(&mut self, timeout: &Duration) -> Result<()>
pub fn set_timeout(&mut self, timeout: &Duration) -> Result<()>
Set a single timeout to occur after the specified duration.
Sourcepub fn set_timeout_interval(&mut self, timeout: &Duration) -> Result<()>
pub fn set_timeout_interval(&mut self, timeout: &Duration) -> Result<()>
Set a timeout to occur at each interval of the specified duration from this point in time forward.
Sourcepub fn disarm(&mut self) -> Result<()>
pub fn disarm(&mut self) -> Result<()>
Unset any existing timeouts on the timer, making this timerfd inert until rearmed.
Sourcepub fn read(&self) -> Result<u64>
pub fn read(&self) -> Result<u64>
Read the timerfd to reset the readability of the timerfd, and allow determining how many times the timer has elapsed since the last read. This should usually be read after any wakeups caused by this timerfd, as reading the timerfd is important to reset the readability of the timerfd.
Failing to call this after this timerfd causes a wakeup will result in immediately re-waking on this timerfd if level polling, or never re-waking if edge polling.
Sourcepub fn create(clockid: c_int, flags: c_int) -> Result<Self>
pub fn create(clockid: c_int, flags: c_int) -> Result<Self>
Wrapper of timerfd_create
from timerfd_create(7); For
most users it’s probably easier to use the TimerFd::new
.
Note that this library may cause the thread to block when
TimerFd::read
is called if the TFD_NONBLOCK
flag is
not included in the flags.
Sourcepub fn settime(
&mut self,
flags: c_int,
new_value: &itimerspec,
) -> Result<itimerspec>
pub fn settime( &mut self, flags: c_int, new_value: &itimerspec, ) -> Result<itimerspec>
Wrapper of timerfd_settime
from timerfd_create(7); For most
users it’s probably easier to use the TimerFd::set_timeout
or
the TimerFd::set_timeout_interval
functions.
Sourcepub fn gettime(&self) -> Result<itimerspec>
pub fn gettime(&self) -> Result<itimerspec>
Wrapper of timerfd_gettime
from timerfd_create(7)