Skip to content

Commit

Permalink
Introduce ssl::Error::would_block
Browse files Browse the repository at this point in the history
  • Loading branch information
ghedo authored and nox committed Aug 3, 2023
1 parent bb063aa commit 4b16781
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
4 changes: 4 additions & 0 deletions boring/src/ssl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl Error {
_ => None,
}
}

pub fn would_block(&self) -> bool {
matches!(self.code, ErrorCode::WANT_READ | ErrorCode::WANT_WRITE)
}
}

impl From<ErrorStack> for Error {
Expand Down
50 changes: 21 additions & 29 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3162,11 +3162,9 @@ impl<S> MidHandshakeSslStream<S> {
Ok(self.stream)
} else {
self.error = self.stream.make_error(ret);
match self.error.code() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
Err(HandshakeError::WouldBlock(self))
}
_ => Err(HandshakeError::Failure(self)),
match self.error.would_block() {
true => Err(HandshakeError::WouldBlock(self)),
false => Err(HandshakeError::Failure(self)),
}
}
}
Expand Down Expand Up @@ -3471,14 +3469,12 @@ where
Ok(stream)
} else {
let error = stream.make_error(ret);
match error.code() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
}))
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
match error.would_block() {
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
})),
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
})),
Expand All @@ -3494,14 +3490,12 @@ where
Ok(stream)
} else {
let error = stream.make_error(ret);
match error.code() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
}))
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
match error.would_block() {
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
})),
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
})),
Expand All @@ -3523,14 +3517,12 @@ where
Ok(stream)
} else {
let error = stream.make_error(ret);
match error.code() {
ErrorCode::WANT_READ | ErrorCode::WANT_WRITE => {
Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
}))
}
_ => Err(HandshakeError::Failure(MidHandshakeSslStream {
match error.would_block() {
true => Err(HandshakeError::WouldBlock(MidHandshakeSslStream {
stream,
error,
})),
false => Err(HandshakeError::Failure(MidHandshakeSslStream {
stream,
error,
})),
Expand Down

0 comments on commit 4b16781

Please sign in to comment.