Skip to content

Server flags

The same server can run single-threaded, on several threads, on several processes, or on AF_XDP. wired_srvdriver_parse reads that choice from the command line. This page runs two worker threads (--cores 0,1, one per CPU) and takes three TLS handshakes.

Code

main.c
#define WIRED_MAIN
#include "wired.h"
/* Unused here: the client below only does TLS handshakes, no requests. */
static int on_request(
void* ctx,
const wired_h3reqdrive_req* req,
u64 offset,
wired_obuf* body_out,
const char** content_type,
int* more,
u64* total_size) {
(void)ctx;
(void)req;
(void)offset;
(void)body_out;
(void)content_type;
(void)more;
(void)total_size;
return 0;
}
int wired_main(int argc, char** argv) {
/* The same fixed demo identity as the HTTP/3 hello page. */
static wired_srvboot_demo_keys keys;
wired_srvboot_id id;
wired_srvboot_demo(&id, &keys, 0x50, "guide-h3");
/* --port, --workers, --cores, --ifindex, ... pick and configure a driver. */
wired_srvdriver_opt opt = {0};
if (!wired_srvdriver_parse(argc, argv, &opt)) {
wired_log_str("bad flags\n");
return 2;
}
wired_srvrun_handler h = {.cb = on_request};
wired_srvrun_obs obs = {0};
return wired_srvdriver_run(&id, h, obs, &opt) < 0 ? 1 : 0;
}

Output

Terminal window
$ ./quic-server-flags --port 4433 --cores 0,1
conn closed by peer (CONNECTION_CLOSE)
conn closed by peer (CONNECTION_CLOSE)
conn closed by peer (CONNECTION_CLOSE)
Terminal window
$ probe tls 127.0.0.1:4433 3
handshake 1 ok: TLS 1.3
handshake 2 ok: TLS 1.3
handshake 3 ok: TLS 1.3
  • wired_srvdriver_parse(argc, argv, &opt) reads --port, --workers, --cores, --ifindex, --pin-core and related flags into wired_srvdriver_opt. It returns 0 for a bad value or a conflicting combination, such as --workers with --cores.
  • wired_srvdriver_run(&id, h, obs, &opt) starts the driver opt.kind names: a single process, --workers N forked processes, --cores 0,1 (one thread per listed CPU), or --ifindex AF_XDP.
  • The identity and handler are the same as in the HTTP/3 hello page.