std/unix
Unix-domain (AF_UNIX) stream sockets: the right transport for a local daemon, scoped by a filesystem path rather than a port, so there is no port to allocate and no accidental exposure to the network. Dropping a UnixListener closes its fd but leaves the socket file behind; remove it with removeSocketFile.
from "std/unix" import { UnixListener, UnixStream, removeSocketFile }API reference
UnixListener
pub struct UnixListenerA listening unix-domain socket. Closes its fd on drop — but NOT the socket file; call removeSocketFile to clean that up.
UnixListener.accept
fn UnixListener.accept(self: &UnixListener): Result<UnixStream, string>Accept one connection. Inside the green scheduler this yields instead of blocking the runtime — acceptFd is family-agnostic and already green-aware.
UnixListener.bind
fn UnixListener.bind(path: &string): Result<UnixListener, string>Bind to path and listen. bind() fails EADDRINUSE if the file already exists — even one left by a crashed process that never cleaned up — so a stale socket file is removed first. That is the standard dance, and it is why the path should live somewhere only this daemon writes.
UnixStream
pub struct UnixStreamA connected unix-domain socket. Closes its fd on drop.
UnixStream.close
fn UnixStream.close(self: &mut UnixStream): voidClose the socket now rather than at drop: the peer sees EOF here. Afterwards the stream is inert and its drop is a no-op.
UnixStream.connect
fn UnixStream.connect(path: &string): Result<UnixStream, string>Connect to a listening socket at path. Inside the green scheduler this yields rather than blocking the whole runtime.
UnixStream.incoming
fn UnixStream.incoming(self: &UnixStream): Channel<string>Inbound bytes as an iterable channel, pumped on a green task — the same shape as TcpStream.incoming.
UnixStream.recv
fn UnixStream.recv(self: &UnixStream): Result<string, string>Read until the peer closes. Prefer incoming() to consume as bytes arrive.
UnixStream.send
fn UnixStream.send(self: &UnixStream, data: &string): Result<i64, string>UnixStream.take
fn UnixStream.take(self: &mut UnixStream): i32Release the fd to the caller; this stream no longer closes it on drop. @unsafe for the same reason as TcpStream.take.
Functions
removeSocketFile
pub fn removeSocketFile(path: &string): voidRemove a socket file. Dropping a UnixListener closes its fd but leaves the path behind.