Merge branch 'master' into ver/flowio

This commit is contained in:
Oliver Gould
2017-07-10 01:15:36 +00:00
18 changed files with 557 additions and 168 deletions

View File

@@ -1,4 +1,7 @@
use {ConnectionError, Reason, Peer};
use Peer;
use error::ConnectionError;
use error::Reason::*;
use error::User::*;
use proto::FlowController;
/// Represents the state of an H2 stream
@@ -101,7 +104,7 @@ impl State {
Ok(true)
}
Open { local, remote } => {
try!(remote.check_is_headers(Reason::ProtocolError));
try!(remote.check_is_headers(ProtocolError.into()));
*self = if eos {
HalfClosedRemote(local)
@@ -113,7 +116,7 @@ impl State {
Ok(false)
}
HalfClosedLocal(remote) => {
try!(remote.check_is_headers(Reason::ProtocolError));
try!(remote.check_is_headers(ProtocolError.into()));
*self = if eos {
Closed
@@ -124,7 +127,36 @@ impl State {
Ok(false)
}
Closed | HalfClosedRemote(..) => {
Err(Reason::ProtocolError.into())
Err(ProtocolError.into())
}
_ => unimplemented!(),
}
}
pub fn recv_data(&mut self, eos: bool) -> Result<(), ConnectionError> {
use self::State::*;
match *self {
Open { local, remote } => {
try!(remote.check_is_data(ProtocolError.into()));
if eos {
*self = HalfClosedRemote(local);
}
Ok(())
}
HalfClosedLocal(remote) => {
try!(remote.check_is_data(ProtocolError.into()));
if eos {
*self = Closed;
}
Ok(())
}
Closed | HalfClosedRemote(..) => {
Err(ProtocolError.into())
}
_ => unimplemented!(),
}
@@ -152,7 +184,7 @@ impl State {
Ok(true)
}
Open { local, remote } => {
try!(local.check_is_headers(Reason::InternalError));
try!(local.check_is_headers(UnexpectedFrameType.into()));
*self = if eos {
HalfClosedLocal(remote)
@@ -164,7 +196,7 @@ impl State {
Ok(false)
}
HalfClosedRemote(local) => {
try!(local.check_is_headers(Reason::InternalError));
try!(local.check_is_headers(UnexpectedFrameType.into()));
*self = if eos {
Closed
@@ -175,7 +207,36 @@ impl State {
Ok(false)
}
Closed | HalfClosedLocal(..) => {
Err(Reason::InternalError.into())
Err(UnexpectedFrameType.into())
}
_ => unimplemented!(),
}
}
pub fn send_data(&mut self, eos: bool) -> Result<(), ConnectionError> {
use self::State::*;
match *self {
Open { local, remote } => {
try!(local.check_is_data(UnexpectedFrameType.into()));
if eos {
*self = HalfClosedLocal(remote);
}
Ok(())
}
HalfClosedRemote(local) => {
try!(local.check_is_data(UnexpectedFrameType.into()));
if eos {
*self = Closed;
}
Ok(())
}
Closed | HalfClosedLocal(..) => {
Err(UnexpectedFrameType.into())
}
_ => unimplemented!(),
}
@@ -184,12 +245,22 @@ impl State {
impl PeerState {
#[inline]
fn check_is_headers(&self, err: Reason) -> Result<(), ConnectionError> {
fn check_is_headers(&self, err: ConnectionError) -> Result<(), ConnectionError> {
use self::PeerState::*;
match *self {
Headers => Ok(()),
_ => Err(err.into()),
_ => Err(err),
}
}
#[inline]
fn check_is_data(&self, err: ConnectionError) -> Result<(), ConnectionError> {
use self::PeerState::*;
match *self {
Data { .. } => Ok(()),
_ => Err(err),
}
}
}