eve.aio.posix.tcp
Async TCP listener and connection primitives for POSIX platforms.
This module provides the POSIX implementation of TCP networking primitives using standard BSD sockets API. It works on Linux, BSD, and macOS.
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
preallocatedSendBufferforsteady-state zero-allocation operation.
See Also
Types 14
Connection-side buffer configuration.
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.int recvBufferSize`SO_RCVBUF` value applied to accepted/connected sockets.int sendBufferSize`SO_SNDBUF` value applied to accepted/connected sockets.int windowClamp`TCP_WINDOW_CLAMP` value applied to accepted/connected sockets.size_t readBufferSizePer-connection receive buffer size in bytes.int keepAliveIdleSeconds before the first TCP keepalive probe is sent.int keepAliveIntervalSeconds between subsequent TCP keepalive probes.int keepAliveCountNumber of unacknowledged keepalive probes before the connection is considered dead.bool keepAliveEnabledEnable TCP keepalive on the socket.Listener-side socket configuration.
int backlogPending backlog size passed to `listen(2)`. -1 = OS default.int deferAcceptSeconds`TCP_DEFER_ACCEPT` value applied to the listening socket.bool reusePortEnable `SO_REUSEPORT` on the listening socket.Async TCP connection wrapper.
Wraps a non-blocking TCP socket and integrates with the Layer 1 event loop for async read/write operations with backpressure support.
private TcpConnectionState _stateTcpConnection create(TcpConnectionConfig config = TcpConnectionConfig.init) static @trusted nothrowCreate a detached connection wrapper.bool isOpen() @property const @safe nothrow @nogcReport whether the wrapper currently owns an open socket.bool isWritable() @property const @safe nothrow @nogcReport whether the connection is currently writable from the caller's perspective.IpAddress remoteAddress() @property const @safe nothrow @nogcReport the remote address of the connection.IpAddress localAddress() @property const @safe nothrow @nogcReport the local address of the connection.AdoptResult adopt(ref EventLoop loop, Handle clientHandle) @trusted nothrowAdopt an already-accepted client socket.ConnectResult connect(ref EventLoop loop, scope const(char)[] host, ushort port, CancelToken cancel = CancelToken
.invalid) @trusted nothrowStart a non-blocking connection attempt.bool track(Coord)(ref Coord coordinator) @trusted nothrowTrack this connection for graceful shutdown.Async TCP listener wrapper.
Wraps a non-blocking TCP listening socket and integrates with the Layer 1 event loop for async accept operations.
private TcpListenerState _stateTcpListener create(TcpListenerConfig config = TcpListenerConfig.init) static @trustedCreate a detached listener wrapper.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.ushort localPort() @property const @safe nothrow @nogcReport the effective local port once listening.ListenResult listen(ref EventLoop loop, scope const(char)[] host, ushort port) @trustedStart listening on the requested endpoint.ConnectCallback onConnectDataCallback onDataWritableCallback onWritableCloseCallback onCloseErrorCallback onErrorprivate EventLoop * _loopprivate Handle _handleprivate Token _tokenprivate TcpConnectionConfig _configprivate bool _readingPausedprivate bool _watchingWriteprivate bool _awaitingWritableprivate bool _closeDeliveredprivate SendQueue _sendQueueprivate SocketState _stateprivate IpAddress _remoteAddressprivate IpAddress _localAddressprivate CancelToken _cancelTokenprivate CancelToken _shutdownTokenprivate bool _drainingprivate ubyte[] _recvBufferConnectResult connect(ref EventLoop loop, scope const(char)[] host, ushort port, CancelToken cancel = CancelToken
.invalid) @trusted nothrowSendResult send(scope const(ubyte)[] data) @trustedvoid closeInternal(SocketCloseReason reason, int errorNumber, bool invokeCallback) @trusted nothrowthis(TcpConnectionConfig config)AcceptCallback onAcceptConnectionCallback onConnectionprivate EventLoop * _loopprivate Handle _handleprivate Token _tokenprivate TcpListenerConfig _configprivate ushort _localPortprivate CancelToken _shutdownTokenprivate Token _throttleTokenprivate bool _drainingprivate bool _throttledthis(TcpListenerConfig config)Range adapter for iterating over addrinfo linked list.
addrinfo * currentFunctions 14
TcpConnectionConfig validated(TcpConnectionConfig config) pure @safe nothrow @nogcValidate a connection config, returning defaults if invalid.TcpListenerConfig validated(TcpListenerConfig config) pure @safe nothrow @nogcValidate a listener config, returning defaults if invalid.const(char) * copyStringz(scope const(char)[] source, return char[] buffer) @trusted nothrowCopy a D string slice to a null-terminated C string buffer.int accept4NonBlocking(int srv, void * addr, uint * alen) @trusted nothrow @nogcAccept a new client socket with `SOCK_NONBLOCK | SOCK_CLOEXEC` atomically.bool wouldBlock(int value) pure @safe nothrow @nogcCheck if an errno value indicates the operation would block.ptrdiff_t drainToEAGAIN(int fd) @trusted nothrow @nogcDrain a socket file descriptor to `EAGAIN` by reading and discarding.int resolveErrno(int status) @trusted nothrowConvert getaddrinfo error to errno equivalent.ushort queryLocalPort(int fd) @trusted nothrowQuery the local port number for a bound socket.AddrinfoRange addrinfoRange(addrinfo * first) pure @safe nothrow @nogcCreate a range over an addrinfo linked list.