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

Make TlsStream cloneable #18

Open
NyxCode opened this issue Feb 15, 2020 · 2 comments
Open

Make TlsStream cloneable #18

NyxCode opened this issue Feb 15, 2020 · 2 comments

Comments

@NyxCode
Copy link

NyxCode commented Feb 15, 2020

async_std::net::TcpStream implements Clone, which makes it possible to read and write to a socket at the same time.
Official async-std example
This library does not implement Clone for TlsStream, neither does it implement AsyncRead or AsyncWrite for &TlsStream.
How would I rewrite the example above to use TLS when TlsStream is not clonable?

@abhishekc-sharma
Copy link

@yoshuawuyts Correct me if I'm wrong but one of the changes suggested by @NyxCode above would need to be implemented to apply either of the solutions suggested in http-rs/async-h1#74

@garbage-repo
Copy link

garbage-repo commented Jun 5, 2024

I'm making a simple proxy server. So being able to read/write a TlsStream in 2 separate threads is a must.

If people are still interested in this, there's a unsafe work-around:

  • Lets say you have a TlsStream, and call it reader.
  • Use ptr::read() to make a copy of reader, name it writer.
  • Use ManuallyDrop to wrap both reader and writer.
  • Send them out to 2 threads.
  • When done, call ManuallyDrop::drop() on one (and only one) of them.

Tests worked for me. My code is not in production yet. But this is the only hack for me. I hope this helps someone else.


In long term, I hope crate authors could provide some split() function, which splits a TlsStream into 2 parts: one readable-only, one writable-only. I'm sorry that I don't have much knowledge about underlying TLS limits, but I hope that can be safely implemented. As I understand this: those 2 parts do not conflict.

--- Edited ---

I'm sorry it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants