Repository navigation
Add Poll::prepare_external_wait - #2030
Open
guybedford wants to merge 1 commit into
Open
guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
Returns the selector's waitable handle for a wait outside of Poll::poll, such as by a host event loop. On Windows, socket interest is submitted to the kernel lazily at the start of select, so this submits the queued interest and, until the next poll, submits further (re)registrations immediately, as when a thread is blocked in select.
guybedford
force-pushed
the
external-wait
branch
from
October 19, 2026 03:13
703b7be to
01635d4
Compare
This branch has not been deployed
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.
This implements an alternative to #2023 providing a
Poll::prepare_external_waitfor integrating with host event loops cross-platform.The hosted event loop concept in tokio-rs/tokio#8479 is that the host waits on the selector's handle instead of calling
Poll::pollto block. This works fine on the Unix theepoll/kqueuefd, but on Windows, a raw completion port handle submits socket interest lazily, at the start of select, unless a thread is already blocked in it. A source that was registered or reregistered, or that returnedWouldBlock, since the last poll (or that does so on another thread during the host's wait) never signals the port, and the host misses the event.Whether such a cooperative model on Windows should be supported in such a way in Mio is of course an outstanding question, so this is posted just to push the conversation forward as opposed to trying to set an explicit direction, while I've been working on this problem.
This instead creates a contract for the hosted model using a new
prepare_external_wait()method, which replaces the raw handle/fd usage:Poll::poll, the handle becomes ready whenever events may be available, including for sources registered, reregistered or returningWouldBlockon any thread after the call. Waiting doesn't consume events, and a ready handle doesn't guarantee events.select. The nextselectends it.epoll/kqueue: returns the descriptor and does nothing else.poll(2)and Solaris event ports: returnErrorKind::Unsupported, since neither has a descriptor that reflects all registrations (event ports watch delivered interests withpoll(2)insideselect).A host can then integrate its own loop something like:
Tests cover registration, reregistration and WouldBlock before and after the call and from other threads, blocked waits from the polling thread and from a thread that never polled, and
WaitForMultipleObjects/MsgWaitForMultipleObjectsExon Windows.