Frontend
Multicore-scheduler worker-target trait.
Implementations bridge the scheduler's lifecycle (pthread
spawn, listener bind, stop flag, drain) with a protocol-
specific accept-and-serve loop. The scheduler does not know
which protocol is running; the frontend's
:meth:run_worker body is what actually serves traffic on
each accepted connection.
Frontends are copied per worker via the trait's
:class:Copyable super-trait; implementations should keep
expensive shared state behind an :class:Pointer or a
similar shared-reference holder so the per-worker copy is
cheap.
Implements Copyable, Movable
run_worker
def run_worker(mut self, listener_fd: Int, mut stopping: Bool, stats_addr: Int, extra_fds: List[Int]) Run this worker's accept-and-serve loop until stopping flips.
- Args
listener_fd: The socket fd this worker accepts on. The scheduler owns the fd; the frontend never closes it.stopping: Heap-shared stop flag; observed every loop iteration. Frontend exits cleanly whenTrue.stats_addr: Heap address of this worker's two-slotInt64stats cell (live-connection snapshot + exit status), or 0 to disable. The frontend forwards it into the reactor loop so the Scheduler can read a real drain report and detect worker crashes.extra_fds: This worker's listeners on any additional bind addresses, one fd per extra address. Empty for the single-address case. A frontend that cannot accept on more than one address must not silently ignore a non-empty list -- an address the caller bound would then never be served.
requires_per_worker_listener
def requires_per_worker_listener(self) -> Bool Return True if this frontend cannot share a single listener fd.
Some serving paths (notably the io_uring buffer-ring
path) need each worker to have its own SO_REUSEPORT
listener -- the kernel-side fan-out happens at accept
time and a shared listener with EPOLLEXCLUSIVE would
funnel every accept event through one entry. The
scheduler honours this signal: when it returns True
the scheduler always binds per-worker SO_REUSEPORT
listeners, ignoring the FLARE_REUSEPORT_WORKERS=0
env knob.
Default false: the frontend is fine with whichever listener strategy the scheduler picks.