diff --git a/src/header/sys_epoll/linux.rs b/src/header/sys_epoll/linux.rs index 4f17c0c19bf93b6ac8606968a37d2b5a45e2d352..0026bcde10ea34b7de5638b771d4a2aa1d179f22 100644 --- a/src/header/sys_epoll/linux.rs +++ b/src/header/sys_epoll/linux.rs @@ -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; diff --git a/src/header/sys_epoll/redox.rs b/src/header/sys_epoll/redox.rs index ecba6a3947622ae97eb4d6a534759748953b61f7..d2ef20d44cf7117b605e7e4f1045021b1256a99f 100644 --- a/src/header/sys_epoll/redox.rs +++ b/src/header/sys_epoll/redox.rs @@ -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; diff --git a/src/platform/redox/epoll.rs b/src/platform/redox/epoll.rs index 9ec4be65dbf9c2af7767e126ed71476087cd581a..fd7e492cce1f77a238309dfaf85eaec7b5c2aa6c 100644 --- a/src/platform/redox/epoll.rs +++ b/src/platform/redox/epoll.rs @@ -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 },