Correct EPOLL constants

This commit is contained in:
Jeremy Soller
2024-05-06 15:00:50 -06:00
parent 59e7d2d70f
commit 0f5e6a5649
3 changed files with 39 additions and 21 deletions
+3 -3
View File
@@ -5,14 +5,14 @@ pub const EPOLL_CLOEXEC: c_int = 0x8_0000;
pub const EPOLLIN: c_uint = 0x001;
pub const EPOLLPRI: c_uint = 0x002;
pub const EPOLLOUT: c_uint = 0x004;
pub const EPOLLRDNORM: c_uint = 0x040;
pub const EPOLLERR: c_uint = 0x008;
pub const EPOLLHUP: c_uint = 0x010;
pub const EPOLLNVAL: c_uint = 0x020;
pub const EPOLLRDNORM: c_uint = 0x040;
pub const EPOLLRDBAND: c_uint = 0x080;
pub const EPOLLWRNORM: c_uint = 0x100;
pub const EPOLLWRBAND: c_uint = 0x200;
pub const EPOLLMSG: c_uint = 0x400;
pub const EPOLLERR: c_uint = 0x008;
pub const EPOLLHUP: c_uint = 0x010;
pub const EPOLLRDHUP: c_uint = 0x2000;
pub const EPOLLEXCLUSIVE: c_uint = 1 << 28;
pub const EPOLLWAKEUP: c_uint = 1 << 29;
+16 -16
View File
@@ -2,19 +2,19 @@ use crate::platform::types::*;
pub const EPOLL_CLOEXEC: c_int = 0x0100_0000;
pub const EPOLLIN: c_uint = 1;
pub const EPOLLPRI: c_uint = 0;
pub const EPOLLOUT: c_uint = 2;
pub const EPOLLRDNORM: c_uint = 0;
pub const EPOLLNVAL: c_uint = 0;
pub const EPOLLRDBAND: c_uint = 0;
pub const EPOLLWRNORM: c_uint = 0;
pub const EPOLLWRBAND: c_uint = 0;
pub const EPOLLMSG: c_uint = 0;
pub const EPOLLERR: c_uint = 0;
pub const EPOLLHUP: c_uint = 0;
pub const EPOLLRDHUP: c_uint = 0;
pub const EPOLLEXCLUSIVE: c_uint = 0;
pub const EPOLLWAKEUP: c_uint = 0;
pub const EPOLLONESHOT: c_uint = 0;
pub const EPOLLET: c_uint = 0;
pub const EPOLLIN: c_uint = 0x001;
pub const EPOLLPRI: c_uint = 0x002;
pub const EPOLLOUT: c_uint = 0x004;
pub const EPOLLERR: c_uint = 0x008;
pub const EPOLLHUP: c_uint = 0x010;
pub const EPOLLNVAL: c_uint = 0x020;
pub const EPOLLRDNORM: c_uint = 0x040;
pub const EPOLLRDBAND: c_uint = 0x080;
pub const EPOLLWRNORM: c_uint = 0x100;
pub const EPOLLWRBAND: c_uint = 0x200;
pub const EPOLLMSG: c_uint = 0x400;
pub const EPOLLRDHUP: c_uint = 0x2000;
pub const EPOLLEXCLUSIVE: c_uint = 1 << 28;
pub const EPOLLWAKEUP: c_uint = 1 << 29;
pub const EPOLLONESHOT: c_uint = 1 << 30;
pub const EPOLLET: c_uint = 1 << 31;
+20 -2
View File
@@ -15,6 +15,25 @@ use syscall::{
flag::EVENT_READ,
};
fn epoll_to_event_flags(epoll: c_uint) -> syscall::EventFlags {
let mut event_flags = syscall::EventFlags::empty();
if epoll & EPOLLIN != 0 {
event_flags |= syscall::EventFlags::EVENT_READ;
}
if epoll & EPOLLOUT != 0 {
event_flags |= syscall::EventFlags::EVENT_WRITE;
}
let unsupported = !(EPOLLIN | EPOLLOUT);
if epoll & unsupported != 0 {
eprintln!("epoll unsupported flags 0x{:X}", epoll & unsupported);
}
event_flags
}
impl PalEpoll for Sys {
fn epoll_create1(flags: c_int) -> c_int {
Sys::open(c_str!("event:"), O_RDWR | flags, 0)
@@ -27,8 +46,7 @@ impl PalEpoll for Sys {
epfd,
&Event {
id: fd as usize,
flags: syscall::EventFlags::from_bits(unsafe { (*event).events as usize })
.expect("epoll: invalid bit pattern"),
flags: unsafe { epoll_to_event_flags((*event).events) },
// NOTE: Danger when using something smaller than 64-bit
// systems. If this is needed, use a box or something
data: unsafe { (*event).data.u64 as usize },