networking
Length-Prefixed Framing and Local IPC
Length-Prefixed Framing and Local IPC
A stream has no message boundaries, so each message gets a length prefix. The reader checks the declared length against a maximum before allocating or reading the body, and the writer refuses oversize frames before sending.
The maximum belongs to the channel, not to the codec. A small cap suits encrypted peer chunks (65535 bytes here). Local IPC carrying whole payloads needed far more (64 MiB). Sharing one constant broke the larger use. Past a point, raising the cap is the wrong fix: have the service write the file and send only the path. An oversize request should get a typed error, not a closed connection.
Chunk size must leave room for envelope and authentication tag. One chunk constant, owned by the layer that enforces the limit.
Local IPC across platforms:
- Unix: a domain socket, mode 0600. Path length is limited (104 bytes on macOS), so long temp directories break tests.
- Windows: a named pipe. The name is global, so include the user. Socket-style timeouts don't apply; a deadline needs polling with
PeekNamedPipe. - Set a read deadline for request frames so a silent client can't hold a worker, and clear it for long-lived event subscriptions.
- Serve with more than one worker.
Used in: Ferry