Socket
TCP socket module: a clean interface over the tcp_* builtins.
Wraps the low-level tcp_connect / tcp_send_all / tcp_recv_all / tcp_close builtins with an ergonomic Result-based API. All operations are synchronous. For async use, wrap in task_spawn.
File descriptors are plain Int values. Always call Socket.close when done, ideally via Socket.with_connection which ensures cleanup.
Public API: Socket.connect(host, port) : Result(Int, SocketError) Socket.write(fd, data) : Result((), SocketError) Socket.recv(fd, max_bytes) : Result(String, SocketError) Socket.recv_timeout(fd, max, ms) : Result(String, SocketError) Socket.close(fd) : () Socket.with_connection(host, port, f) : Result(a, SocketError) Socket.error_message(e) : String
Types
Functions
Close fd. Silently ignores errors (already-closed fds, etc.).
Open a TCP connection to host:port. Returns Ok(fd) or Err.
Return a human-readable description of a SocketError.
Receive up to max_bytes from fd (no timeout). Returns Ok(data) or Err.
Receive up to max_bytes from fd with timeout_ms timeout (0 = no timeout).
Open a connection, run f(fd), then close. fd is always closed.
Write all bytes of data over fd. Returns Ok(()) or Err(WriteFailed(...)).