async-rs / async-tls

A TLS implementation over AsyncRead and AsyncWrite
https://async.rs
Apache License 2.0
167 stars 47 forks source link

Make TlsStream cloneable #18

Open NyxCode opened 4 years ago

NyxCode commented 4 years ago

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 commented 4 years ago

@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 https://github.com/http-rs/async-h1/issues/74

garbage-repo commented 4 months ago

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:

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.