rusl/platform/compat/
epoll.rs1use linux_rust_bindings::epoll::__poll_t;
2#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
4transparent_bitflags! {
5 pub struct EpollEventMask: __poll_t {
6 const DEFAULT = 0;
7 const EPOLLIN = 0x0000_0001;
8 const EPOLLPRI = 0x0000_0002;
9 const EPOLLOUT = 0x0000_0004;
10 const EPOLLERR = 0x0000_0008;
11 const EPOLLHUP = 0x0000_0010;
12 const EPOLLNVAL = 0x0000_0020;
13 const EPOLLRDNORM = 0x0000_0040;
14 const EPOLLRDBAND = 0x0000_0080;
15 const EPOLLWRNORM = 0x0000_0100;
16 const EPOLLWRBAND = 0x0000_0200;
17 const EPOLLMSG = 0x0000_0400;
18 const EPOLLRDHUP = 0x0000_2000;
19 const EPOLLEXCLUSIVE = 1 << 28;
20 const EPOLLWAKEUP = 1 << 29;
21 const EPOLLONESHOT = 1 << 30;
22 const EPOLLET = 1 << 31;
23 }
24}
25
26#[derive(Debug, Copy, Clone)]
27pub enum EpollOp {
28 Add,
29 Mod,
30 Del,
31}
32
33impl EpollOp {
34 pub(crate) const fn into_op(self) -> i32 {
35 match self {
36 Self::Add => linux_rust_bindings::epoll::EPOLL_CTL_ADD,
37 Self::Mod => linux_rust_bindings::epoll::EPOLL_CTL_MOD,
38 Self::Del => linux_rust_bindings::epoll::EPOLL_CTL_DEL,
39 }
40 }
41}
42
43#[repr(transparent)]
44#[derive(Debug, Copy, Clone)]
45pub struct EpollEvent(pub(crate) linux_rust_bindings::epoll::epoll_event);
46
47impl EpollEvent {
48 #[inline]
49 #[must_use]
50 pub const fn new(user_data: u64, mask: EpollEventMask) -> Self {
51 Self(linux_rust_bindings::epoll::epoll_event {
52 events: mask.bits(),
53 data: user_data,
54 })
55 }
56
57 #[inline]
58 #[must_use]
59 pub const fn get_data(&self) -> u64 {
60 self.0.data
61 }
62
63 #[inline]
64 #[must_use]
65 pub const fn get_events(&self) -> EpollEventMask {
66 EpollEventMask(self.0.events)
67 }
68}