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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::fd::{AsFd, BorrowedFd};
use bitflags::bitflags;
bitflags! {
pub struct PollFlags: u16 {
const IN = linux_raw_sys::general::POLLIN as u16;
const PRI = linux_raw_sys::general::POLLPRI as u16;
const OUT = linux_raw_sys::general::POLLOUT as u16;
const RDNORM = linux_raw_sys::general::POLLRDNORM as u16;
const WRNORM = linux_raw_sys::general::POLLWRNORM as u16;
const RDBAND = linux_raw_sys::general::POLLRDBAND as u16;
const WRBAND = linux_raw_sys::general::POLLWRBAND as u16;
const ERR = linux_raw_sys::general::POLLERR as u16;
const HUP = linux_raw_sys::general::POLLHUP as u16;
const NVAL = linux_raw_sys::general::POLLNVAL as u16;
const RDHUP = linux_raw_sys::general::POLLRDHUP as u16;
}
}
#[doc(alias = "pollfd")]
#[repr(C)]
#[derive(Debug, Clone)]
pub struct PollFd<'fd> {
pub(crate) fd: BorrowedFd<'fd>,
pub(crate) events: u16,
pub(crate) revents: u16,
}
impl<'fd> PollFd<'fd> {
#[inline]
pub fn new<Fd: AsFd>(fd: &'fd Fd, events: PollFlags) -> Self {
Self::from_borrowed_fd(fd.as_fd(), events)
}
#[inline]
pub fn set_fd<Fd: AsFd>(&mut self, fd: &'fd Fd) {
self.fd = fd.as_fd();
}
#[inline]
pub fn clear_revents(&mut self) {
self.revents = 0;
}
#[inline]
pub fn from_borrowed_fd(fd: BorrowedFd<'fd>, events: PollFlags) -> Self {
Self {
fd,
events: events.bits(),
revents: 0,
}
}
#[inline]
pub fn revents(&self) -> PollFlags {
PollFlags::from_bits(self.revents).unwrap()
}
}
impl<'fd> AsFd for PollFd<'fd> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
self.fd.as_fd()
}
}