0

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

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

1 Answers1

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