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. Zeroallocation in steady state. Requires
preallocatedSendBuffer > 0in 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:
- Separate fields instead of a union: avoids GC scanning issues with
D unions that contain both managed (
ubyte[]) and struct types. - Ring buffer capacity must be
>= highWaterMarkso that any sendthat passes the per-connection budget check will always fit.
consume()in dynamic-array mode uses.dupto release the frontof the backing array for GC, matching the pre-existing behaviour. In ring-buffer mode,
consume()is a simple pointer advance — zero allocation.
Copyright
Types 1
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.
void initialize(size_t highWaterMark, size_t preallocatedSize) @trusted nothrowPrepare the send queue for use.const(ubyte)[] front() const @trusted nothrow @nogcGet a contiguous view of the front of the queue for writing to a socket or pipe.size_t budget() const @safe nothrow @nogcBytes remaining before the per-connection `highWaterMark` is reached.