Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying custom interest for TcpStream #5796

Closed
wants to merge 1 commit into from

Conversation

leftmostcat
Copy link

With the addition of Interest::PRIORITY, it is possible to ask ready() to wake on urgent data. However, because PollEvented is set up with only read/write interest, ready()'s future will never complete.

Add support for specifying custom interest in the creation of PollEvented to allow ready() to correctly poll for urgent.

Fixes: #5784

Motivation

It is not currently possible to poll for urgent data via TcpStream. Interest::PRIORITY was added in mio, support for it was added to AsyncFd, and it's possible to pass Interest::PRIORITY to TcpStream::ready(), but it it will never be resolved due to a lack of API for registering the interest for PollEvented.

Solution

Provide API parallel to AsyncFd's with_interest() to API which returns a TcpStream. The primary entry points are TcpStream::connect() and TcpListener::accept(), so provide connect_with_interest() and accept_with_interest().

@leftmostcat
Copy link
Author

No automated tests have been added; I'm not sure where it would be appropriate to add them, particularly given that Interest::PRIORITY is presently restricted to Linux/Android.

With the addition of Interest::PRIORITY, it is possible to ask `ready()`
to wake on urgent data. However, because `PollEvented` is set up with
only read/write interest, `ready()`'s future will never complete.

Add support for specifying custom interest in the creation of
`PollEvented` to allow `ready()` to correctly poll for urgent.

Fixes: tokio-rs#5784
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-net Module: tokio/net labels Jun 15, 2023
Copy link
Contributor

@folkertdev folkertdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think a test for this logic is required. I'd guess tests/tcp_stream or tests/tcp_socket is the natural location. You can just use a cfg(target_os = "linux") on the test, cfgs happen in a bunch of places already, also in the tests.

In 4a254e9 I even made a custom file for the test. The code was removed from #5566 to simplify that PR (and because I don't need that functionality), but it may provide inspiration now.

@@ -158,13 +158,58 @@ impl TcpListener {
/// }
/// ```
pub async fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
self.accept_with_interest(Default::default()).await
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is a general practice, but I'd prefer Interest::default() here to make it clearer that we're passing an interest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also assuming that the Default instance is a good choice, which I'm not sure about.

Comment on lines +139 to +144
impl Default for Interest {
fn default() -> Self {
Interest::READABLE.add(Interest::WRITABLE)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this truly a reasonable default for Interest? I think Interest::READABLE | Interest::WRITABLE written out in full is always clearer.

@Darksonn
Copy link
Contributor

I'm closing this as stale. There are some reviews by folkertdev that would be good to address. If you want to continue this work, feel free to reopen.

@Darksonn Darksonn closed this Jan 30, 2024
@mox692
Copy link
Member

mox692 commented Feb 24, 2024

@leftmostcat Hi, are you still actively working on this? If not, I would like to continue working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interest::PRIORITY never ready on TcpStream
4 participants