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.

Types 13

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.
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.
private aliasConnectCallback = void delegate(ref UnixConnection connection) @safe
private aliasDataCallback = void delegate(ref UnixConnection connection, scope const(ubyte)[] data) @safe
private aliasWritableCallback = void delegate(ref UnixConnection connection) @safe
private aliasCloseCallback = void delegate(ref UnixConnection connection, SocketCloseReason reason) @safe
private aliasErrorCallback = void delegate(ref UnixConnection connection, int errorNumber) @safe
private aliasAcceptCallback = void delegate(ref UnixListener listener, Handle clientHandle) @safe
private aliasConnectionCallback = void delegate(ref UnixListener listener, ref UnixConnection connection) @safe

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.

Fields
Methods
UnixConnection create(UnixConnectionConfig config = UnixConnectionConfig.init) @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 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.
AdoptResult adopt(ref EventLoop loop, Handle clientHandle) @trusted nothrowAdopt an already-accepted client socket.
ConnectResult connect(ref EventLoop loop, scope const(char)[] path, CancelToken cancel = CancelToken.invalid) @trustedStart a non-blocking connection attempt to a Unix domain socket path.
SendResult send(scope const(ubyte)[] data) @trustedSend bytes over the connection.
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.

Fields
Methods
UnixListener create(UnixListenerConfig config = UnixListenerConfig.init) @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.
ListenResult listen(ref EventLoop loop, scope const(char)[] path) @trustedStart listening on the requested Unix domain socket path.
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.
UnixListenerState mutableState() @trusted nothrow
Fields
ConnectCallback onConnect
WritableCallback onWritable
EventLoop * _loop
Handle _handle
Token _token
bool _readingPaused
bool _watchingWrite
bool _awaitingWritable
bool _closeDelivered
ubyte[] _sendQueue
CancelToken _cancelToken
CancelToken _shutdownToken
bool _draining
Methods
void initiateShutdown(CancelToken token) @safe nothrow
void performDrain() @safe nothrow
void forceAbort() @safe nothrow
bool isClosed() @property const @safe nothrow @nogc
bool isOpen() @property const @safe nothrow @nogc
size_t sendQueueLen() @property const @safe nothrow @nogc
bool isWritable() @property const @safe nothrow @nogc
AdoptResult adopt(ref EventLoop loop, Handle clientHandle) @trusted nothrow
ConnectResult connect(ref EventLoop loop, scope const(char)[] path, CancelToken cancel = CancelToken.invalid) @trusted nothrow
SendResult send(scope const(ubyte)[] data) @trusted
void pauseReading() @trusted nothrow
void resumeReading() @trusted nothrow
void closeExplicitly() @trusted nothrow
void handleIo(ref EventLoop loop, Token token, IoReady ready) @safe nothrow
UnixConnection owner() @safe nothrow
void finishConnect() @trusted nothrow
void readAvailable() @trusted nothrow
void flushSendQueue() @trusted nothrow
int refreshInterest() @trusted nothrow
void fail(int errorNumber) @trusted nothrow
void closeInternal(SocketCloseReason reason, int errorNumber, bool invokeCallback) @trusted nothrow
void closeWithoutCallback() @trusted nothrow
void invokeConnect() @trusted nothrow
void invokeData(scope const(ubyte)[] data) @trusted nothrow
void invokeWritable() @trusted nothrow
void invokeError(int errorNumber) @trusted nothrow
void invokeClose(SocketCloseReason reason) @trusted nothrow
Constructors
Fields
ConnectionCallback onConnection
EventLoop * _loop
Handle _handle
Token _token
byte[UNIX_PATH_MAX] _localPath
CancelToken _shutdownToken
bool _draining
Methods
void initiateShutdown(CancelToken token) @safe nothrow
void performDrain() @safe nothrow
void forceAbort() @safe nothrow
bool isClosed() @property const @safe nothrow @nogc
bool isOpen() @property const @safe nothrow @nogc
const(char)[] localPath() @property const @safe nothrow @nogc
ListenResult listen(ref EventLoop loop, scope const(char)[] path) @trusted nothrow
void close() @trusted nothrow
void handleIo(ref EventLoop loop, Token token, IoReady ready) @safe nothrow
UnixListener owner() @safe nothrow
void acceptAvailable() @trusted nothrow
void invokeAccept(Handle clientHandle) @trusted nothrow
Constructors

Functions 9

private fnUnixConnectionConfig validated(UnixConnectionConfig config) pure @safe nothrow @nogcValidate a connection config, returning defaults if invalid.
private fnUnixListenerConfig validated(UnixListenerConfig config) pure @safe nothrow @nogcValidate a listener config, returning defaults if invalid.
private fnint setNonBlocking(int fd) @trusted nothrowSet a file descriptor to non-blocking mode.
private fnbool wouldBlock(int value) pure @safe nothrow @nogcCheck if an errno value indicates the operation would block.
private fnint socketError(int fd) @trusted nothrowQuery the socket error status.
fnbool isValidPath(scope const(char)[] path) pure @safe nothrow @nogcCheck if a Unix socket path is valid.
private fnListenResult mapListenError(int err) pure @safe nothrow @nogc
private fnConnectResult mapConnectError(int err) pure @safe nothrow @nogc
private fnAdoptResult mapAdoptError(int err) pure @safe nothrow @nogc

Variables 1

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.