eve.aio.sendqueue

Dual-mode send queue for Layer 2 stream transports.

Encapsulates buffer management for send()/write() operations, supporting two modes selected at initialization time:

  • Dynamic array mode (default): uses `~=` append. May allocate on

    every send() call. Compatible with all existing code.

  • Ring buffer mode (opt-in): uses eve.util.RingBuffer. Zero

    allocation in steady state. Requires preallocatedSendBuffer > 0 in the transport config.

This module exists because all three POSIX stream transports (TCP, Unix, Pipe) share identical send-queue logic (~100 lines each). Centralising it here avoids triple-maintenance and ensures ring-buffer integration is correct in one place.

Design decisions:

  1. Separate fields instead of a union: avoids GC scanning issues with

    D unions that contain both managed (ubyte[]) and struct types.

  2. Ring buffer capacity must be >= highWaterMark so that any send

    that passes the per-connection budget check will always fit.

  3. consume() in dynamic-array mode uses .dup to release the front

    of the backing array for GC, matching the pre-existing behaviour. In ring-buffer mode, consume() is a simple pointer advance — zero allocation.

struct SendQueue

Types 1

structSendQueue

Dual-mode send queue for stream transports.

The queue is non-copyable to prevent accidental duplication of the backing storage. Pass by reference or store as a field in a class.

Buffer Ownership (TERMINOLOGY.md): Internal storage is EVE-Owned. append() uses Copy semantics — the caller may reuse or free the source buffer immediately. front() returns a Borrowed slice valid only until the next append() or consume() call.

Fields
ubyte[] _dynamic
bool _usingRingBuffer
size_t _highWaterMark
Methods
void initialize(size_t highWaterMark, size_t preallocatedSize) @trusted nothrowPrepare the send queue for use.
void dispose() @trusted nothrowRelease all backing storage immediately.
bool append(scope const(ubyte)[] data) @trusted nothrowAppend data to the send queue.
const(ubyte)[] front() const @trusted nothrow @nogcGet a contiguous view of the front of the queue for writing to a socket or pipe.
void consume(size_t n) @trusted nothrowAdvance past `n` bytes that were written to the socket/pipe.
void clear() @trusted nothrowEmpty the queue without releasing storage.
size_t length() const @safe nothrow @nogcCurrent number of bytes queued.
size_t budget() const @safe nothrow @nogcBytes remaining before the per-connection `highWaterMark` is reached.
bool empty() const @safe nothrow @nogcWhether the queue contains no data.