Make error handling more reliable
This commit is contained in:
parent
91f8c542f7
commit
aa37dba0bc
|
|
@ -1000,20 +1000,30 @@ impl<S> SslStream<S> {
|
||||||
SslError::StreamError(io::Error::new(io::ErrorKind::ConnectionAborted,
|
SslError::StreamError(io::Error::new(io::ErrorKind::ConnectionAborted,
|
||||||
"unexpected EOF observed"))
|
"unexpected EOF observed"))
|
||||||
} else {
|
} else {
|
||||||
let error = unsafe { bio::take_error::<S>(self.ssl.get_raw_rbio()) };
|
SslError::StreamError(self.get_bio_error())
|
||||||
SslError::StreamError(error.unwrap())
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LibSslError::ErrorZeroReturn => SslError::SslSessionClosed,
|
||||||
LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => {
|
LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => {
|
||||||
|
SslError::StreamError(self.get_bio_error())
|
||||||
|
}
|
||||||
|
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::<S>(self.ssl.get_raw_rbio()) };
|
let error = unsafe { bio::take_error::<S>(self.ssl.get_raw_rbio()) };
|
||||||
SslError::StreamError(error.unwrap())
|
match error {
|
||||||
}
|
Some(error) => error,
|
||||||
err => panic!("unexpected error {:?} with ret {}", err, ret),
|
None => io::Error::new(io::ErrorKind::Other,
|
||||||
|
"BUG: got an ErrorSyscall without an error in the BIO?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the underlying stream.
|
/// Returns a reference to the underlying stream.
|
||||||
pub fn get_ref(&self) -> &S {
|
pub fn get_ref(&self) -> &S {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -1057,6 +1067,7 @@ impl<S: Read> Read for SslStream<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.make_error(ret) {
|
match self.make_error(ret) {
|
||||||
|
SslError::SslSessionClosed => Ok(0),
|
||||||
SslError::StreamError(e) => Err(e),
|
SslError::StreamError(e) => Err(e),
|
||||||
e => Err(io::Error::new(io::ErrorKind::Other, e)),
|
e => Err(io::Error::new(io::ErrorKind::Other, e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue