Module net/unix

net/unix
Stability: unstable — it mirrors `std/net/tcp` one-to-one deliberately, which means it also inherits that module's open shapes: no pointer-free read (safe code needs `std/io/bufio`'s `BufReader` or the `Reader` defaults), and no `incoming`, which waits on an async iterator protocol. Two things are specific to this module and not yet decided: a stream cannot report the peer path Rust's `UnixStream::peer_addr` gives, even though the pieces exist one layer down (`std/sys/sockinfo.getpeername` plus `std/sys/unix.sockaddr_un_path`) — so the shape of a Unix address in this API is still unchosen; and there is no `UnixDatagram` beside the stream pair. Freezing follows the tcp decisions plus an address accessor. — stable modules only change additively; this one may still change.

Unix domain sockets — UnixListener / UnixStream (plans/archive/STD_API_AUDIT.md §7 P0 item 10: the sys layer was fully plumbed with no typed wrapper). The API mirrors TcpListener/TcpStream one-to-one, with a filesystem Path where TCP has a SocketAddr.

The LISTENER's socket file is NOT removed on close — like Rust, the caller unlinks it (fs_dir.remove_file); binding to a path that already exists throws AddressInUse.

Every network operation is an io.async future on the single event-loop thread, and kernel failures throw IoExn carrying a NetError (D1) rather than resolving to a negative count.

Stability

unstable — it mirrors std/net/tcp one-to-one deliberately, which means it also inherits that module's open shapes: no pointer-free read (safe code needs std/io/bufio's BufReader or the Reader defaults), and no incoming, which waits on an async iterator protocol. Two things are specific to this module and not yet decided: a stream cannot report the peer path Rust's UnixStream::peer_addr gives, even though the pieces exist one layer down (std/sys/sockinfo.getpeername plus std/sys/unix.sockaddr_un_path) — so the shape of a Unix address in this API is still unchosen; and there is no UnixDatagram beside the stream pair. Freezing follows the tcp decisions plus an address accessor.

Types

UnixListener object
UnixListener

A Unix-domain socket listening on a filesystem path.

Fields

NameTypeDescription
_fdi32
_pathString
_is_closedbool
impl(UnixListener, ...)
bind : (UnixListener) fn(path : Path, io : Io) -> Impl : (Future[Future](UnixListener) IoExn : IoExn)

Bind to a filesystem path and start listening. The path must not already exist (AddressInUse otherwise) and is NOT unlinked on close.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl : (Future[Future](UnixListener) IoExn : IoExn)

accept : (UnixListener) fn(self : UnixListener, io : Io) -> Impl : (Future[Future](UnixStream) IoExn : IoExn)

Accept an incoming connection, returning a new UnixStream.

Parameters

NameTypeNotes
selfUnixListener
ioIo

Returns: Impl : (Future[Future](UnixStream) IoExn : IoExn)

local_path : (UnixListener) fn(self : UnixListener) -> String

The filesystem path this listener is bound to.

Parameters

NameTypeNotes
selfUnixListener

Returns: String

close : (UnixListener) fn(self : UnixListener, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)

Close the stream.

Parameters

NameTypeNotes
selfUnixListener
ioIo

Returns: Impl : (Future[Future](unit) IoExn : IoExn)

fd : (UnixListener) fn(self : UnixListener) -> i32

Get the underlying file descriptor.

Parameters

NameTypeNotes
selfUnixListener

Returns: i32

UnixStream object
UnixStream

A connected Unix-domain stream socket.

Fields

NameTypeDescription
_fdi32
_is_closedbool

Trait Implementations

IoTraits
impl(UnixStream, ...)
connect : (UnixStream) fn(path : Path, io : Io) -> Impl : (Future[Future](UnixStream) IoExn : IoExn)

Connect to a Unix-domain socket at path, returning a new stream.

Parameters

NameTypeNotes
pathPath
ioIo

Returns: Impl : (Future[Future](UnixStream) IoExn : IoExn)

read : (UnixStream) fn(self : UnixStream, buf : *(u8), size : usize, io : Io) -> Impl : (Future[Future](usize) IoExn : IoExn)

Read up to size bytes into buf, resolving to the number actually read. 0 — and only 0 — means the peer closed; a SHORT count is ordinary on a stream socket and is not end-of-stream, so a caller that needs size bytes loops. Awaiting parks this task on the event loop until the kernel has bytes; a failure throws IoExn. The raw pointer needs pragma(Pragma.AllowUnsafe) — safe code uses the Reader defaults (read_to_end, read_to_string) or BufReader(UnixStream).

Parameters

NameTypeNotes
selfUnixStream
buf*(u8)
sizeusize
ioIo

Returns: Impl : (Future[Future](usize) IoExn : IoExn)

write : (UnixStream) fn(self : UnixStream, buf : *(u8), size : usize, io : Io) -> Impl : (Future[Future](usize) IoExn : IoExn)

Write up to size raw bytes from buf, resolving to the number the kernel accepted — which may be LESS than size, so a caller that must deliver everything loops or takes the Writer trait's write_all. Needs pragma(Pragma.AllowUnsafe); write_bytes / write_str / write_string are the safe spellings.

Parameters

NameTypeNotes
selfUnixStream
buf*(u8)
sizeusize
ioIo

Returns: Impl : (Future[Future](usize) IoExn : IoExn)

write_str : (UnixStream) fn(self : UnixStream, data : str, io : Io) -> Impl : (Future[Future](usize) IoExn : IoExn)

Write a str to the stream. Returns the number of bytes written.

Parameters

NameTypeNotes
selfUnixStream
datastr
ioIo

Returns: Impl : (Future[Future](usize) IoExn : IoExn)

write_string : (UnixStream) fn(self : UnixStream, data : String, io : Io) -> Impl : (Future[Future](usize) IoExn : IoExn)

Write a String to the stream. Returns the number of bytes written.

Parameters

NameTypeNotes
selfUnixStream
dataString
ioIo

Returns: Impl : (Future[Future](usize) IoExn : IoExn)

write_bytes : (UnixStream) fn(self : UnixStream, data : ArrayList(u8), io : Io) -> Impl : (Future[Future](usize) IoExn : IoExn)

Write raw bytes from an ArrayList(u8). Returns the count written.

Parameters

NameTypeNotes
selfUnixStream
dataArrayList(u8)
ioIo

Returns: Impl : (Future[Future](usize) IoExn : IoExn)

close : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)

Close the stream.

Parameters

NameTypeNotes
selfUnixStream
ioIo

Returns: Impl : (Future[Future](unit) IoExn : IoExn)

fd : (UnixStream) fn(self : UnixStream) -> i32

Get the underlying file descriptor.

Parameters

NameTypeNotes
selfUnixStream

Returns: i32

impl(UnixStream, IoTraits)
impl(UnixStream, IoTraits)
Methods
read_to_end : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](ArrayList(u8)) IoExn : IoExn)

Parameters

NameTypeNotes
selfUnixStream
ioIo

Returns: Impl : (Future[Future](ArrayList(u8)) IoExn : IoExn)

read_to_string : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](String) IoExn : IoExn)

Parameters

NameTypeNotes
selfUnixStream
ioIo

Returns: Impl : (Future[Future](String) IoExn : IoExn)

flush : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)

Parameters

NameTypeNotes
selfUnixStream
ioIo

Returns: Impl : (Future[Future](unit) IoExn : IoExn)

write_all : (UnixStream) fn(self : UnixStream, buf : *(u8), size : usize, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)

Parameters

NameTypeNotes
selfUnixStream
buf*(u8)
sizeusize
ioIo

Returns: Impl : (Future[Future](unit) IoExn : IoExn)