TimerFd

Struct TimerFd 

Source
pub struct TimerFd(/* private fields */);

Implementations§

Source§

impl TimerFd

Source

pub fn new_custom( clock: TimerfdClockId, nonblocking: bool, cloexec: bool, ) -> Result<TimerFd>

Source

pub fn new() -> Result<TimerFd>

Examples found in repository?
examples/example.rs (line 8)
3fn main() {
4    let mut poll = mio::Poll::new().unwrap();
5    let mut events = mio::Events::with_capacity(2);
6
7    /* Timer */
8    let mut timer1 = timerfd_mio::TimerFd::new().unwrap();
9    timer1.set_timeout_interval(Duration::from_millis(600), Duration::from_millis(300)).unwrap();
10    poll.registry().register(&mut timer1, mio::Token(1), mio::Interest::READABLE).unwrap();
11
12    let mut timer2 = timerfd_mio::TimerFd::new().unwrap();
13    timer2.set_timeout_interval(Duration::from_millis(1000), Duration::from_millis(1000)).unwrap();
14    poll.registry().register(&mut timer2, mio::Token(2), mio::Interest::READABLE).unwrap();
15
16    loop {
17        poll.poll(&mut events, None).unwrap();
18
19        for event in &events {
20            if event.token() == mio::Token(1) {
21                timer1.read().unwrap();
22                println!("Timer 1 event");
23            }
24            if event.token() == mio::Token(2) {
25                // this function check timer overrun
26                timer2.read_and_check_overrun().unwrap();
27                println!("Timer 2 event");
28            }
29        }
30    }
31}
Source

pub fn set_timeout_interval_and_flags( &mut self, value: Duration, interval: Duration, sflags: TimerFdFlag, ) -> Result<()>

Source

pub fn set_timeout_interval( &mut self, value: Duration, interval: Duration, ) -> Result<()>

Examples found in repository?
examples/example.rs (line 9)
3fn main() {
4    let mut poll = mio::Poll::new().unwrap();
5    let mut events = mio::Events::with_capacity(2);
6
7    /* Timer */
8    let mut timer1 = timerfd_mio::TimerFd::new().unwrap();
9    timer1.set_timeout_interval(Duration::from_millis(600), Duration::from_millis(300)).unwrap();
10    poll.registry().register(&mut timer1, mio::Token(1), mio::Interest::READABLE).unwrap();
11
12    let mut timer2 = timerfd_mio::TimerFd::new().unwrap();
13    timer2.set_timeout_interval(Duration::from_millis(1000), Duration::from_millis(1000)).unwrap();
14    poll.registry().register(&mut timer2, mio::Token(2), mio::Interest::READABLE).unwrap();
15
16    loop {
17        poll.poll(&mut events, None).unwrap();
18
19        for event in &events {
20            if event.token() == mio::Token(1) {
21                timer1.read().unwrap();
22                println!("Timer 1 event");
23            }
24            if event.token() == mio::Token(2) {
25                // this function check timer overrun
26                timer2.read_and_check_overrun().unwrap();
27                println!("Timer 2 event");
28            }
29        }
30    }
31}
Source

pub fn set_timeout_oneshot_and_flags( &mut self, value: Duration, flags: TimerFdFlag, ) -> Result<()>

Source

pub fn set_timeout_oneshot(&mut self, value: Duration) -> Result<()>

Source

pub fn disarm(&mut self)

Source

pub fn get_remaining_time(&self) -> Result<Duration>

Source

pub fn get_interval(&self) -> Result<Duration>

Source

pub fn read(&self) -> Result<u64>

Examples found in repository?
examples/example.rs (line 21)
3fn main() {
4    let mut poll = mio::Poll::new().unwrap();
5    let mut events = mio::Events::with_capacity(2);
6
7    /* Timer */
8    let mut timer1 = timerfd_mio::TimerFd::new().unwrap();
9    timer1.set_timeout_interval(Duration::from_millis(600), Duration::from_millis(300)).unwrap();
10    poll.registry().register(&mut timer1, mio::Token(1), mio::Interest::READABLE).unwrap();
11
12    let mut timer2 = timerfd_mio::TimerFd::new().unwrap();
13    timer2.set_timeout_interval(Duration::from_millis(1000), Duration::from_millis(1000)).unwrap();
14    poll.registry().register(&mut timer2, mio::Token(2), mio::Interest::READABLE).unwrap();
15
16    loop {
17        poll.poll(&mut events, None).unwrap();
18
19        for event in &events {
20            if event.token() == mio::Token(1) {
21                timer1.read().unwrap();
22                println!("Timer 1 event");
23            }
24            if event.token() == mio::Token(2) {
25                // this function check timer overrun
26                timer2.read_and_check_overrun().unwrap();
27                println!("Timer 2 event");
28            }
29        }
30    }
31}
Source

pub fn read_and_check_overrun(&self) -> Result<bool>

Examples found in repository?
examples/example.rs (line 26)
3fn main() {
4    let mut poll = mio::Poll::new().unwrap();
5    let mut events = mio::Events::with_capacity(2);
6
7    /* Timer */
8    let mut timer1 = timerfd_mio::TimerFd::new().unwrap();
9    timer1.set_timeout_interval(Duration::from_millis(600), Duration::from_millis(300)).unwrap();
10    poll.registry().register(&mut timer1, mio::Token(1), mio::Interest::READABLE).unwrap();
11
12    let mut timer2 = timerfd_mio::TimerFd::new().unwrap();
13    timer2.set_timeout_interval(Duration::from_millis(1000), Duration::from_millis(1000)).unwrap();
14    poll.registry().register(&mut timer2, mio::Token(2), mio::Interest::READABLE).unwrap();
15
16    loop {
17        poll.poll(&mut events, None).unwrap();
18
19        for event in &events {
20            if event.token() == mio::Token(1) {
21                timer1.read().unwrap();
22                println!("Timer 1 event");
23            }
24            if event.token() == mio::Token(2) {
25                // this function check timer overrun
26                timer2.read_and_check_overrun().unwrap();
27                println!("Timer 2 event");
28            }
29        }
30    }
31}

Trait Implementations§

Source§

impl AsFd for TimerFd

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for TimerFd

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for TimerFd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Source for TimerFd

Source§

fn register( &mut self, registry: &Registry, token: Token, interests: Interest, ) -> Result<()>

Register self with the given Registry instance. Read more
Source§

fn reregister( &mut self, registry: &Registry, token: Token, interests: Interest, ) -> Result<()>

Re-register self with the given Registry instance. Read more
Source§

fn deregister(&mut self, registry: &Registry) -> Result<()>

Deregister self from the given Registry instance. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.