Repository navigation
Fix the WSAPoll backend of Io\Poll accepting handles that are not sockets - #25135
nicolas-grekas wants to merge 1 commit into
Conversation
…kets WSAPoll() can only poll sockets, but the backend accepted any fd. A file or a pipe such as STDOUT was then dropped by wait() without being reported. Adding such a handle now fails with ERR_NOSUPPORT, as epoll does for regular files.
|
@bukka Thanks for landing this. With What are your plans for non-socket handles in the WSAPoll backend, and what would you recommend? Is supporting them on your roadmap? Or should event loops treat I discussed this with Claude. Below is its suggestion. It's unverified, so please take it as a starting point, not a proposal:
Does this direction make sense to you, or do you have something else in mind? |
Found in revoltphp/event-loop#135, where the Windows CI hangs on callbacks on
STDOUT.WSAPoll()can only poll sockets, but the WSAPoll backend accepts any fd. Files and pipes give a CRT fd, soContext::add()succeeds for them. ThenWSAPoll()reportsPOLLNVALfor them, or fails withWSAENOTSOCKwhen they're alone. In both caseswait()drops them and returns at once. The watcher is never reported:This PR checks the fd with
getsockopt(SO_TYPE)inadd(), the waystream_select()tells sockets apart on Windows. Anything else fails withERROR_NOSUPPORT, as #23805 does for epoll. An event loop can then catch theFailedHandleAddExceptionand fall back tostream_select(). Revolt doesn't pick itsIo\Polldriver on Windows for now because of this.I left the
WSAENOTSOCKbranch ofwait()as is. This branch now only sees sockets that were closed after being added. It drops those sockets like the poll backend dropsPOLLNVAL./cc @bukka