Repository navigation
Wait for readiness on Windows through IOCTL_AFD_POLL under WinIO - #641
Merged
Merged
Conversation
waitAndCancelReadSocketSTM and waitAndCancelWriteSocketSTM issue an AFD poll on the socket, which completes on the I/O manager's port like any overlapped operation; cancelling kills the waiting thread. MIO still throws. Relies on FILE_SKIP_COMPLETION_PORT_ON_SUCCESS (haskell#639). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They had no tests. The new ones run on POSIX and on Windows under WinIO, and are pending where readiness is not available. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 14, 2026
Closed
kazu-yamamoto
added a commit
that referenced
this pull request
Nov 14, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
waitReadSocketSTM,waitWriteSocketSTMand theirwaitAndCancelversions threw on Windows. Under WinIO they now work as on POSIX, throughIOCTL_AFD_POLL: an undocumented but long-stable ioctl of the AFD driver beneath Winsock, which libuv (uv_poll), wepoll and mio use. Issued overlapped on the socket, it completes on the I/O manager's port like any other operation. This is one of the items of #557 (network 4.0, WinIO only on Windows).cbits/afdpoll.c:hsnet_afd_pollissues the poll throughNtDeviceIoControlFile, looked up inntdllat run time. It sets the status block toSTATUS_PENDINGfirst, asDeviceIoControldoes; otherwisegetOverlappedResultreads a pending poll as finished.Network/Socket/STM.hs: under WinIO, the wait runsMgr.withOverlappedin a thread of its own and hands the result over through aTMVar; cancelling kills that thread, andwithOverlappedcancels the poll. Read readiness is RECEIVE, DISCONNECT, ACCEPT, ABORT or LOCAL_CLOSE, and write readiness SEND, CONNECT_FAIL, ABORT or LOCAL_CLOSE. Under No IO Manager the functions still throw.FILE_SKIP_COMPLETION_PORT_ON_SUCCESS(WinIO: skip the completion port when a socket request finishes at once #639) so that no stray packet is left on the port.Tested on Windows 11 with GHC 9.12.4.20260713: 123 examples, 0 failures under WinIO, with the seven new tests running; with No IO Manager and with GHC 9.8.2 they are pending. macOS: 127 examples, 0 failures. CI's Windows jobs use GHC 9.4 and 9.14.1, which compile WinIO out, so the new tests are pending there.
🤖 Generated with Claude Code