eve.aio.posix.unix

Async Unix domain socket listener and connection primitives for POSIX platforms.

This module provides the POSIX implementation of Unix domain socket primitives using standard BSD sockets API. Unix domain sockets provide inter-process communication on the same host without network overhead.

Backpressure is modelled via an all-or-nothing send policy: send() either accepts all bytes (OK) or none (PRESSURE). A per-connection send queue buffers data until the kernel can drain it. See the Backpressure Specification for details.

Two send-queue allocation modes are available:

  • Dynamic array (default) — may allocate per send() call.
  • Pre-allocated ring buffer — set preallocatedSendBuffer for

    steady-state zero-allocation operation.

Descriptor passing (SCM_RIGHTS) is available through the fd-aware send and receive surface. Successful send(data, descriptors) acceptance duplicates the supplied descriptors into queue-owned close-on-exec handles; the caller retains ownership of the originals and may close them immediately. Receiving delivers a move-only ReceivedDescriptors batch whose unclaimed descriptors are closed automatically. Bytes and descriptors form two ordered streams: no association between a descriptor and a byte offset is promised, because recvmsg may coalesce earlier plain bytes with descriptor-bearing data.

See Also

Types 8

Unix domain socket address: a filesystem path or a Linux abstract-namespace name.

The address is a Borrow view over caller memory (TERMINOLOGY.md): connect and listen consume it synchronously and keep no reference.

Abstract names are raw bytes, available on Linux only. The display-layer `@` notation is converted by the caller (@name becomes abstractName(name)); EVE writes the internal leading NUL itself and computes the address length from the actual name bytes, never from a NUL terminator.

Methods
UnixAddress filesystem(scope const(char)[] path) static pure @safe nothrow @nogcCreate a filesystem-path address.
UnixAddress abstractName(scope const(ubyte)[] name) static pure @safe nothrow @nogcCreate a Linux abstract-namespace address from raw name bytes.
Kind kind() @property const pure @safe nothrow @nogcThe address kind.
const(ubyte)[] name() @property const pure @safe nothrow @nogcThe raw name bytes: the filesystem path or the abstract name.
Nested Templates
KindAddress kind.

Credentials of a Unix domain socket peer, captured when the connection was established.

Field availability is explicit per platform: a false flag means the platform did not supply the value — a field is never a plausible default such as zero. The kernel pins the values at connect time, so they remain valid after the peer exits. Identity is not authorization; consumers decide what to trust.

Fields
bool hasUidWhether `uid` was supplied by the platform.
bool hasGidWhether `gid` was supplied by the platform.
bool hasPidWhether `pid` was supplied by the platform.
uint uidEffective user id of the peer at connect time; meaningful iff `hasUid`.
uint gidEffective group id of the peer at connect time; meaningful iff `hasGid`.
int pidProcess id of the peer at connect time; meaningful iff `hasPid`.

Result of a peer-credential query: the captured credentials, or a CredentialsError explaining the failure.

Move-only owned batch of descriptors received with one recvmsg.

The batch holds Owned descriptors in EVE-managed storage: every descriptor still inside the batch when it is destroyed is closed automatically. take Transfers a single descriptor to the caller, who then owns closing or adopting it; peek Borrows a descriptor value without transferring ownership (TERMINOLOGY.md).

The batch cannot be copied. It is delivered to the descriptor-aware data callback as a scoped reference and must not escape the callback; claim descriptors with take to keep them.

Methods
size_t length() @property const @safe nothrow @nogcNumber of descriptor slots in the batch (claimed and unclaimed).
size_t remaining() @property const @safe nothrow @nogcNumber of descriptors still owned by the batch.
bool isClaimed(size_t index) const @safe nothrow @nogcReport whether the descriptor at `index` was already claimed.
Handle peek(size_t index) const @safe nothrow @nogcBorrow the descriptor at `index` without transferring ownership.
Handle take(size_t index) @trusted nothrow @nogcTransfer the descriptor at `index` out of the batch.
void release() @trusted nothrowClose every descriptor still owned by the batch.
Destructors

Connection-side buffer configuration.

Fields
size_t highWaterMarkMaximum queued bytes before `send` starts reporting pressure.
size_t lowWaterMarkQueue threshold below which `onWritable` may fire again.
size_t preallocatedSendBufferPre-allocate a fixed-capacity ring buffer for the send queue.
size_t maxQueuedDescriptorsMaximum descriptors held in the send queue across all pending batches.
Methods
bool isValid() @property const pure @safe nothrow @nogcValidate the config.

Listener-side socket configuration.

Fields
int backlogPending accept backlog passed to `listen(2)`.
Methods
bool isValid() @property const pure @safe nothrow @nogcValidate the config.

Async Unix domain socket connection wrapper.

Wraps a non-blocking Unix domain socket and integrates with the Layer 1 event loop for async read/write operations with backpressure support.

Methods
UnixConnection create(UnixConnectionConfig config = UnixConnectionConfig.init) static @trusted nothrowCreate a detached connection wrapper.
void onConnect(ConnectCallback callback) @property @trustedSet the connect callback.
void onData(DataCallback callback) @property @trustedSet the inbound data callback.
void onDataWithDescriptors(DataWithDescriptorsCallback callback) @property @trustedSet the descriptor-aware inbound data callback.
void onWritable(WritableCallback callback) @property @trustedSet the writable callback.
void onClose(CloseCallback callback) @property @trustedSet the close callback.
void onError(ErrorCallback callback) @property @trustedSet the error callback.
bool isOpen() @property const @safe nothrow @nogcReport whether the wrapper currently owns an open socket.
SocketState state() @property const @safe nothrow @nogcReport the current connection state.
size_t sendQueueLen() @property const @safe nothrow @nogcReport the current queued send size.
bool isWritable() @property const @safe nothrow @nogcReport whether the connection is currently writable from the caller's perspective.
CredentialsResult peerCredentials() const @safe nothrow @nogcQuery the credentials of the connected peer.
AdoptStatus adopt(ref EventLoop loop, Handle clientHandle) @trusted nothrowAdopt an already-accepted client socket.
ConnectStatus connect(ref EventLoop loop, scope const(char)[] path, CancelToken cancel = CancelToken.invalid) @trustedStart a non-blocking connection attempt to a Unix domain socket path.
ConnectStatus connect(ref EventLoop loop, UnixAddress address, CancelToken cancel = CancelToken.invalid) @trustedStart a non-blocking connection attempt to a Unix domain socket address.
SendStatus send(scope const(ubyte)[] data) @trustedSend bytes over the connection.
SendStatus send(scope const(ubyte)[] data, scope const(Handle)[] descriptors) @trustedSend bytes and pass open descriptors over the connection (SCM_RIGHTS).
void pauseReading() @trusted nothrowPause socket read delivery.
void resumeReading() @trusted nothrowResume socket read delivery.
void close() @trusted nothrowClose the connection.
void dispose() @trusted nothrowDispose the connection and its watcher registration.
bool track(Coord)(ref Coord coordinator) @trusted nothrowTrack this connection for graceful shutdown.

Async Unix domain socket listener wrapper.

Wraps a non-blocking Unix domain socket listening socket and integrates with the Layer 1 event loop for async accept operations.

Methods
UnixListener create(UnixListenerConfig config = UnixListenerConfig.init) static @trustedCreate a detached listener wrapper.
void onAccept(AcceptCallback callback) @property @trustedSet the accept callback.
void onConnection(ConnectionCallback callback) @property @trustedSet the high-level connection callback.
bool isOpen() @property const @safe nothrow @nogcReport whether the listener currently owns an open socket.
const(char)[] localPath() @property const @safe nothrow @nogcReport the filesystem path the listener is bound to.
ListenStatus listen(ref EventLoop loop, scope const(char)[] path) @trustedStart listening on the requested Unix domain socket path.
ListenStatus listen(ref EventLoop loop, UnixAddress address) @trustedStart listening on the requested Unix domain socket address.
void close() @trusted nothrowClose the listener and remove the socket file.
void dispose() @trusted nothrowDispose the listener and its watcher registration.
bool track(Coord)(ref Coord coordinator) @trusted nothrowTrack this listener for graceful shutdown.

Functions 1

fnbool isValidPath(scope const(char)[] path) pure @safe nothrow @nogcCheck if a Unix socket path is valid.

Variables 2

enumvarUNIX_PATH_MAX = sockaddr_un.init.sun_path.length

Maximum length of a Unix domain socket path.

This is typically 108 bytes on Linux and 104 on BSD/macOS, but we use the actual sun_path array size for correctness.

enumvarUNIX_MAX_DESCRIPTORS_PER_SEND = 253

Maximum number of descriptors accepted by a single send call, and the capacity the receive path reserves for the control data of one recvmsg.

253 is the Linux kernel per-message limit (SCM_MAX_FD). EVE applies the same limit on every POSIX platform so that EVE peers interoperate uniformly and the receive capacity always covers an accepted send. Control data from a non-EVE peer that exceeds this capacity arrives truncated, which terminates the connection (fail-closed).