eve.aio.linux.io

Async file I/O primitives for Linux with io_uring optimization.

This module provides a Linux-specific implementation of asynchronous file I/O that uses io_uring when available for true kernel-level async operations. When io_uring is not available (Linux < 5.1 or restricted environments), it falls back to a thread pool implementation.

io_uring benefits for file I/O:

  • True kernel-level async - no threads needed
  • Zero syscall overhead with submission queue batching
  • Works with regular files unlike epoll

Types 6

File operation configuration.

Fields
size_t bufferSizeBuffer size hint for I/O operations.
Methods
bool isValid() @property const pure @safe nothrow @nogcValidate the config.
aliasReadCallback = void delegate(ref AsyncFile file, ubyte[] data, int error) @safe

Callback invoked when a read operation completes. data is a borrowed slice valid only during callback execution.

aliasWriteCallback = void delegate(ref AsyncFile file, size_t bytesWritten, int error) @safe

Callback invoked when a write operation completes. bytesWritten is the actual bytes written (not queued).

aliasErrorCallback = void delegate(ref AsyncFile file, int error) @safe

Callback invoked on error conditions.

structAsyncFile

Async file handle wrapper.

Wraps a file descriptor and integrates with the Layer 1 event loop for async read/write operations. On Linux 5.1+, uses io_uring for true kernel-level async. Falls back to thread pool on older kernels.

Methods
AsyncFile create(FileConfig config = FileConfig.init) static @trustedCreate a detached file wrapper.
void onRead(ReadCallback callback) @safeRegister callback for read completion.
void onWrite(WriteCallback callback) @safeRegister callback for write completion.
void onError(ErrorCallback callback) @safeRegister callback for error conditions.
bool isOpen() @property const @safe nothrow @nogcCheck if the file is open.
FileState state() @property const @safe nothrow @nogcGet the current file state.
bool usingIoUring() @property const @safe nothrow @nogcCheck if this file is using io_uring for async operations.
OpenStatus open(ref EventLoop loop, scope const(char)[] path, int flags) @trustedOpen a file for reading and/or writing.
FileIoResult read(ubyte[] buffer, ulong offset) @trustedQueue an async read operation.
FileIoResult write(scope const(ubyte)[] data, ulong offset) @trustedQueue an async write operation.
long size() @trustedQuery the file size.
void close() @trustedClose the file.
void dispose() @trustedDispose the file wrapper and release resources.

Shared io_uring instance for file I/O operations.

One ring per EventLoop, shared across all AsyncFile instances on that loop. Eliminates per-file ring overhead (mmap, eventfd, kernel state) and amortises io_uring_enter() syscalls across multiple concurrent file operations.

Access via sharedFileRing.

Methods
bool isValid() @property const @safe nothrow @nogcWhether this ring is usable for I/O.
int eventFd() @property const @safe nothrow @nogcFile descriptor of the completion eventfd.
bool isAvailable() static @trusted nothrowWhether io_uring is available on this kernel.
IoUringFileRing create(uint entries = SHARED_RING_ENTRIES) static @trusted nothrowCreate a shared io_uring ring.
void dispose() @trusted nothrowRelease all ring resources.
bool submitRead(int fd, void * buf, uint len, ulong offset, ulong userData) @trusted nothrowSubmit a read operation to the ring.
bool submitWrite(int fd, const(void) * buf, uint len, ulong offset, ulong userData) @trusted nothrowSubmit a write operation to the ring.
bool submitClose(int fd, ulong userData) @trusted nothrowSubmit a close operation to the ring.
bool submitSendfile(int sockfd, int fileFd, ulong offset, size_t length, ulong userData) @trusted nothrowSubmit a sendfile-compatible splice if supported.
void processCompletions(scope CompletionCallback callback) @trusted nothrowProcess all available completions.
Constructors
this(uint entries)

Functions 7

fnIoUringFileRing sharedFileRing(EventLoop * loop) @trusted nothrow
fnvoid disposeSharedFileRing(EventLoop * loop) @trusted nothrow
fnToken sharedFileRingToken(EventLoop * loop) @trusted nothrow
fnvoid sharedFileRingToken(EventLoop * loop, Token token) @trusted nothrow
fnvoid sharedFileRingRetain(EventLoop * loop) @trusted nothrow
fnvoid sharedFileRingRelease(EventLoop * loop) @trusted nothrow
fnuint sharedFileRingUseCount(EventLoop * loop) @trusted nothrow