#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Event {
None,
Read,
Write,
Error,
EdgeTriggered,
HangUp,
OneShot,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Events(u32);
impl std::fmt::Display for Events {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{:08X}", self.0)
}
}
impl Events {
pub fn new() -> Self {
Self { 0: 0 }
}
pub fn none(mut self) -> Self {
self.0 = 0;
self
}
pub fn read(mut self) -> Self {
self.0 |= 1 << Event::Read as u32;
self
}
pub fn write(mut self) -> Self {
self.0 |= 1 << Event::Write as u32;
self
}
pub fn error(mut self) -> Self {
self.0 |= 1 << Event::Error as u32;
self
}
pub fn is_none(self) -> bool {
self.0 == 0
}
pub fn has_read(self) -> bool {
(self.0 & (1 << Event::Read as u32)) != 0
}
pub fn has_write(self) -> bool {
(self.0 & (1 << Event::Write as u32)) != 0
}
pub fn has_error(self) -> bool {
(self.0 & (1 << Event::Error as u32)) != 0
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct SysError(i32);
impl std::fmt::Display for SysError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, r#"Code={}, Reason="{{}}")"#, self.0)
}
}
impl std::error::Error for SysError {}
impl From<i32> for SysError {
fn from(val: i32) -> Self {
Self { 0: val }
}
}
impl Into<i32> for SysError {
fn into(self) -> i32 {
self.0
}
}
impl SysError {
pub fn last() -> Self {
unsafe {
Self {
0: *(libc::__errno_location()),
}
}
}
}
#[cfg(target_os = "linux")]
pub mod epoll;
#[cfg(target_os = "linux")]
#[doc(inline)]
pub use epoll::{EventContext, EventData, Poller};
#[cfg(not(target_os = "linux"))]
pub mod select;
#[cfg(test)]
mod tests {}