add SendResponse::poll_reset and SendStream::poll_reset to listen for reset streams (#279)

This commit is contained in:
Sean McArthur
2018-05-30 22:57:43 +02:00
committed by GitHub
parent 82addd6369
commit 3a4633d205
11 changed files with 281 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
use std::io;
use codec::{RecvError, UserError};
use codec::UserError::*;
use frame::Reason;
use proto;
use proto::{self, PollReset};
use self::Inner::*;
use self::Peer::*;
@@ -399,8 +401,6 @@ impl State {
}
pub fn ensure_recv_open(&self) -> Result<bool, proto::Error> {
use std::io;
// TODO: Is this correct?
match self.inner {
Closed(Cause::Proto(reason)) |
@@ -412,6 +412,24 @@ impl State {
_ => Ok(true),
}
}
/// Returns a reason if the stream has been reset.
pub(super) fn ensure_reason(&self, mode: PollReset) -> Result<Option<Reason>, ::Error> {
match self.inner {
Closed(Cause::Proto(reason)) |
Closed(Cause::LocallyReset(reason)) |
Closed(Cause::Scheduled(reason)) => Ok(Some(reason)),
Closed(Cause::Io) => Err(proto::Error::Io(io::ErrorKind::BrokenPipe.into()).into()),
Open { local: Streaming, .. } |
HalfClosedRemote(Streaming) => match mode {
PollReset::AwaitingHeaders => {
Err(UserError::PollResetAfterSendResponse.into())
},
PollReset::Streaming => Ok(None),
},
_ => Ok(None),
}
}
}
impl Default for State {