wepoll-d — a single-file D port of wepoll (epoll-style socket polling for Windows)

Adam D. Ruppe destructionator at gmail.com
Tue Nov 24 11:37:09 UTC 2026


On Tuesday, 24 November 2026 at 09:42:36 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> https://notgull.net/device-afd/

This claims:

"The overarching idea is, what if that the operation that the 
IOCP is waiting on is waiting for the socket to become ready? 
This would handily solve our problem here, since we could just 
register that waiting operation to adapt it to the polling model. 
Sadly, the WinSock API doesn’t expose a way of doing this, aside 
from WSAPoll, which we’ve already established doesn’t work."

But that's not true, there's also WSAASyncSelect and 
WSAEventSelect which do these. They're both quite elegant too.

AsyncSelect sends a window message for readiness notifications. 
EventSelect sets an event. You can use a threadpool wait on the 
event and QueueUserAPC (if you want to target a specific thread 
and/or a gui thread) or PostQueuedCompletionPacket (to target a 
threadpool waiting on an iocp) back to the owner loop.

The implementation of SetThreadpoolWait uses the afd thing, but 
the difference is STW is actually documented and supported.

So to do it this way:

* CreateEvent
* WSAEventSelect
* CreateThreadpoolWait
* SetThreadpoolWait to a callback that, if not oneshot, does 
SetThreadpoolWait again after PostQueuedCompletionPacket or 
QueueUserAPC. Note there will be multiple threads working here so 
watch for sequencing and race conditions.
* Your event loop works with GetQueuedCompletionStatusEx or 
MsgWaitForMultipleObjectsEx

I recently did this in the arsd libs (among many other things) 
and it was a triumph, so I'm making a note here.


More information about the Digitalmars-d-announce mailing list