Module
std.poll — one wait over files, sockets and signals, answering every ready entry once. Stability tier: core.
Keep one owned Waiter across the server loop: open, add_file, add_socket and add_listener; modify interests as output queues fill or empty; remove entries before closing their handles; close the waiter. Files and sockets share one wait with signal meanings and a monotonic deadline. A meaning never hides ready handles.
The readiness set opens lazily on the first valid add or wait. Native Linux and macOS hold it in the kernel: O(ready) per wait, plus O(polled) for descriptors the kernel set cannot hold (regular files included). The checked machine keeps a set of its own and scans O(N). Where set opening answers unsupported, a list feeds os_wait_ready: O(N), up to two elements per entry. Results follow runtime order, unspecified for a persistent set and key order for the list fallback. A persistent-set wait neither sorts results nor scans the held keys.
A waiter holds at most 256 entries, matching the smallest serving runtime's set bound. Registration 257 answers io without changing it; shape and duplicate errors still answer invalid first. The capacity refusal makes no host call and does not replace os_error's last result. A runtime handle close removes its registration; remove before close to release std's bookkeeping and reuse its key.
READ and WRITE are interests and facts; HANGUP and ERROR are real host facts, returned with the applicable interest. A read loop tests READ and lets its read name the end: eof, closed, or a pty master's io on Linux. A non-blocking writer uses fs.write_some or net.write_some, retains unsent bytes and enables WRITE only while its queue has bytes. busy means wait for room and retry, never discard the unsent bytes.
Linux and macOS serve every combination. Windows preserves its narrow sockets-only READ wait, no meanings, through net.wait (only READ facts known there), and its empty deadline-only waits with no meanings. Other fallback combinations use os_wait_ready and its host refusal. PAX uses the static Linux binary. lupin 0.1.62 refuses readiness calls at run by builtin name, not a caught unsupported error mark.
Capability exec for sets/waits, net for the Windows narrow fallback, and Clock for its positive deadlines. Fallback adds validate through fs metadata or a zero-deadline net look (fs or net respectively); they publish no key before validation. All host calls are refused at comptime. open, len and constants are pure. modify/remove retain {invalid, io}: unsupported from a set change is explicitly handled as io. A set that opened cannot meet it on that same host; tests/poll/set_mutation.lu holds that fact.
Types and traits
struct · Source line 105
pub struct Waiter { set: int, kinds: List[int], handles: List[int], interests: List[int], count: int, }
An owned waiter holding at most 256 entries, named by stable keys. Fields are bookkeeping, not an API for constructing a waiter: set is -1 before acquisition, -2 for the list fallback, else a runtime set. Entry handles remain the caller's.
struct · Source line 114
pub struct Ready { key: int, facts: int, }
One ready entry: its key and READ/WRITE/HANGUP/ERROR facts.
struct · Source line 122
pub struct Events { meaning: int, ready: List[Ready], }
Every ready entry once, in runtime order (unspecified for a set), and one meaning taken off the queue, or 0. Both may arrive together. Empty ready and meaning 0 means the deadline passed.
Functions and methods
fn · Source line 137
pub fn open() -> Waiter ! {io}
A new empty waiter; acquire its host set lazily at add/wait. Pure construction, but this edition's comptime engine cannot materialize its List fields ([type.list.lit.value]). The reserved io row stays unchanged; acquisition failures belong to the first add/wait.
var w = poll.open()?
poll.len(w) == 0
poll.close(take w)?
fn · Source line 148
pub fn len(w: Waiter) -> int
The number of entries added and not removed. Total and pure.
fn · Source line 155
pub fn close(take w: Waiter) -> () ! {io}
Close the set, consuming w, leaving its entry handles open. io for a failed close or forged set. Capability exec when acquired; comptime refuses the host call. A never-acquired or fallback waiter has no set.
fn · Source line 232
pub fn add_file(mut w: Waiter, f: fs.File, interest: int) -> int ! {invalid, io, unsupported}
Add f with READ, WRITE or both; return the lowest free key, stable until removal. invalid for duplicates, invalid interest, negative or wait-marked handles. io for capacity (256), a closed/forged handle or host failure; unsupported where registration is unsupported. Remove before closing f. Capability exec for a set, fs for fallback handle validation; refused at comptime.
fn · Source line 240
pub fn add_socket(mut w: Waiter, s: net.Socket, interest: int) -> int ! {invalid, io, unsupported}
Add a TCP or Unix stream with READ, WRITE or both. Keys and rows are add_file's; file and net handle numbers belong to separate tables. Capability exec for a set, net for fallback handle validation; refused at comptime.
fn · Source line 247
pub fn add_listener(mut w: Waiter, l: net.Listener) -> int ! {invalid, io, unsupported}
Add l with READ (a pending connection). Keys and rows are add_file's. Capability exec for a set, net for fallback handle validation; refused at comptime.
fn · Source line 275
pub fn modify(mut w: Waiter, key: int, interest: int) -> () ! {invalid, io}
Change key's interest to READ, WRITE or both. invalid for a non-live key, bad interest, or WRITE on a listener; io for a runtime failure. An opened set cannot answer unsupported on this host; that delegate outcome is handled as io. Capability exec when acquired; refused at comptime. No host call is needed on the list fallback.
fn · Source line 289
pub fn remove(mut w: Waiter, key: int) -> () ! {invalid, io}
Remove key before closing its handle; the key becomes free. invalid for a non-live key; io for a runtime failure, including an already closed handle removed by the runtime. An opened set cannot answer unsupported on this host; that delegate outcome is handled as io. Capability exec when acquired; refused at comptime.
fn · Source line 330
pub fn wait(mut w: Waiter, meanings: int, deadline_ms: int) -> Events ! {invalid, io, unsupported}
Wait for every ready entry and one signal meaning, together. meanings is 0 or a set listened for through std.signal; deadline_ms is 0 for a look, -1 for no deadline, otherwise monotonic milliseconds. A timeout is never answered early; ready entries may answer before the deadline. Level-triggered: readiness remains until consumed.
invalid for a deadline below -1, a non-listenable meaning bit, or an empty waiter with no meanings and no deadline. io for a host failure; unsupported where the host or tier does not serve the call. Linux and macOS serve files+sockets, signals+sockets, socket WRITE and files without meanings. Windows retains its narrow socket READ case and empty no-meaning deadline waits. Capability exec (net on that narrow fallback, plus Clock for positive deadlines); refused at comptime. Never traps for a host failure.
var w = poll.open()?
let ev = poll.wait(mut w, 0, 0)?
poll.close(take w)?
ev.ready.len == 0
ev.meaning == 0