From aa37dba0bc139fb9c866b6a57b5028227313df7a Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 10 Dec 2015 21:58:22 -0800 Subject: Make error handling more reliable --- openssl/src/ssl/mod.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'openssl/src/ssl') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 5ac6d33e..bc64d7c8 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1000,20 +1000,30 @@ impl SslStream { SslError::StreamError(io::Error::new(io::ErrorKind::ConnectionAborted, "unexpected EOF observed")) } else { - let error = unsafe { bio::take_error::(self.ssl.get_raw_rbio()) }; - SslError::StreamError(error.unwrap()) + SslError::StreamError(self.get_bio_error()) } } else { err } } + LibSslError::ErrorZeroReturn => SslError::SslSessionClosed, LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => { - let error = unsafe { bio::take_error::(self.ssl.get_raw_rbio()) }; - SslError::StreamError(error.unwrap()) + SslError::StreamError(self.get_bio_error()) } - err => panic!("unexpected error {:?} with ret {}", err, ret), + err => SslError::StreamError(io::Error::new(io::ErrorKind::Other, + format!("unexpected error {:?}", err))), } } + + fn get_bio_error(&mut self) -> io::Error { + let error = unsafe { bio::take_error::(self.ssl.get_raw_rbio()) }; + match error { + Some(error) => error, + None => io::Error::new(io::ErrorKind::Other, + "BUG: got an ErrorSyscall without an error in the BIO?") + } + } + /// Returns a reference to the underlying stream. pub fn get_ref(&self) -> &S { unsafe { @@ -1057,6 +1067,7 @@ impl Read for SslStream { } match self.make_error(ret) { + SslError::SslSessionClosed => Ok(0), SslError::StreamError(e) => Err(e), e => Err(io::Error::new(io::ErrorKind::Other, e)), } -- cgit v1.2.3