pub struct TimerFd(/* private fields */);Implementations§
Source§impl TimerFd
impl TimerFd
pub fn new_custom( clock: TimerfdClockId, nonblocking: bool, cloexec: bool, ) -> Result<TimerFd>
Sourcepub fn new() -> Result<TimerFd>
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}pub fn set_timeout_interval_and_flags( &mut self, value: Duration, interval: Duration, sflags: TimerFdFlag, ) -> Result<()>
Sourcepub fn set_timeout_interval(
&mut self,
value: Duration,
interval: Duration,
) -> Result<()>
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}pub fn set_timeout_oneshot_and_flags( &mut self, value: Duration, flags: TimerFdFlag, ) -> Result<()>
pub fn set_timeout_oneshot(&mut self, value: Duration) -> Result<()>
pub fn disarm(&mut self)
pub fn get_remaining_time(&self) -> Result<Duration>
pub fn get_interval(&self) -> Result<Duration>
Sourcepub fn read(&self) -> Result<u64>
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}Sourcepub fn read_and_check_overrun(&self) -> Result<bool>
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
impl AsFd for TimerFd
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
Auto Trait Implementations§
impl Freeze for TimerFd
impl RefUnwindSafe for TimerFd
impl Send for TimerFd
impl Sync for TimerFd
impl Unpin for TimerFd
impl UnwindSafe for TimerFd
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more