Expand description
Minimal WebSocket server (RFC 6455 subset) with JSON envelopes.
Reference infrastructure for the web contributor. Speaks unfragmented text frames only (client frames masked, server frames unmasked) and maps JSON messages onto the config surface:
{"type": "config.get", "id": "1"}
{"type": "config.set", "id": "2", "config": {"led_brightness": 128}}
{"type": "system.get", "id": "3"}
{"type": "ping", "id": "4"}
{"type": "reset", "id": "5"}Replies: {"type": "ok", "id": …, "config"?| "system"? …},
{"type": "pong", "id": …}, {"type": "err", "id": …, "code", "message"}.
config.set takes a ConfigPatch — same merge semantics as
POST /api/config. Fragmented frames, continuations and binary
messages end the session without a close frame (extending that to a
close code like 1003 is the contributor’s call).
Structs§
- Config
SetPayload 🔒 - Payload of a
config.setmessage. - Message
Head 🔒 - First-pass envelope:
{"type": "...", "id": "..."}(extra fields ignored). - Reply 🔒
- Server reply envelope — flat struct (same JSON as a tagged enum).
- System
Info 🔒 - Runtime information payload (
system.get).
Constants§
- GUID 🔒
- RFC 6455 magic GUID for the accept key.
- IDLE_
TIMEOUT 🔒 - Per-frame idle budget — dead peers free their slot.
- MAX_
PAYLOAD 🔒 - Largest client payload accepted (config patches are well below this).
- MAX_
REPLY 🔒 - Largest server payload emitted (config JSON answers).
- OPCODE_
CLOSE 🔒 - Frame opcode: close the connection.
- OPCODE_
PING 🔒 - Frame opcode: ping probe.
- OPCODE_
PONG 🔒 - Frame opcode: pong answer.
- OPCODE_
TEXT 🔒 - Frame opcode: text payload.
Functions§
- format_
mac 🔒 - Format MAC bytes as
AA:BB:CC:DD:EE:FF. - handle_
message 🔒 - Parse and execute one JSON message, then send the reply.
- handshake 🔒
- Complete the HTTP→WebSocket upgrade handshake.
- read_
frame 🔒 - Read one complete client frame (masked, unfragmented) into
buf. - send_
reply 🔒 - Serialize and write one reply frame.
- serve 🔒
- Run one WebSocket session until close; the socket stays borrowed in.
- write_
frame 🔒 - Write one unmasked server frame.