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

Should be able to poll on a &TcpListener #1413

Closed
jethrogb opened this issue Aug 8, 2019 · 10 comments
Closed

Should be able to poll on a &TcpListener #1413

jethrogb opened this issue Aug 8, 2019 · 10 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net

Comments

@jethrogb
Copy link

jethrogb commented Aug 8, 2019

Version

0.1.x

Subcrates

tokio-tcp

Description

Accepting a connection in std doesn't require mutable access to the TcpListener, so polling for the same should also not require it. However, there is currently no way to poll a &TcpListener.

TcpStream does support this through impl AsyncRead|AsyncWrite for &'_ TcpStream (although this was recently removed in master)

@carllerche
Copy link
Member

Can you describe why you want this? In general, TcpStream supports Sync but TcpStream does not support concurrent polling of poll_read. This is why &mut self is used.

@jethrogb
Copy link
Author

jethrogb commented Aug 9, 2019

TcpStream does not support concurrent polling of poll_read

As mentioned this is supported through impl AsyncRead|AsyncWrite for &'_ TcpStream

@carllerche
Copy link
Member

@jethrogb one task can call poll_ready concurrently to another calling poll_write, but two tasks cannot concurrently call poll_read. This is due to only one one task being notified.

Could you describe the use case? There could be a better way to model what you are trying to do.

@Darksonn Darksonn added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net labels Jul 25, 2020
@Darksonn
Copy link
Contributor

This is not a feature we want for now. Split the TcpStream instead.

@jethrogb
Copy link
Author

@Darksonn not sure what you're talking about? This issue is about TcpListener, not TcpStream.

@Darksonn Darksonn reopened this Jul 25, 2020
@Darksonn
Copy link
Contributor

Oh sorry, I misread the issue title.

@Darksonn
Copy link
Contributor

Still, I don't think this is possible with how mio works. When you poll something, only the last used Waker is notified of updates, so if you poll it from many places, only one of them will actually work.

@jethrogb
Copy link
Author

That seems fine, the woken up place will accept a connection and other place will get woken up next time?

@Darksonn
Copy link
Contributor

No, if you poll it from two places, one of them will keep getting all of the connections and the other is never woken up again. This is because only the last waker is woken.

@carllerche
Copy link
Member

This is covered by #2779 and will be supported once that lands.

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 C-feature-request Category: A feature request. M-net Module: tokio/net
Projects
None yet
Development

No branches or pull requests

3 participants