net
stdlib/extra/net.hk: blocking TCP networking.
A pure-Hanki face over the sys native seam (HANKI.md §4): these functions hold no @intrinsic, they delegate to the raw sys socket primitives, and the [net] effect bubbles up automatically.
Concurrency is one-actor-per-connection over blocking sockets, matching the 1-OS-thread-per-actor model. connect! / listen! return TcpStream / TcpListener resources (GC-closed, never sendable, §4); their methods (read!, write!, accept!, close!, local_address!) live in stdlib/core/socket.hk. Failures carry a specific sys.NetError.
Runs on both tiers (bytecode and LLVM AOT): each runtime implements the raw sys socket primitives over the shared OS layer, and an AOT-built program does real TCP I/O.
No hermetic test block belongs here: this module has no logic of its own, each function being a thin effectful delegation to the sys native seam, and exercising it needs real, non-deterministic OS state that cannot be asserted in the pure stdlib test pack. Coverage is end-to-end through the CLI integration tests and example programs.
TcpStream
TcpStream, or net.TcpStream, is a runtime-managed native resource handle (HANKI.md §4): live native state the per-actor memory manager owns, released when the last handle drops. It is single-owner - never copied, moved across a send - and has no fields of its own, so its methods are its whole surface. A handle is minted by an API that opens one; it is never constructed.
connect!
def connect!(host: string, port: u16) -> Result<TcpStream, sys.NetError> [net]
Open a blocking TCP connection to host:port. @no-doctest: opens a real socket; needs a peer, and cannot assert in a doctest
TcpListener
TcpListener, or net.TcpListener, is a runtime-managed native resource handle (HANKI.md §4): live native state the per-actor memory manager owns, released when the last handle drops. It is single-owner - never copied, moved across a send - and has no fields of its own, so its methods are its whole surface. A handle is minted by an API that opens one; it is never constructed.
listen!
def listen!(host: string, port: u16) -> Result<TcpListener, sys.NetError> [net]
Bind a blocking listening socket to host:port and start accepting. Port 0 binds an ephemeral port; read back which one with the listener's local_address!, the one call that recovers it. @no-doctest: binds a real socket; needs a free port, and cannot assert in a doctest
write_all!
def write_all!<S: Stream>(s: S, data: bytes) -> Result<(), sys.NetError> [net]
Write the whole of data, looping over the single-write primitive until every byte is sent. Ok(()) once the buffer is drained, or the first Err(NetError) a write reports. @no-doctest: writes to a live stream; needs a connected peer, and cannot assert in a doctest