wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
srvthreads.h File Reference

Thread-based worker fan-out over the single-process wired_srvrun_serve_env: one control thread spawns N worker threads sharing the process's address space (unlike srvworkers' fork fan-out), each running its own wired_srvrun_env instance. More...

Go to the source code of this file.

Data Structures

struct  wired_srvthreads_opt
 Fan-out policy: per-worker CPU pinning, optional control-thread pinning, the srvrun knobs copied to every worker, and an optional shared AF_XDP config selecting multi-queue mode. More...

Macros

#define WIRED_SRVTHREADS_MAX   16u
 Max worker threads this domain supports (fixed-size cores[] table).

Functions

int wired_srvthreads_run (u16 port, wired_srvboot_id *id, wired_srvrun_handler h, wired_srvrun_obs obs, const wired_srvthreads_opt *opt)
 Run N worker threads serving port/h until a graceful shutdown is requested (SIGTERM, or SIGHUP-driven cert reload paths configured via id), matching wired_srvworkers_run's contract but over threads instead of processes: shared address space, one shared AF_XDP BPF filter in XDP mode instead of N independent ones.
int wired_srvthreads_parse_cores (const char *s, wired_srvthreads_opt *opt)
 Parse a comma-separated core list ("2,3,4,5") into opt->cores[] and opt->n_cores, e.g.

Detailed Description

Thread-based worker fan-out over the single-process wired_srvrun_serve_env: one control thread spawns N worker threads sharing the process's address space (unlike srvworkers' fork fan-out), each running its own wired_srvrun_env instance.

The control thread blocks on a timed futex wait for the shared shutdown word (wired_srvrun_shutdown_word), then joins every worker before releasing shared resources (the BPF objects, the mmap'd env storage).

Lifecycle: the control thread blocks SIGTERM/SIGHUP, spawns all N workers (which inherit the mask), unblocks and installs the handlers, waits for shutdown, then joins every worker and cleans up. A signal arriving during the blocked window is delivered, pending, once unblocked.

Function Documentation

◆ wired_srvthreads_parse_cores()

int wired_srvthreads_parse_cores ( const char * s,
wired_srvthreads_opt * opt )

Parse a comma-separated core list ("2,3,4,5") into opt->cores[] and opt->n_cores, e.g.

for a –cores CLI flag (example servers each reimplemented this parser separately; this is the shared version).

The empty string is rejected rather than accepted as "0 cores": an empty –cores value is always a caller mistake (the thread-fan-out driver is only selected when –cores is given at all), so treating it as malformed surfaces the mistake instead of silently running zero workers. The same reasoning rejects a leading/trailing/doubled comma: an empty field is not a valid core number, so "2,3," and ",2,3" are malformed rather than silently ignoring the empty field.

Parameters
sNUL-terminated comma-separated list of non-negative base-10 core numbers, e.g. "2,3,4,5"
optdestination; cores[]/n_cores are written on success, left untouched on failure
Returns
1 on success, 0 if s is malformed (non-digit, empty field) or the parsed core count exceeds WIRED_SRVTHREADS_MAX

◆ wired_srvthreads_run()

int wired_srvthreads_run ( u16 port,
wired_srvboot_id * id,
wired_srvrun_handler h,
wired_srvrun_obs obs,
const wired_srvthreads_opt * opt )

Run N worker threads serving port/h until a graceful shutdown is requested (SIGTERM, or SIGHUP-driven cert reload paths configured via id), matching wired_srvworkers_run's contract but over threads instead of processes: shared address space, one shared AF_XDP BPF filter in XDP mode instead of N independent ones.

Parameters
portUDP port every worker serves
idthe fixed server identity; each worker gets its own copy so a SIGHUP reload (handled by wired_srvrun_serve_env internally) never races across workers
hthe application's request responder, passed through unchanged
obsoptional qlog/keylog/cert-reload settings, passed through
optworker CPU pinning, control pinning, srvrun knobs, and optional AF_XDP config
Returns
1 once every worker has exited and cleanup is complete; 0 if opening the shared BPF filter or allocating per-worker env storage fails before any worker starts.