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 7

File operation configuration.

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

Callback invoked when a read operation completes.

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

Callback invoked when a write operation completes.

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

Callback invoked on error conditions.

structAsyncFile

Async file handle wrapper.

Wraps a file handle and integrates with the Layer 1 event loop for async read/write operations using IOCP overlapped I/O.

Fields
private AsyncFileState _state
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 @nogcReport whether the file is open.
bool usingIocp() @property const @safe nothrow @nogcReport whether this file is using IOCP overlapped I/O.
FileState state() @property const @safe nothrow @nogcReport the current file state.
OpenResult open(ref EventLoop loop, scope const(char)[] path, int flags) @trustedOpen a file asynchronously.
FileResult read(ubyte[] buffer, ulong offset) @trustedRead data from the file at the given offset.
FileResult write(scope const(ubyte)[] data, ulong offset) @trustedWrite data to the file at the given offset.
long size() @trustedGet the file size in bytes.
void close() @safe nothrowClose the file handle.
void dispose() @safe nothrowDispose of the file wrapper and release all resources.
FileConfig validated(FileConfig config) static pure @safe nothrow @nogc
private enumOperationType : ubyte
NONE
READ
WRITE
private classAsyncFileState
Fields
FileConfig _config
HANDLE _handle
FileState _fileState
EventLoop * _loop
OVERLAPPED _readOverlapped
OVERLAPPED _writeOverlapped
ubyte[] _readBuffer
ubyte[] _writeBuffer
OperationType _pendingOp
bool _appendMode
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 fileCompletionCallback(void * context, OVERLAPPED * overlappedPtr, size_t bytesTransferred, DWORD error) static @trusted nothrowStatic IOCP completion callback.
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 processReadCompletionData(DWORD bytesRead, DWORD error) @trusted nothrowProcess a completed read operation using IOCP completion data.
int submitWrite(ubyte[] data, ulong offset) @trusted nothrowSubmit an overlapped write operation.
void processWriteCompletionData(DWORD bytesWritten, DWORD error) @trusted nothrowProcess a completed write operation using IOCP completion data.
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 @nogcMap Windows error codes to POSIX errno equivalents.
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. Open file read-only.

enumvarO_WRONLY = 0x0001

Open file write-only.

enumvarO_RDWR = 0x0002

Open file for reading and writing.

enumvarO_CREAT = 0x0100

Create file if it does not exist.

enumvarO_TRUNC = 0x0200

Truncate file to zero length.

enumvarO_APPEND = 0x0400

Append on each write.

private varint _errno

Thread-local errno for Windows compatibility.