flare.uds
flare.uds — Unix domain socket primitives.
UDS gives a flare-process two doors that TCP doesn't:
- Sidecar IPC. A process pinned to a single host can talk to a
local sibling (logging agent, metrics scraper, in-rack mesh
sidecar) without going through the network stack — no ARP, no
IP routing, no TCP retransmit timer, no TLS. ~3-5x lower latency
than
127.0.0.1TCP for short request/response pairs. - Filesystem-permission AAA.
chmod/chownon the socket path are the entire access-control story; no per-message token, no TLS client cert. The kernel enforces it beforeaccept(2)ever fires.
The wire shape is a stream-oriented byte pipe identical to
flare.tcp: same read / write / write_all /
shutdown semantics. The differences are address-family-only:
- The "address" is a filesystem path (Linux: 108 bytes; macOS BSD: 104 bytes — flare uses 108 in the public surface but enforces the BSD-shorter limit on macOS).
SO_REUSEADDRdoesn't apply (UDS doesn't have a port to contend on); rebinding to the same path requires the previous socket to beunlink(2)'d.UnixListener.binddoes this cleanup automatically whenunlink_existing=True(default).TCP_NODELAYdoesn't apply (no Nagle on UDS).SO_REUSEPORTworks on Linux >= 4.5 for UDS too — the multi-worker shared-listener scheduler in :mod:flare.runtime.schedulercan balance UDS connections across worker pthreads exactly the way it does for TCP.
Public surface:
- :class:
UnixListener— bound + listening AF_UNIX socket. - :class:
UnixStream— connected AF_UNIX byte stream. - :func:
accept_uds_fd— accept on a borrowed listener fd (multi-worker scheduler hand-off path; mirrors :func:flare.tcp.accept_fd). - :class:
FrameMux— multiplexed framed transport over oneUnixStream: many logical streams demuxed byrequest_id, with :class:FrameDemux/ :class:Frame/ :class:FrameKindand the pure :func:encode_frame/ :func:decode_framecodec.
Example:
from flare.uds import UnixListener
var l = UnixListener.bind("/tmp/flare-sidecar.sock")
while True:
var s = l.accept()
s.write_all("hello".as_bytes())
s.close()
Out of scope today:
- Abstract namespace addresses (Linux-only