Fix connect and accept error reporting

We were previously trying to create an error twice so the second
wouldn't be correct.
This commit is contained in:
Steven Fackler 2016-01-22 15:34:31 -08:00
parent 3640edd17a
commit b7d3357f37
1 changed files with 16 additions and 20 deletions

View File

@ -1094,10 +1094,9 @@ impl<S: Read + Write> SslStream<S> {
if ret > 0 { if ret > 0 {
Ok(stream) Ok(stream)
} else { } else {
match stream.make_error(ret) { match stream.make_old_error(ret) {
// This is fine - nonblocking sockets will finish the handshake in read/write Some(err) => Err(err),
Error::WantRead(..) | Error::WantWrite(..) => Ok(stream), None => Ok(stream),
_ => Err(stream.make_old_error(ret)),
} }
} }
} }
@ -1110,10 +1109,9 @@ impl<S: Read + Write> SslStream<S> {
if ret > 0 { if ret > 0 {
Ok(stream) Ok(stream)
} else { } else {
match stream.make_error(ret) { match stream.make_old_error(ret) {
// This is fine - nonblocking sockets will finish the handshake in read/write Some(err) => Err(err),
Error::WantRead(..) | Error::WantWrite(..) => Ok(stream), None => Ok(stream),
_ => Err(stream.make_old_error(ret)),
} }
} }
} }
@ -1188,11 +1186,11 @@ impl<S> SslStream<S> {
} }
} }
fn make_old_error(&mut self, ret: c_int) -> SslError { fn make_old_error(&mut self, ret: c_int) -> Option<SslError> {
self.check_panic(); self.check_panic();
match self.ssl.get_error(ret) { match self.ssl.get_error(ret) {
LibSslError::ErrorSsl => SslError::get(), LibSslError::ErrorSsl => Some(SslError::get()),
LibSslError::ErrorSyscall => { LibSslError::ErrorSyscall => {
let err = SslError::get(); let err = SslError::get();
let count = match err { let count = match err {
@ -1201,22 +1199,20 @@ impl<S> SslStream<S> {
}; };
if count == 0 { if count == 0 {
if ret == 0 { if ret == 0 {
SslError::StreamError(io::Error::new(io::ErrorKind::ConnectionAborted, Some(SslError::StreamError(io::Error::new(io::ErrorKind::ConnectionAborted,
"unexpected EOF observed")) "unexpected EOF observed")))
} else { } else {
SslError::StreamError(self.get_bio_error()) Some(SslError::StreamError(self.get_bio_error()))
} }
} else { } else {
err Some(err)
} }
} }
LibSslError::ErrorZeroReturn => SslError::SslSessionClosed, LibSslError::ErrorZeroReturn => Some(SslError::SslSessionClosed),
LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => { LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => None,
SslError::StreamError(self.get_bio_error())
}
err => { err => {
SslError::StreamError(io::Error::new(io::ErrorKind::Other, Some(SslError::StreamError(io::Error::new(io::ErrorKind::Other,
format!("unexpected error {:?}", err))) format!("unexpected error {:?}", err))))
} }
} }
} }