1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use mio::Registry;
use std::io;
use std::time::Duration;
#[derive(Debug)]
pub struct Poll {
poll: mio::Poll,
events: mio::Events,
}
impl Poll {
pub fn with_capacity(capacity: usize) -> io::Result<Poll> {
let poll = mio::Poll::new()?;
Ok(Poll {
poll,
events: mio::Events::with_capacity(capacity),
})
}
pub fn poll<I>(&mut self, timeout: I) -> io::Result<&mio::Events>
where
I: Into<Option<Duration>>,
{
let _ = self.poll.poll(&mut self.events, timeout.into())?;
Ok(&self.events)
}
pub fn clear(&mut self) {
self.events.clear()
}
pub fn polled_events(&self) -> &mio::Events {
&self.events
}
pub fn registry(&self) -> &Registry {
self.poll.registry()
}
}