code wiki / (root) / nx_websocket_frame.nx

nx_websocket_frame.nx

buildroot/runtime/nx_websocket_frame.nx

8926 B256 linesdepth 2pulls 2 transitivereach 18 importersview sourcekind tooltopic websocket
docsdependenciesstructsconstsfunctions

about

websocket_frame.nx -- RFC 6455 WebSocket frame parser + builder. Parses and emits individual frames. The handshake (HTTP Upgrade + Sec-WebSocket-Key + Sec-WebSocket-Accept) goes in a separate websocket_handshake.nx that will build on sha1.nx + base64.nx + this module. Frame layout (RFC 6455 ยง5.2): 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-------+-+-------------+-------------------------------+ |F|R|R|R| opcode|M| Payload len | Extended payload length | |I|S|S|S| (4) |A| (7) | (16/64) | |N|V|V|V| |S| | (if payload len==126/127) | | |1|2|3| |K| | | +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + | Extended payload length continued, if payload len == 127 | + - - - - - - - - - - - - - - - +-------------------------------+ | |Masking-key, if MASK set to 1 | +-------------------------------+-------------------------------+ | Masking-key (continued) | Payload Data | +-------------------------------- - - - - - - - - - - - - - - - + Opcodes: 0x0 continuation frame 0x1 text frame (UTF-8) 0x2 binary frame 0x8 close 0x9 ping 0xA pong Invariants: WS1 Client -> server frames MUST be masked (RFC). We set this flag on encode per the `masked` arg; callers MUST supply a random 4-byte mask when sending from a client. WS2 Server -> client frames MUST NOT be masked. WS3 Payload length encoding: 7-bit inline (0..125), or 126 + 16-bit extended, or 127 + 64-bit extended. WS4 Masking is reversible -- apply mask twice = identity.

dependencies 1 imports · 12 importers

nx_syscalls.nx nx_websocket_frame.nx nx_friend_video_caller.nx nx_health_eval.nx nx_room_live_gate.nx nx_room_perf_gate.nx nx_sig2_bp_gate.nx nx_sig2_txq.nx nx_signaling_v2.nx nx_signaling_v2_gate.nx nx_websocket_frame_test.nx nx_websocket_stream.nx

diagram shows first 10 each side; +0 more imports, +2 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_friend_video_caller.nxnx_health_eval.nxnx_room_live_gate.nxnx_room_perf_gate.nxnx_sig2_bp_gate.nxnx_sig2_txq.nxnx_signaling_v2.nxnx_signaling_v2_gate.nxnx_websocket_frame_test.nxnx_websocket_stream.nxnx_websocket_stream_test.nxnx_ws_client_session.nx

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

main sys_mmap ws_parse_frame ws_build_header ws_apply_mask

structs

61struct WsFrame

consts

49const WS_MAGIC_65536: i64 = 65536
51const WS_ERR_SHORT: i64 = -1
52const WS_ERR_LONG: i64 = -2
54const WS_OP_CONT: i64 = 0x0
55const WS_OP_TEXT: i64 = 0x1
56const WS_OP_BINARY: i64 = 0x2
57const WS_OP_CLOSE: i64 = 0x8
58const WS_OP_PING: i64 = 0x9
59const WS_OP_PONG: i64 = 0xA

functions

78func ws_parse_frame(buf: *u8, n: i64, off: i64, f: *WsFrame) -> i64
137func ws_apply_mask(buf: *u8, off: i64, n: i64, mask_key: i64) -> i64
159func ws_build_header(out: *u8, cap: i64,
214func main() -> i64