On this page

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):

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