socket
stdlib/core/socket.hk: methods on the TcpStream and TcpListener resource types.
Sockets are runtime-managed native resources (HANKI.md §4), like File: the per-actor heap closes one when its last handle goes, and a dropped socket is never leaked; close! releases it eagerly. A socket is single-owner and NOT sendable across actors.
Open a connection with net.connect! or a listener with net.listen!; the methods here read, write, accept, and close. The primitive operations are @intrinsic in sys; this face delegates, and the [net] effect bubbles up through the call.
There is no hermetic test block here: every method bottoms out in a real OS socket via an @intrinsic, with no pure result to assert in the stdlib test pack. These paths are covered end-to-end by 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.
impl TcpStream
read!
def read!(self, max: u32) -> Result<bytes, sys.NetError> [net]
Read once, returning up to max bytes. An empty bytes is EOF (the peer closed). Err(NetError) on an I/O error or a closed socket. @no-doctest: reads a real socket; needs a peer, cannot assert in a doctest
write!
def write!(self, data: bytes) -> Result<i64, sys.NetError> [net]
Write once, returning the count written (which may be less than data.length). For the whole buffer, use net.write_all!. @no-doctest: writes a real socket; needs a peer, cannot assert in a doctest
close!
def close!(self) -> () [net]
Release the descriptor now. Idempotent: dropping the last handle also closes a stream, and an explicit close! is therefore an eager optimisation. @no-doctest: side-effecting close; no return value to assert
impl Stream<TcpStream>
The Stream face: framing code written against S: Stream works over a socket unchanged.
Each body forwards to the inherent method of the same name above, which is not the self-call it looks like: inherent-wins coherence (HANKI.md §10) resolves self.read! to the inherent impl, never back into this one. Forwarding in place of repeating the sys calls is what binds the two faces together: a guard added to the inherent method is then also in force for every caller that arrives through the trait.
read!
def read!(self, max: u32) -> Result<bytes, sys.NetError> [net]
See stream.Stream.read!. @no-doctest: reads a real socket; needs a peer, cannot assert in a doctest
write!
def write!(self, data: bytes) -> Result<i64, sys.NetError> [net]
See stream.Stream.write!. @no-doctest: writes a real socket; needs a peer, cannot assert in a doctest
close!
def close!(self) -> () [net]
See stream.Stream.close!. @no-doctest: side-effecting close; no return value to assert
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.
impl TcpListener
accept!
def accept!(self) -> Result<TcpStream, sys.NetError> [net]
Block until the next inbound connection arrives and return its TcpStream. Err(NetError) on an I/O error. @no-doctest: blocks on a real accept; needs a peer, cannot assert in a doctest
local_address!
def local_address!(self) -> Result<sys.LocalAddress, sys.NetError> [net]
The address this listener is bound to. An ephemeral bind (net.listen!(host, 0)) reports the port the OS chose, which nothing else recovers. @no-doctest: needs a bound port; environment-dependent, cannot assert in a doctest
close!
def close!(self) -> () [net]
Release the bound port now. Idempotent, like TcpStream.close!. @no-doctest: side-effecting close; no return value to assert