std::net::TcpStream
has the try_clone()
method to clone the underlying socket, but there's nothing similar for openssl::ssl::SslStream
.
Asked
Active
Viewed 347 times
0

Shepmaster
- 388,571
- 95
- 1,107
- 1,366

Nicolas Penot
- 40
- 5
1 Answers
2
It doesn't make sense to clone an SslStream
as the SSL / TLS logic contains state. All the clones need to agree on and update that state.
In fact, it used to implement Clone
and it was deprecated and removed because it was a large footgun.
You will need to wrap it in an Arc<Mutex<_>>
or equivalent and clone that. Another approach would be to restructure your code so that only one thing has ownership of the stream and you communicate via other techniques.
See also:

Shepmaster
- 388,571
- 95
- 1,107
- 1,366