Module net/unix
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
A Unix-domain socket listening on a filesystem path.
Fields
| Name | Type | Description |
|---|---|---|
_fd | i32 | |
_path | String | |
_is_closed | bool |
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
| Name | Type | Notes |
|---|---|---|
path | Path | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixListener | |
io | Io |
Returns: Impl : (Future[Future](UnixStream) IoExn : IoExn)
local_path : (UnixListener) fn(self : UnixListener) -> StringThe filesystem path this listener is bound to.
Parameters
| Name | Type | Notes |
|---|---|---|
self | UnixListener |
Returns: String
close : (UnixListener) fn(self : UnixListener, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)fd : (UnixListener) fn(self : UnixListener) -> i32A connected Unix-domain stream socket.
Fields
| Name | Type | Description |
|---|---|---|
_fd | i32 | |
_is_closed | bool |
Trait Implementations
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
| Name | Type | Notes |
|---|---|---|
path | Path | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
buf | *(u8) | |
size | usize | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
buf | *(u8) | |
size | usize | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
data | str | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
data | String | |
io | Io |
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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
data | ArrayList(u8) | |
io | Io |
close : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](unit) IoExn : IoExn)fd : (UnixStream) fn(self : UnixStream) -> i32impl(UnixStream, IoTraits)
impl(UnixStream, IoTraits)
Methods
read_to_end : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](ArrayList(u8)) IoExn : IoExn)Parameters
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
io | Io |
Returns: Impl : (Future[Future](ArrayList(u8)) IoExn : IoExn)
read_to_string : (UnixStream) fn(self : UnixStream, io : Io) -> Impl : (Future[Future](String) IoExn : IoExn)flush : (UnixStream) fn(self : UnixStream, io : Io) -> 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
| Name | Type | Notes |
|---|---|---|
self | UnixStream | |
buf | *(u8) | |
size | usize | |
io | Io |