Struct std::Reactor
struct Reactor {
int kq;
struct Vec<struct SigFdEntry> sigfds;
struct Vec<struct WatchedFd> watched;
}Fields
underlying OS event queue fd (kqueue fd, epoll fd, or unused on the Win32/WSAPoll backend)
epoll has no native "wake on signal" filter the way kqueue's EVFILT_SIGNAL does — reactor_epoll.sc's SCHED_SIGNAL support instead converts each registered signal into a readable fd via signalfd() and epoll-polls that, tracking the signum -> signalfd mapping here (elements are struct SigFdEntry) so remove()/poll() can find/close the right fd and translate a ready signalfd back into its original signal number. Left empty and unused by the kqueue and Win32 backends, which handle (or don't support) signals differently.
reactor_win32.sc's registration table (elements are struct WatchedFd). Unlike kqueue/epoll, WSAPoll has no persistent OS-side registration — the full set of watched (fd, filter) pairs must be rebuilt and re-passed on every poll() call, so Reactor::add/remove maintain that set here themselves. Left empty and unused by the kqueue and epoll backends, which rely on real OS-side registration instead.
Methods
A reactor with no OS event queue yet (kq = -1): call init() next, and drop() it when done.
Opens the underlying OS event queue. Returns 0 on success, -1 on failure (check errno).
Registers persistent, level-triggered interest in 'fd' becoming ready for 'filter' — once added, it stays registered (no per-event re-arming needed) until a matching remove().
Waits up to 'timeout_ms' for events (0 = return immediately if none are pending, negative = wait indefinitely), then calls sched->unblock_fd() for every task waiting on a now-ready (fd, filter). Returns the number of OS events processed (not the number of tasks unblocked, which may differ if several tasks await the same fd).
generic<T> int poll_events(fn void(?&T, int, int) on_ready, ?&T ctx, long long timeout_ms)source · definitionWaits like poll(), but hands every ready (fd, filter) to on_ready(ctx, fd, filter) instead of a TaskScheduler — the hook other schedulers drive the reactor through (std/async's IoDriver wakes the futures waiting on that fd). For SCHED_SIGNAL, 'fd' is the signal number. Returns the number of OS events processed. poll() is this with a callback that calls sched->unblock_fd().
close_(): a Reactor is a Drop type, so a local one is dropped (or closed and then dropped) on every path.