0163:
Native TCP in the runtime through Net, not FFI
Status: Accepted by maintainer 2026-11-07
Context
Net can be granted and narrowed
(Net.none, Net.restrict,
host|port keys in net_host.rs and
hrt_net_covers) but has no socket API; ADR-0095 D7
deferred one. A loopback HTTP server needs listen, accept, read,
write and close. FFI (ADR-0151) could reach socket(2)
with no compiler work, but an extern fn never checks
Net (compare sqlite.open(fs, …), which
takes Fs and ignores it), forces the ffi
ceiling on every app, and routes each interpreter call through the
ffi-host IPC (ADR-0152).
Decision
Add TCP as native cli platform ops, in C
(plugins/cli/native/hrt_net.h) and in the interpreter
(std::net, no crate, no unsafe):
Net.listen(addr) -> result<Listener, CliError>andNet.connect(addr) -> result<Conn, CliError>;addris an IP literal plus port. Both check the grant with the existing cover rule; wildcard binds need an explicit grant.Listener.accept,Listener.port,Listener.timeout(ms),Conn.read(max: Size),Conn.write(bytes), idempotentcloseon both.ListenerandConnare handle kinds withceiling = "", modelled onFile: generation handles,close { release }, use after close traps likeFile.- Each accepted connection gets a total deadline (default 30 s);
reads and writes
pollagainst the remaining time. The monotonic clock helper is shared withhrt_proc.h. - Sockets are
FD_CLOEXEC; writes useMSG_NOSIGNAL(SO_NOSIGPIPEon macOS). CliError.Iocarries a fixed message set (timeout,reset,closed,address in use,refused,limit), identical in both backends.
Consequences
Authority flows Net → Listener →
Conn; libraries that receive handles need no ceiling.
About ten new PlatformOps pass through the usual
eight compiler files. POSIX only; Windows waits for M15.1. Tests
that need a loopback bind print UNVERIFIED and skip
where binding is forbidden.
Alternatives
- FFI socket plugin: no compiler work, but
bypasses
Net, needs thefficeiling, and is slow underinterp. - Socket ops on the agent platform first: no consumer needs them there yet.