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 11
File operation configuration.
size_t bufferSizeBuffer size hint for I/O operations.Callback invoked when a read operation completes.
Callback invoked when a write operation completes.
Callback invoked on error conditions.
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.
AsyncFileState _statebool usingIoUring() @property const @safe nothrow @nogcCheck if this file is using io_uring for async operations.OpenResult open(ref EventLoop loop, scope const(char)[] path, int flags) @trustedOpen a file for reading and/or writing.AsyncFileState mutableState() @trustedFileConfig _configHandle _handleFileState _fileStateEventLoop * _loopToken _wakeupTokenToken _ioTokenbool _usingIoUringReadCallback onReadWriteCallback onWriteErrorCallback onErrorOperationType _pendingOpubyte[] _readBufferubyte[] _writeDataCopyIoUringFileRing _ringint _resultErrorsize_t _resultBytesFileResult read(ubyte[] buffer, ulong offset) @trustedFileResult write(scope const(ubyte)[] data, ulong offset) @trustedthis(FileConfig config)Dedicated io_uring instance for file I/O operations.
Each AsyncFileState owns its own ring and eventfd so completion notifications stay scoped to the event loop that registered them.
private int _eventFdprivate bool _validprivate void * _sqRingprivate void * _cqRingprivate void * _sqesprivate size_t _sqRingSizeprivate size_t _cqRingSizeprivate size_t _sqesSizeprivate uint _sqEntriesprivate uint _cqEntriesprivate shared(uint) * _sqHeadprivate shared(uint) * _sqTailprivate shared(uint) * _sqMaskprivate shared(uint) * _sqArrayprivate shared(uint) * _cqHeadprivate shared(uint) * _cqTailprivate shared(uint) * _cqMaskprivate io_uring_cqe * _cqesprivate io_uring_sqe * _sqeArrayprivate int _ringFdprivate Mutex _submitMutexprivate bool _probedprivate bool _availablebool 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.void processCompletions(scope CompletionCallback callback) @trusted nothrowProcess all available completions.this()Simple thread pool for file I/O operations (fallback when io_uring unavailable).
private Mutex _mutexprivate Condition _conditionprivate ThreadPoolWorkItem[] _queueprivate Thread _workerprivate bool _shutdownprivate FileThreadPool _instanceprivate bool _instanceCreatedthis()Functions 2
OpenResult mapOpenError(int err) pure @safe nothrow @nogcMap errno values to OpenResult variants.Variables 2
O_CLOEXEC = 0x80000O_CLOEXEC for exec-safe file descriptors.
FILE_RING_ENTRIES = 64uRequested ring size for file I/O operations.