From e85b49d3755375b3e535cbd4b07d4fbf953948cb Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 21:19:16 -0800 Subject: Work around the worst of clone bogusness SslStream::{clone,try_clone} are inherently broken since the Ssl object shared by both streams is only going to be talking to one stream. Stuff like hyper depends on try_clone, so we'll leave it here for now but minimize the brokenness to "no worse than what it used to be like". They'll be removed in 0.8. cc #325 --- openssl/src/ssl/mod.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'openssl/src/ssl/mod.rs') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index d529347f..b4385290 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -10,7 +10,7 @@ use std::str; use std::net; use std::path::Path; use std::ptr; -use std::sync::{Once, ONCE_INIT, Mutex}; +use std::sync::{Once, ONCE_INIT, Mutex, Arc}; use std::cmp; use std::any::Any; #[cfg(any(feature = "npn", feature = "alpn"))] @@ -778,6 +778,7 @@ impl Drop for Ssl { } impl Clone for Ssl { + /// # Deprecated fn clone(&self) -> Ssl { unsafe { rust_SSL_clone(self.ssl) }; Ssl { ssl: self.ssl } @@ -1003,23 +1004,22 @@ make_LibSslError! { /// A stream wrapper which handles SSL encryption for an underlying stream. pub struct SslStream { ssl: Ssl, - _method: Box, // :( + _method: Arc, // NOTE: this *must* be after the Ssl field so things drop right _p: PhantomData, } unsafe impl Send for SslStream {} impl Clone for SslStream { + /// # Deprecated + /// + /// This method does not behave as expected and will be removed in a future + /// release. fn clone(&self) -> SslStream { - let stream = self.get_ref().clone(); - Self::new_base(self.ssl.clone(), stream) - } -} - -impl Drop for SslStream { - fn drop(&mut self) { - unsafe { - let _ = bio::take_stream::(self.ssl.get_raw_rbio()); + SslStream { + ssl: self.ssl.clone(), + _method: self._method.clone(), + _p: PhantomData, } } } @@ -1232,10 +1232,16 @@ impl SslStream { } impl SslStream<::std::net::TcpStream> { - /// Like `TcpStream::try_clone`. + /// # Deprecated + /// + /// This method does not behave as expected and will be removed in a future + /// release. pub fn try_clone(&self) -> io::Result> { - let stream = try!(self.get_ref().try_clone()); - Ok(Self::new_base(self.ssl.clone(), stream)) + Ok(SslStream { + ssl: self.ssl.clone(), + _method: self._method.clone(), + _p: PhantomData + }) } } -- cgit v1.2.3 From a31acdbb93988638afb1d3c211e5ef6a3219a30c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:21:23 -0800 Subject: Fix deprecation location --- openssl/src/ssl/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openssl/src/ssl/mod.rs') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index b4385290..ec37bf0f 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1010,11 +1010,11 @@ pub struct SslStream { unsafe impl Send for SslStream {} +/// # Deprecated +/// +/// This method does not behave as expected and will be removed in a future +/// release. impl Clone for SslStream { - /// # Deprecated - /// - /// This method does not behave as expected and will be removed in a future - /// release. fn clone(&self) -> SslStream { SslStream { ssl: self.ssl.clone(), -- cgit v1.2.3 From 11129aa5214b7ed70027368d52715c7d4e2247c2 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:34:30 -0800 Subject: Rustfmt --- openssl/src/ssl/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openssl/src/ssl/mod.rs') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index ec37bf0f..955f10fd 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1240,7 +1240,7 @@ impl SslStream<::std::net::TcpStream> { Ok(SslStream { ssl: self.ssl.clone(), _method: self._method.clone(), - _p: PhantomData + _p: PhantomData, }) } } -- cgit v1.2.3