eve.aio.posix.io

Async file I/O primitives for POSIX platforms.

This module provides the POSIX implementation of asynchronous file I/O using a thread pool for blocking operations. Regular files don't map cleanly onto readiness APIs, so blocking I/O is performed in worker threads and completion is signaled back to the event loop via wakeup watchers.

Uses pread() and pwrite() for thread-safe positioned I/O.

Types 9

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.

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

Callback invoked when a write operation completes.

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 using a background thread pool.

Fields
Methods
AsyncFile create(FileConfig config = FileConfig.init) @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.
OpenResult open(ref EventLoop loop, scope const(char)[] path, int flags) @trustedOpen a file for reading and/or writing.
FileResult read(ubyte[] buffer, ulong offset) @trustedQueue an async read operation.
FileResult 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.
private classAsyncFileState
Fields
FileConfig _config
Handle _handle
FileState _fileState
EventLoop * _loop
Token _wakeupToken
bool _operationPending
int _resultError
size_t _resultBytes
ubyte[] _readBuffer
Methods
bool isOpen() @property const @safe nothrow @nogc
OpenResult open(ref EventLoop loop, scope const(char)[] path, int flags) @trusted nothrow
FileResult read(ubyte[] buffer, ulong offset) @trusted
FileResult write(scope const(ubyte)[] data, ulong offset) @trusted
long size() @trusted nothrow
void closeFile() @trusted nothrow
void dispose() @trusted nothrow
void handleWakeup(ref EventLoop loop, Token token) @safe nothrow
void notifyComplete(int error, size_t bytes) @trusted nothrow
AsyncFile owner() @trusted nothrow
Constructors
private enumWorkType : ubyte
READ
WRITE
private structWorkItem
Fields
int fd
ubyte * buffer
size_t length
ulong offset
private classFileThreadPool

Simple thread pool for file I/O operations.

Uses a single worker thread to perform blocking I/O and signals completion back to the event loop.

Fields
private Mutex _mutex
private Condition _condition
private WorkItem[] _queue
private Thread _worker
private bool _shutdown
private FileThreadPool _instance
private bool _instanceCreated
Methods
FileThreadPool instance() @trusted nothrow
void submit(WorkItem item) @trusted nothrow
void shutdown() @trusted nothrow
void workerLoop() @trusted nothrow
void processWork(WorkItem item) @trusted nothrow
Constructors

Functions 2

private fnOpenResult mapOpenError(int err) pure @safe nothrow @nogcMap errno values to OpenResult variants.
private fnFileConfig validated(FileConfig config) pure @safe nothrow @nogc