eve.backend.windows.iocp
Windows Layer 0 readiness backend built on IOCP and WSAPoll.
This backend uses Windows I/O Completion Ports as the core notification mechanism while leveraging WSAPoll for socket readiness detection. The combination provides an IOCP-based architecture with readiness semantics suitable for the Layer 0 abstraction.
Key features:
- WSAPoll-based socket readiness polling (reliable, tested)
- Handle type classification for future non-socket support
- IOCP-based wakeup mechanism via PostQueuedCompletionStatus
- Unified wait combining IOCP wakeups with socket polling
Copyright
Types 11
Handle type classification.
Different handle types require different polling mechanisms on Windows. Currently, only sockets are fully supported via WSAPoll. Other handle types are classified for future IOCP-based overlapped I/O support.
I/O model used for a registered handle.
Determines how the handle is polled for readiness or completion.
Type of I/O operation for overlapped tracking.
Entry in the overlapped I/O pool.
Each entry contains an OVERLAPPED structure, a data buffer, and metadata for tracking the operation. The entry must remain valid until the I/O operation completes. Entry in the overlapped I/O pool.
Each entry contains an OVERLAPPED structure and metadata for tracking the operation. Buffers are provided externally by the caller. The entry must remain valid until the I/O operation completes.
OVERLAPPED overlappedWindows OVERLAPPED structure for async I/O.ulong userDataUser data associated with this operation.HANDLE handleHandle this operation is associated with.void * bufferPtrPointer to external buffer (owned by caller).size_t bufferSizeSize of the external buffer.IoOperation operationType of operation in progress.bool inUseWhether this entry is currently in use.size_t bytesTransferredNumber of bytes transferred (filled on completion).Pool of pre-allocated OVERLAPPED entries for async I/O.
This pool manages the lifecycle of OVERLAPPED structures used for Windows overlapped I/O operations. Entries are acquired before submitting an I/O operation and released when the operation completes.
OverlappedEntry * findByOverlapped(OVERLAPPED * overlappedPtr) @trusted nothrow @nogcFind an entry by its OVERLAPPED pointer.size_t activeCount() @property const pure @safe nothrow @nogcGet the number of active (in-use) entries.bool hasAvailable() @property const pure @safe nothrow @nogcCheck if the pool has available entries.Special completion keys for internal IOCP events.
Native event type returned by this backend.
Mirrors the shape used by the epoll backend to maintain a consistent interface for Layer 1 consumption.
uint eventsReadiness event mask in epoll-compatible format.DataNested data union for compatibility.Registration entry for a handle.
SOCKET socketThe native socket value (for WSAPoll).HANDLE nativeHandleNative handle for non-socket handles.HandleType handleTypeType of handle registered.IoModel ioModelI/O model used for this handle.IoInterest interestRequested readiness interests.ulong userDataUser-provided opaque data.bool activeWhether this slot is actively registered.Completion callback for overlapped I/O operations.
Parameters
context | User-provided context pointer (typically this). |
overlappedPtr | Pointer to the OVERLAPPED structure that completed. |
bytesTransferred | Number of bytes transferred by the operation. |
error | Win32 error code (0 on success). |
Entry in the completion handler table.
void * completionKeyContext pointer used as IOCP completion key.CompletionCallback callbackCallback to invoke when a completion arrives for this key.bool activeWhether this entry is in use.IOCP-backed poller state for Windows.
This backend maintains an I/O Completion Port handle for the notification mechanism and uses WSAPoll internally for socket readiness detection. The IOCP is also used for efficient cross-thread wakeups.
void * _iocpRegistration[maxRegistrations] _registrationsWSAPOLLFD[maxRegistrations] _pollFdssize_t[maxRegistrations] _pollToRegOverlappedPool _overlappedPoolsize_t _registrationCountsize_t _socketCountsize_t _overlappedCountCompletionEntry[maxCompletionHandlers] _completionHandlerssize_t _completionHandlerCountbool _winsockInitializedbool _pendingWakeupbool isValid() @property const pure @safe nothrow @nogcCheck whether the poller has a valid IOCP handle.Handle handle() @property const pure @trusted nothrow @nogcReturn the native handle wrapper for the IOCP instance.BackendId backendId() @property const pure @safe nothrow @nogcReturn the identifier of this backend.BackendCapabilities capabilities() @property const pure @safe nothrow @nogcReturn the capability flags for this backend.size_t registrationCount() @property const pure @safe nothrow @nogcGet the number of active registrations.size_t overlappedCount() @property const pure @safe nothrow @nogcGet the number of overlapped (non-poll) registrations.OverlappedPool overlappedPool() @property ref return @safe nothrow @nogcGet the overlapped entry pool.int registerCompletion(void * context, CompletionCallback callback) @trusted nothrowRegister a completion handler for a given context pointer.int registerHandle(Handle handle, IoInterest interest, ulong userData) @trusted nothrow @nogcRegister a handle with the given interests and opaque user data.int modifyHandle(Handle handle, IoInterest interest, ulong userData) @trusted nothrow @nogcModify the interest mask and user data for an already-registered handle.int unregisterHandle(Handle handle) @trusted nothrow @nogcRemove a handle from the registration table.int associateHandle(HANDLE handle, ulong completionKey) @trusted nothrow @nogcAssociate a handle with the IOCP for overlapped I/O.void dispatchCompletion(ULONG_PTR completionKey, OVERLAPPED * overlappedPtr,
size_t bytesTransferred, DWORD error) @trusted nothrowDispatch a single IOCP completion to its registered handler.OsEvent translate(ref const(NativeEvent) nativeEvent) static pure @safe nothrow @nogcTranslate a native event into the shared Layer 0 event shape.IoReady translateReady(uint nativeMask) static pure @safe nothrow @nogcTranslate a native readiness mask into shared readiness flags.Functions 3
short toNativeMask(IoInterest interest) pure @safe nothrow @nogcConvert IoInterest to native WSAPoll mask.uint toEpollMask(short pollMask) pure @safe nothrow @nogcConvert WSAPoll revents mask to epoll-compatible mask.IoReady fromNativeMask(uint mask) pure @safe nothrow @nogcConvert epoll-compatible mask to shared IoReady flags.Variables 3
maxRegistrations = 1024Maximum number of registrations supported.
This limit applies to the total number of handles (sockets, pipes, files) that can be registered with a single event loop. If your application needs more than 1024 concurrent I/O watchers, you may need to use multiple event loops or restructure your application.
Note
Future versions may support dynamic sizing via EventLoopConfig.watcherCapacity.
MAX_OVERLAPPED_ENTRIES = 64Maximum number of overlapped entries in the pool.
maxCompletionHandlers = 128Maximum number of completion handlers that can be registered.