Skip to content

Commit

Permalink
fix: don't panic if co-op budget exceeded (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac authored Jan 2, 2024
1 parent feee126 commit d4c83ba
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::handshake::HandshakeResult;
use crate::trace;
use crate::TestOptions;
use futures::future::poll_fn;
use futures::task::noop_waker_ref;
use futures::task::Context;
use futures::task::Poll;
use futures::task::Waker;
Expand Down Expand Up @@ -648,11 +647,8 @@ impl AsyncRead for TlsStream {
} => {
// If the handshake completed, we want to finalize it and then continue
if handle.is_finished() {
let Poll::Ready(res) =
handle.poll_unpin(&mut Context::from_waker(noop_waker_ref()))
else {
unreachable!()
};
// This may return Pending if we've exhausted the co-op budget
let res = ready!(handle.poll_unpin(cx));
self.finalize_handshake(res)?;
continue;
}
Expand Down Expand Up @@ -695,11 +691,8 @@ impl AsyncWrite for TlsStream {
} => {
// If the handshake completed, we want to finalize it and then continue
if handle.is_finished() {
let Poll::Ready(res) =
handle.poll_unpin(&mut Context::from_waker(noop_waker_ref()))
else {
unreachable!()
};
// This may return Pending if we've exhausted the co-op budget
let res = ready!(handle.poll_unpin(cx));
self.finalize_handshake(res)?;
continue;
}
Expand Down Expand Up @@ -752,11 +745,8 @@ impl AsyncWrite for TlsStream {
} => {
// If the handshake completed, we want to finalize it and then continue
if handle.is_finished() {
let Poll::Ready(res) =
handle.poll_unpin(&mut Context::from_waker(noop_waker_ref()))
else {
unreachable!()
};
// This may return Pending if we've exhausted the co-op budget
let res = ready!(handle.poll_unpin(cx));
self.finalize_handshake(res)?;
continue;
}
Expand Down Expand Up @@ -809,12 +799,10 @@ impl AsyncWrite for TlsStream {
handle,
..
} => {
// If the handshake completed, we want to finalize it and then continue
if handle.is_finished() {
let Poll::Ready(res) =
handle.poll_unpin(&mut Context::from_waker(noop_waker_ref()))
else {
unreachable!()
};
// This may return Pending if we've exhausted the co-op budget
let res = ready!(handle.poll_unpin(cx));
self.finalize_handshake(res)?;
continue;
}
Expand Down

0 comments on commit d4c83ba

Please sign in to comment.