Expand description
Epoll runtime implementation for WASIX.
This module centralizes epoll internals behind a small crate-internal API used
by epoll_create, epoll_ctl, and epoll_wait.
§Architecture
The implementation uses:
EpollState: global state for one epoll fd (subscriptions, ready queue, notifier).EpollSubState: per-watched-fd state (pending_bits,enqueued,generation, metadata).EpollHandler: producer-side interest handler attached to socket/pipe/notification sources.
§Important flows
§Registration (epoll_ctl ADD/MOD/DEL)
epoll_ctlcreates/removesEpollSubStateentries inEpollState.subscriptions.- On ADD/MOD,
register_epoll_handler()installs anEpollHandleron the target fd. - Guard ownership is stored in
EpollSubState.joins; dropping a subscription drops guards and unregisters handlers.
§Producer path (EpollHandler::push_interest)
- Convert
InterestTypeto a readiness bit. - Set
pending_bitsatomically. - Enqueue exactly one
ReadyItemper subscription whileenqueued == true. - Wake one waiter via
Notify.
§Consumer path (drain_ready_events used by epoll_wait)
- Pop
ReadyItemfrom the ready queue. - Resolve the current subscription and drop stale/missing entries.
- Atomically take readiness bits, clear
enqueued, and map bits to output events. - Repair queue state if a race set new bits during draining.
§Correctness model
pending_bitsis the source of truth for unread readiness.enqueueddeduplicates queue presence per subscription.generationprevents stale queued entries from emitting after DEL/MOD.- Consumer logic tolerates stale queue entries and must never await while holding locks.
Structs§
Constants§
- ERR_BIT 🔒
- HUP_BIT 🔒
- READABLE_
BIT 🔒 - WRITABLE_
BIT 🔒
Statics§
- EPOLL_
EMPTY_ 🔒DEQUEUE_ ENTRIES - EPOLL_
ENQUEUE_ 🔒ATTEMPTS - EPOLL_
ENQUEUE_ 🔒DEDUPE_ HITS - EPOLL_
STALE_ 🔒GENERATION_ DROPS
Functions§
- drain_
ready_ 🔒events - Drains ready items into
(EpollFd, readiness)events up tomaxevents. - epoll_
empty_ 🔒dequeue_ entry - Increments empty dequeue metric.
- epoll_
mask_ 🔒to_ pending_ bits - epoll_
stale_ 🔒generation_ drop - Increments stale-generation dequeue metric.
- epoll_
type_ 🔒to_ pending_ bit - Maps epoll readiness flags into internal pending-bit positions.
- interest_
to_ 🔒pending_ bit - Maps a source interest callback variant into the internal pending-bit mask.
- pending_
bits_ 🔒to_ events - Converts consumed pending bits into caller-visible epoll events.
- prime_
immediate_ 🔒writable_ if_ applicable - register_
epoll_ 🔒handler - Registers an epoll interest handler on the watched fd and returns a guard.
- repair_
ready_ 🔒queue_ after_ drain - Re-enqueues a subscription if new pending bits arrived during/after consumer drain.