pub struct TimerPoll(/* private fields */);Expand description
A event notification system for timers.
This instance can be wrapped into Arc and polled in separate thread.
A timer which is added to the poll instance is wrapped into
PolledTimerFd.
let poll = TimerPoll::new().unwrap();
let timer1 =
TimerFd::new("test".into(), TimerType::CLOCK_REALTIME, TimerFlags::TFD_NONBLOCK)
.unwrap();
let polled_timer1 = poll.add(timer1).unwrap();Implementations§
Source§impl TimerPoll
impl TimerPoll
Sourcepub fn new() -> TimerResult<Self>
pub fn new() -> TimerResult<Self>
Creates new instance of the event listener.
Sourcepub fn add<T: FdTimerMarker>(&self, timer: T) -> TimerResult<PolledTimerFd<T>>
pub fn add<T: FdTimerMarker>(&self, timer: T) -> TimerResult<PolledTimerFd<T>>
Adds the timer to the event monitor. It accepts any reference to instance which implements [AsFd] and it is not limited specificly to timers. Maybe later this behaviour will me modified.
§Arguments
timer-Twhere impl FdTimerMarker a timer instance. The provided FD will be polled for [EpollFlags::EPOLLIN] event types. The FD of the timer should be inited as non-blocking, but if it is not, the function attepts to switch the mode. It will not be restored when the timer will be removed fromSelf.
§Returns
A TimerResult i.e Result is returned with error description in case of error.
Sourcepub fn poll(
&self,
timeout: Option<i32>,
) -> TimerResult<Option<Vec<PollEventType>>>
pub fn poll( &self, timeout: Option<i32>, ) -> TimerResult<Option<Vec<PollEventType>>>
Polls the event monitor for events. Depending on the timeout the behaviour will
be different.
§Arguments
timeout- poll timeout. If set to Option::None will block the current thread. If set to Option::Some with inner value0will return immidiatly. The timeout is set inmiliseconds.
§Returns
A TimerResult i.e Result is returned with
-
Result::Ok with the Option where:
-
Option::Some with the Vec with the [RawFd] of the timer’s where the event has happened.
-
Option::None if no events happened.
-
-
Result::Err with error description.
Sourcepub fn get_poll_interruptor(&self) -> PollInterrupt
pub fn get_poll_interruptor(&self) -> PollInterrupt
Aquires the PollInterrupt which can be used to
interrupt the poll.
Sourcepub fn interrupt_poll(&self) -> bool
pub fn interrupt_poll(&self) -> bool
Interrupts the poll if any.