[][src]Crate mio_timerfd

mio-timerfd

A linux timerfd wrapper for mio, making it fairly simple to integrate timers into mio-based systems with minimal overhead. Reading timerfd(7) is recommended for using this library, though for simple use all you really need to know is:

let mut timer = TimerFd::new(ClockId::Monotonic).unwrap();
timer.set_timeout(&Duration::from_millis(10)).unwrap();

let mut poll = Poll::new().unwrap();
let mut events = Events::with_capacity(64);
poll.registry().register(&mut timer, Token(0), Interest::READABLE).unwrap();

// will wait for 10ms to pass
poll.poll(&mut events, None).unwrap();
// always call `read` after the timerfd wakes your thread up, or
// else the readability of the fd isn't going to change and therefore
// the next call to poll will either wake immediately if level triggered,
// or never wake for the timerfd again if edge triggered.
let number_of_timeouts = timer.read().unwrap();

Note that any given timer can only ever contain one of:

  • a recurring interval at which to tick. When an interval timeout is set up the first tick will happen one interval's duration after the time at which the timer's timeout was set. (IE the time to first tick is the same as the time between each tick.)
  • a single timeout which will occur a given duration after the timeout was set.

Structs

TimerFd

A timerfd which can be used to create mio-compatible timers on linux targets.

Enums

ClockId

Clock used to mark the progress of the timer. timerfd_create(7)