std1.0.0-beta-7 SafeC docs

std :: sched::reactor

Struct std::Reactor

#include <std/sched/reactor.h> source

struct Reactor {
    int kq;
    struct Vec<struct SigFdEntry> sigfds;
    struct Vec<struct WatchedFd> watched;
}

Fields

§int kqsource

underlying OS event queue fd (kqueue fd, epoll fd, or unused on the Win32/WSAPoll backend)

§struct Vec<struct SigFdEntry> sigfdssource

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.

§struct Vec<struct WatchedFd> watchedsource

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

§static struct Reactor new()source · definition

A reactor with no OS event queue yet (kq = -1): call init() next, and drop() it when done.

§int init()source · definition

Opens the underlying OS event queue. Returns 0 on success, -1 on failure (check errno).

§void add(int fd, int filter)source · definition

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().

§void remove(int fd, int filter)source · definition
§int poll(&TaskScheduler sched, long long timeout_ms)source · definition

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 · definition

Waits 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().

§void drop()source · definition

close_(): a Reactor is a Drop type, so a local one is dropped (or closed and then dropped) on every path.