hanki

net

stdlib/extra/net.hk: blocking TCP and pathname Unix-domain 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 I/O direction over blocking sockets, matching the 1-OS-thread-per-actor model. A full stream's split! produces the independently movable handles that make this possible. connect! / listen! return TcpStream / TcpListener or UnixStream / UnixListener resources (resource-managed, movable and never copied, §4); their methods (read!, write!, split!, 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 socket I/O. On a non-Unix host the Unix-domain entry points return NetError.Other.

The private default policy is pure and pinned below. Exercising the actual deadline needs real OS state. Transport behavior is covered end-to-end by the CLI integration tests.

defaultdeadline_ms

def _default_deadline_ms() -> i32

The one-minute client default. Kept private so the public API has one policy value and no constant a caller could mistake for an independently tunable runtime setting.

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 with a 60-second deadline for resolution, connect, and later reads/writes. Use connect_with_deadline! to choose another initial budget, or TcpStream.set_deadline! to reset it. @no-doctest: opens a real socket; needs a peer, and cannot assert in a doctest

connectwithdeadline!

def connect_with_deadline!(host: string, port: u16, timeout_ms: i32) -> Result<TcpStream, sys.NetError> [net]

Open a blocking TCP connection under one absolute wall-clock deadline. Negative values clamp to an immediate poll; an already-ready operation may still complete without waiting. @no-doctest: opens a real socket; needs a peer

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

UnixStream

UnixStream, or net.UnixStream, 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_unix!

def connect_unix!(path: string) -> Result<UnixStream, sys.NetError> [net]

Open a pathname Unix-domain connection with a 60-second deadline for connect and later reads/writes. Use connect_unix_with_deadline! to choose another initial budget, or UnixStream.set_deadline! to reset it. Abstract-namespace addresses are intentionally out of scope. @no-doctest: opens a real local socket; needs a peer

connectunixwith_deadline!

def connect_unix_with_deadline!(path: string, timeout_ms: i32) -> Result<UnixStream, sys.NetError> [net]

Open a pathname Unix-domain connection under one absolute wall-clock deadline. Negative values clamp to an immediate poll; an already-ready operation may still complete without waiting. @no-doctest: opens a real local socket; needs a peer

UnixListener

UnixListener, or net.UnixListener, 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_unix!

def listen_unix!(path: string) -> Result<UnixListener, sys.NetError> [fs_write, net]

Bind a pathname Unix-domain listener. An existing path is never unlinked first and makes this fail. Closing or dropping the returned listener leaves the pathname in place; remove it explicitly with fs.delete! once no other process can replace it concurrently. @no-doctest: creates a real filesystem socket; environment-dependent

write_all!

def write_all!<S: WriteStream>(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