Module: net.unix

Source: ./net/unix.reef


Overview

net/unix - Unix domain sockets

Provides inter-process communication via Unix domain sockets (AF_UNIX). Data transfer uses the same send/recv as TCP (both are SOCK_STREAM).

Example - Client: let fd = unix_connect("/tmp/myapp.sock") unix_send(fd, "hello") let reply = unix_recv(fd, 256) unix_close(fd)

Example - Server: let server = unix_listen("/tmp/myapp.sock", 5) let client = unix_accept(server) let msg = unix_recv(client, 256) unix_send(client, "reply") unix_close(client) unix_close(server) unix_unlink("/tmp/myapp.sock") The 5 fallible ops (connect/listen/accept, send, recv) return result.Result[T, error.Error]. Failures are classified via net.socket's net_err() (errno -> ErrorKind, with a strerror() message) -- same pattern as net.tcp. unix_connect's ENOENT and unix_listen's EADDRINUSE map to ErrorKind_NotFound / ErrorKind_AlreadyExists automatically via net_err()'s errno table -- no special-casing needed here.

unix_recv treats a clean close/EOF as Ok(""), NOT an error: the runtime returns 0 for a graceful close, which is a normal end-of-stream condition, not a failure. Only a negative (non-close) return from the runtime becomes Err(net_err()).


Functions

fn unix_connect(path: string): result.Result[int, error.Error]

Connect to a Unix domain socket Ok(socket fd) on success, Err(socket.net_err()) on failure (e.g. ENOENT maps to ErrorKind_NotFound if the path doesn't exist).

fn unix_listen(path: string, backlog: int): result.Result[int, error.Error]

Create a listening Unix domain socket Ok(server socket fd) on success, Err(socket.net_err()) on failure (e.g. EADDRINUSE maps to ErrorKind_AlreadyExists if the path is already bound).

fn unix_accept(server_fd: int): result.Result[int, error.Error]

Accept a connection Ok(client socket fd) on success, Err(socket.net_err()) on failure.

fn unix_send(sockfd: int, data: string): result.Result[int, error.Error]

Send data (reuses TCP send — works on any SOCK_STREAM fd) Ok(number of bytes sent) on success, Err(socket.net_err()) on failure.

fn unix_recv(sockfd: int, max_len: int): result.Result[string, error.Error]

Receive data Ok(received string, GC-copied; may be shorter than max_len) on success; Ok("") on clean close/EOF (runtime returns 0 -- NOT an error); Err(socket.net_err()) on failure (runtime returns < 0).

GC-copies via reef_string_alloc + memcpy before freeing the raw buffer, matching the tcp_recv pattern.

fn unix_close(sockfd: int): int

Close socket

fn unix_unlink(path: string): int

Remove socket file


Generated by reefc doc