-
Notifications
You must be signed in to change notification settings - Fork 115
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 try_clone on TcpStream #198
Comments
Thanks for the report! Unfortunately this is a pretty difficult notion on the backend, however, as the semantics of duplicate file descriptors and epoll notifications tends to get... interesting. (much less the Windows semantics as well). I don't think it's impossible but I don't think it's easy either, and we currently haven't put a huge amount of thought into how to do this. For now could you use something like |
Thanks for your reply, much appreciated. I will take a look at I see there is a good example here. |
Relates to tokio-rs/mio#361 |
A few notes…
The use case of the standard However, there is |
You can create a tokio broadcast channel and subscribe to it in the TcpStream handler fn, then when you get new messages you send them back to the TcpStream, no need to clone it. |
Another good option is to convert the tokio Then you can eventually do
|
This method takes the ownership of the origin tokio's tcpstream object, which can cause problem somewhere (for example, the stream itself is a field of another struct) |
Is it possible to implement the try_clone method for the tokio TcpStream type?
I'm using the echo server example, eventually I am hoping to be able to iterate through all the currently connected sockets and broadcast a message to them one by one.
Lets say I have the following code:
The code fails to compile as try_clone is not implemented.
It appears that TcpStream in the standard library does allow the cloning of TcpStream objects.
Is there a way to work around this? Apologies I am very new to Rust, so what I am trying to do might not make any sense at all.
The text was updated successfully, but these errors were encountered: