Skip to main content

Crate pollio

Crate pollio 

Source
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

PlatformBackendType alias
LinuxepollOsPoller
macOSkqueueOsPoller

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) and EVFILT_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 safetyOsPoller is not Sync; typical use is a single thread driving the event loop.
  • Error handling — syscalls surface as std::io::Error via last_os_error().
  • No per-call allocationPoller::wait returns a slice backed by a buffer owned by the poller and reused across calls; it is valid only until the next wait call.

Structs§

EventObject
A registered file descriptor and its application-defined role.
OsPollerLinux
Linux epoll backend implementing Poller.

Enums§

EventKind
Application-defined role for a registered file descriptor.

Traits§

Poller
Platform-agnostic interface for registering file descriptors and waiting for readiness.