Introduce ssl::Error::would_block

This commit is contained in:
Alessandro Ghedini 2023-06-23 10:44:20 +01:00 committed by Alessandro Ghedini
parent f67498cf00
commit 7b0de9341c
2 changed files with 25 additions and 29 deletions

View File

@ -81,6 +81,10 @@ impl Error {
_ => None, _ => None,
} }
} }
pub fn would_block(&self) -> bool {
matches!(self.code, ErrorCode::WANT_READ | ErrorCode::WANT_WRITE)
}
} }
impl From<ErrorStack> for Error { impl From<ErrorStack> for Error {

View File

@ -3242,11 +3242,9 @@ impl<S> MidHandshakeSslStream<S> {
Ok(self.stream) Ok(self.stream)
} else { } else {
self.error = self.stream.make_error(ret); self.error = self.stream.make_error(ret);
match self.error.code() { match self.error.would_block() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => { true => Err(HandshakeError::WouldBlock(self)),
Err(HandshakeError::WouldBlock(self)) false => Err(HandshakeError::Failure(self)),
}
_ => Err(HandshakeError::Failure(self)),
} }
} }
} }
@ -3606,14 +3604,12 @@ where
Ok(stream) Ok(stream)
} else { } else {
let error = stream.make_error(ret); let error = stream.make_error(ret);
match error.code() { match error.would_block() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => { true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream { stream,
stream, error,
error, })),
})) false => Err(HandshakeError::Failure(MidHandshakeSslStream {
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream, stream,
error, error,
})), })),
@ -3633,14 +3629,12 @@ where
Ok(stream) Ok(stream)
} else { } else {
let error = stream.make_error(ret); let error = stream.make_error(ret);
match error.code() { match error.would_block() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => { true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream { stream,
stream, error,
error, })),
})) false => Err(HandshakeError::Failure(MidHandshakeSslStream {
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream, stream,
error, error,
})), })),
@ -3662,14 +3656,12 @@ where
Ok(stream) Ok(stream)
} else { } else {
let error = stream.make_error(ret); let error = stream.make_error(ret);
match error.code() { match error.would_block() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => { true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream { stream,
stream, error,
error, })),
})) false => Err(HandshakeError::Failure(MidHandshakeSslStream {
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream, stream,
error, error,
})), })),