Expand description
A minimal, cross-platform event poller for Linux and macOS.
pollio wraps native readiness APIs — epoll
on Linux and kqueue on macOS — behind a small,
uniform Poller trait.
Use it as a building block for event-driven servers, custom async runtimes, or anywhere you want direct control over the OS poller without pulling in a full I/O framework.
§Supported platforms
Other targets are not supported. OsPoller is exported only on Linux and macOS.
§Quick start
use pollio::{EventObject, OsPoller, Poller};
fn main() -> std::io::Result<()> {
let mut poller = OsPoller::new()?;
// Register a listening socket as a "server" FD.
let listen_fd = 0; // replace with your listening socket
poller.add(EventObject::server(listen_fd))?;
loop {
// Block until at least one FD is readable (-1 = no timeout).
let ready = poller.wait(-1)?;
for event in ready {
match event.kind {
pollio::EventKind::Server => { /* accept new connections */ }
pollio::EventKind::Client => { /* read from client */ }
}
}
}
}§Design notes
- Read-only today — registrations use
EPOLLIN(Linux) andEVFILT_READ(macOS). Write readiness and edge-triggered modes are not exposed yet. - FD ownership — pollio does not close registered FDs; you manage their lifecycle.
- Thread safety —
OsPolleris notSync; typical use is a single thread driving the event loop. - Error handling — syscalls surface as
std::io::Errorvialast_os_error(). - No per-call allocation —
Poller::waitreturns a slice backed by a buffer owned by the poller and reused across calls; it is valid only until the nextwaitcall.
Structs§
- Event
Object - A registered file descriptor and its application-defined role.
- OsPoller
Linux - Linux
epollbackend implementingPoller.
Enums§
- Event
Kind - Application-defined role for a registered file descriptor.
Traits§
- Poller
- Platform-agnostic interface for registering file descriptors and waiting for readiness.