code wiki / (root) / nx_websocket_upgrade_test.nx

nx_websocket_upgrade_test.nx

buildroot/runtime/nx_websocket_upgrade_test.nx

9026 B191 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind gate/prooftopic websocket
docsdependenciesstructsconstsfunctions

about

nx_websocket_upgrade_test.nx -- KAT for the server-side upgrade driver. Uses sys_pipe2 to simulate a TCP fd: write a hand-crafted HTTP/1.1 upgrade request into the pipe, run the upgrade handshake, then read what got written back to verify the 101 response (RFC 6455 ยง4.2.2). The "fd" handed to the driver is a duplex socketpair would be ideal, but two unidirectional pipes work: one for client->server (request), one for server->client (101 response). The driver needs to read AND write on the same fd, so we use a Unix domain socketpair via the already-shipped sys_pipe2 trick (or socketpair if available). For this test we use a SINGLE pipe for each direction and tie them together via two separate calls. Concrete shape: Test writes request bytes into pipe1.write_end. Driver reads from pipe1.read_end + writes 101 to pipe2.write_end. Test reads from pipe2.read_end. That requires the driver to take SEPARATE read_fd + write_fd... but our API takes a single fd. So we wrap by having the test: - Write the request bytes first (full request) - sys_close the write end (signals EOF after request) - Pass the read end to the driver - For the WRITE side, give the driver a separate write-pipe But the driver's _wsu_write_n uses sys_write(fd, ...) on the same fd it reads from. So to test the FULL flow we need a true socket pair. Use sys_socketpair if shipped, otherwise document. For this initial KAT we test ONLY the validation logic: feed a full request, verify the read+parse path returns OK and writes a 101 with the right Sec-WebSocket-Accept. Read+write on the same fd works when both ends of a sys_pipe2 stay open during the call -- write happens to the SAME pipe (loopback) and the test reads it after. expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_websocket_upgrade.nx nx_websocket_upgrade_test.nx

imports: nx_syscalls.nxnx_websocket_upgrade.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap sys_pipe2 sys_write sys_close nx_ws_upgrade_handshake _wsu_read_headers sys_read _wsu_find_header_end _wsu_eq_cs _wsu_find_byte _wsu_eol sys_mmap ↻ _wsu_find_header _wsu_eq_ci _wsu_tolower _wsu_skip_ws _wsu_eol ↻ _wsu_next_line _wsu_eq_ci ↻ ws_accept sys_mmap ↻ ws_guid sha1 sys_mmap ↻ sha1_process_block if_ge b64_encode b64_enc_char _wsu_write_n sys_write ↻

structs

none

consts

none

functions

42func main() -> i64