Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Allow registration with empty interest #640
In order to temporarily disable event listening for a specific handle, it may be convenient to reregister it with an empty interest.
This avoids to temporarily deregister the handle before registering it again (which, by the way, is not supported on Windows).
Therefore, remove the check that prohibited registration with empty interest.
Note that ERROR and HUP may still be triggered in that case.
I agree that
But even in the case
In my client code using mio, for convenience I implemented a
@carllerche On IRC, you were wondering if using empty interest was portable across all platforms.
So we need to know if it works for the backends supported by mio: epoll, kqueue, IOCP, and also the backend used fuchsia (I saw some commits recently about fuchsia).
In order to test the "empty interest" behavior on each platform, I wrote a minimal sample that polls for readable events, then with empty interest, then for readable events again, so we can check that it behaves as expected: https://github.com/rom1v/mio-empty-interest
I executed it on Linux, Windows and Mac OS, I get the expected output:
I didn't test on fuchsia (@cramertj – or someone else –, could I ask you to execute this sample on fuchsia, please?).
The sample is maybe too minimal. Can you think of any specific situations were empty interest may lead to incorrect behavior?
I also use this patch in a "real-world" – not a sample – application where I often switch from/to non-empty/empty interests, it behaves as expected on Linux and Windows (I will test on Mac OS soon).
Currently, the mio library does not accept registering a handle with empty interest. As a workaround, we provided a wrapper that exposed an API that did, calling deregister/reregister internally as necessary. However, this workaround does not work on Windows, because deregister/reregister is not implemented: <tokio-rs/mio#633> Therefore, make mio accept empty interest directly: <tokio-rs/mio#640> This is implemented in our own fork, unless this change is accepted upstream or we manage to find a solution that works with the upstream version.
Concretely, it means calling
This is convenient when you initialize your interests conditionally, then call the same code whatever its value (without taking care of deregistering/reregistering):
carllerche left a comment
Thanks for the PR & sorry for the delay.
I did a quick skim of the various platform docs and I think this should be an OK change. I have added a request to expand on a test, but the change seems good besides that.
The registration of the client socket was missing, which is a problem on Windows.
I amended the commit to fix the issue.
In order to temporarily disable event listening for a specific handle, it may be convenient to reregister it with an empty interest. This avoids to temporarily deregister the handle before registering it again (which, by the way, is not supported on Windows). Therefore, remove the check that prohibited registration with empty interest. Note that ERROR and HUP may still be triggered in that case. : #633
Rust mio 0.6.11, the first release including the patch to support "empty interest", is available. Therefore, remove the temporary '[replace]' section in Cargo.toml, and use the last 0.6.x version. Also update other dependencies (generated by "cargo update"). <tokio-rs/mio#640>