nx_h2_serve_multi.nx
buildroot/runtime/nx_h2_serve_multi.nx
about
nx_h2_serve_multi.nx -- TUTOR-BOOTSTRAP SCAFFOLD (Claude, authored under the B1
rung(6) PERSISTENT-MULTI-STREAM step of the R4-H2 HTTP/2-transport ladder), NOT
credited as team self-authoring (back-fill via the emitter-of-emitters once the
daemon-from-spec organ exists -- X-AUT-006c/e/f).
THE PERSISTENT MULTI-STREAM ALPN-h2 SERVER CONNECTION-DRIVER organ (single
responsibility: SERVE >1 REQUEST STREAM on ONE already-accepted, KEPT-ALIVE h2
connection over OUR sovereign TLS 1.3). This is the EVOLUTION of nx_h2_serve.nx
h2_serve_connection, which serves exactly ONE stream then sends GOAWAY + closes
(so each external curl --http2 GET needs a FRESH TCP connection; num_connects=1
per request). The persistent driver here:
- does NOT send GOAWAY after each stream (GOAWAY ends the whole connection),
- LOOPS reading TLS records, COMPACTING consumed frame bytes out of a bounded
buffer (so the buffer survives many sequential requests), responding to EACH
request HEADERS frame on ITS OWN client-chosen odd stream id (1,3,5,...),
- stops when (a) the client closes the connection (read EOF -- the clean end
of a sequential keep-alive burst), (b) the client sends GOAWAY, or (c) the
served count reaches the caller's max_streams cap (honest backstop), and
- sends ONE GOAWAY(last_stream_id) at the very end, then the LM-023 graceful
shutdown(SHUT_WR)+drain so the peer reads every response (close-with-unread
RX would RST the peer).
MEASURED EXCEED (vs h2_serve_connection): an external curl given K same-origin
URLs REUSES ONE h2 connection (total num_connects across the K transfers = 1)
where the single-stream driver forces K separate connections. The persistent
driver thus serves the SAME K requests on 1/K the TCP connections.
WHY A NEW ORGAN (rule 9 single-responsibility + rule 25 build-don't-strip):
h2_serve_connection is GATED GREEN and REUSED by the proven N=3 daemon; it is
left BYTE-UNTOUCHED. Persistent multi-stream is a DISTINCT connection
lifecycle (keep-alive read loop with frame compaction + per-stream response +
single terminal GOAWAY) -- folding it into the single-stream driver would
collapse "serve-one-then-close AND serve-many-keep-alive" into one organ (the
'and' split-test fails). So this organ is a SIBLING driver composing the same
proven framing + tls transport stones.
DRIVER CONTRACT:
h2_serve_connection_multi(ss_fd, srand, sxpriv, cert_der, cert_len, ed_priv,
body, blen, max_streams) -> i64
The session is established INSIDE via run_h2_ed25519 (handshake inputs are
caller args; single-responsibility -- caller hands an already-ACCEPTED fd +
dependencies 5 imports · 2 importers
imports: nx_syscalls.nxnx_h2_server.nxnx_tls13_server_session_run_h2.nxnx_tls13_server_session_app_data.nxnx_tls13_read_record_from_fd.nx
imported by: _h2_multistream_curl_daemon.nx_h2_multistream_interop_gate.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 66 | const NX_MAGIC_16384: i64 = 16384 |
| 67 | const NX_MAGIC_16645: i64 = 16645 |
| 68 | const NX_MAGIC_2048: i64 = 2048 |
| 71 | const NX_H2_SETTINGS_MAX_CONCURRENT_STREAMS: i64 = 0x03 |
| 79 | const NX_H2_MAX_CONCURRENT_STREAMS: i64 = 100 |
functions
| 84 | func msrv_send_record(ss: *Tls13ServerSession, ss_fd: i64, plain: *u8, plen: i64) -> i64 |
| 100 | func msrv_respond_stream(ss: *Tls13ServerSession, ss_fd: i64, sid: i64, body: *u8, blen: i64) -> i64 called by 1: h2_serve_connection_multi calls 4: sys_mmaph2_frame_write_headersh2_frame_write_datamsrv_send_record |
| 111 | func h2_serve_connection_multi( |
| 260 | func main() -> i64 |