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
46
47
48
49
50
51
52
53
54
use Error;
use file::*;
use tempus::Span;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Poll {
pub fd: ::libc::c_int,
pub ev: Event,
r: Event,
}
impl Poll {
#[allow(missing_docs)]
#[inline]
pub fn new(f: &File, ev: Event) -> Self { Poll {
fd: f.fd() as _, ev, r: Event::empty(),
} }
#[inline]
pub fn ready(self) -> Event { self.r }
}
bitflags! {
pub struct Event: ::libc::c_short {
const In = ::libc::POLLIN;
const Out = ::libc::POLLOUT;
const Pri = ::libc::POLLPRI;
const Hup = ::libc::POLLHUP;
const Err = ::libc::POLLERR;
}
}
#[allow(missing_docs)]
pub trait PollExt {
fn poll(&mut self, t: Option<Span>) -> Result<usize, Error>;
}
impl PollExt for [Poll] {
#[inline]
fn poll(&mut self, t: Option<Span>) -> Result<usize, Error> {
let t = match t {
None => None,
Some(t) => Some(t.to_c_timespec().ok_or(Error::ERANGE)?),
};
unsafe { esyscall!(POLL, self.as_ptr(), self.len(), t.as_ref().map_or(::core::ptr::null(), |p| p as *const _), 0) }
}
}