eve.aio.windows.io

Async file I/O primitives for Windows.

This module provides the Windows implementation of asynchronous file I/O using IOCP overlapped I/O. Files are opened with FILE_FLAG_OVERLAPPED and associated with the event loop's I/O completion port for true async operation.

Uses overlapped ReadFile() and WriteFile() with file offsets specified in the OVERLAPPED structure.

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.

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 Windows file handle and integrates with the Layer 1 event loop for async read/write operations using IOCP overlapped I/O.

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 _prepareToken
OVERLAPPED _readOverlapped
OVERLAPPED _writeOverlapped
ubyte[] _readBuffer
ubyte[] _writeBuffer
bool _readInProgress
bool _writeInProgress
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 nothrow
FileResult write(scope const(ubyte)[] data, ulong offset) @trusted nothrow
long size() @trusted nothrow
void closeFile() @trusted nothrow
void dispose() @trusted nothrow
void handlePrepare(ref EventLoop loop, Token token) @trusted nothrowHandle prepare phase callback from the event loop.
int associateWithIocp() @trusted nothrowAssociate the file handle with the event loop's IOCP.
int submitRead(ubyte[] buffer, ulong offset) @trusted nothrowSubmit an overlapped read operation.
void processReadCompletion() @trusted nothrowProcess a completed read operation.
int submitWrite(ubyte[] data, ulong offset) @trusted nothrowSubmit an overlapped write operation.
void processWriteCompletion() @trusted nothrowProcess a completed write operation.
void invokeReadCallback(ubyte[] data, int errorCode) @trusted nothrow
void invokeWriteCallback(size_t bytesWritten, int errorCode) @trusted nothrow
void invokeErrorCallback(int errorCode) @trusted nothrow
AsyncFile owner() @trusted nothrow
Constructors

Functions 4

private fnint errno() ref @trusted nothrow @nogc
private fnFileConfig validated(FileConfig config) pure @safe nothrow @nogc
private fnint mapWinError(DWORD winError) @safe nothrow @nogc
private fnOpenResult mapOpenError(DWORD winError) pure @safe nothrow @nogcMap Windows error codes to OpenResult variants.

Variables 11

private enumvarFILE_SHARE_READ = 0x00000001

Windows file share mode.

private enumvarFILE_SHARE_WRITE = 0x00000002
private enumvarFILE_ATTRIBUTE_NORMAL = 0x00000080
private enumvarFILE_FLAG_OVERLAPPED = 0x40000000
enumvarO_RDONLY = 0x0000

POSIX-like flags for compatibility.

enumvarO_WRONLY = 0x0001
enumvarO_RDWR = 0x0002
enumvarO_CREAT = 0x0100
enumvarO_TRUNC = 0x0200
enumvarO_APPEND = 0x0400
private varint _errno

Thread-local errno for Windows compatibility.