chore: cargo fmt, clippy
This commit is contained in:
committed by
Sean McArthur
parent
e72d6dc189
commit
f46840f3fa
@@ -1,7 +1,7 @@
|
||||
use std::io;
|
||||
|
||||
use crate::codec::{RecvError, UserError};
|
||||
use crate::codec::UserError::*;
|
||||
use crate::codec::{RecvError, UserError};
|
||||
use crate::frame::Reason;
|
||||
use crate::proto::{self, PollReset};
|
||||
|
||||
@@ -94,37 +94,40 @@ impl State {
|
||||
let local = Streaming;
|
||||
|
||||
self.inner = match self.inner {
|
||||
Idle => if eos {
|
||||
HalfClosedLocal(AwaitingHeaders)
|
||||
} else {
|
||||
Open {
|
||||
local,
|
||||
remote: AwaitingHeaders,
|
||||
Idle => {
|
||||
if eos {
|
||||
HalfClosedLocal(AwaitingHeaders)
|
||||
} else {
|
||||
Open {
|
||||
local,
|
||||
remote: AwaitingHeaders,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Open {
|
||||
local: AwaitingHeaders,
|
||||
remote,
|
||||
} => if eos {
|
||||
HalfClosedLocal(remote)
|
||||
} else {
|
||||
Open {
|
||||
local,
|
||||
remote,
|
||||
} => {
|
||||
if eos {
|
||||
HalfClosedLocal(remote)
|
||||
} else {
|
||||
Open { local, remote }
|
||||
}
|
||||
},
|
||||
HalfClosedRemote(AwaitingHeaders) => if eos {
|
||||
Closed(Cause::EndStream)
|
||||
} else {
|
||||
HalfClosedRemote(local)
|
||||
},
|
||||
}
|
||||
HalfClosedRemote(AwaitingHeaders) => {
|
||||
if eos {
|
||||
Closed(Cause::EndStream)
|
||||
} else {
|
||||
HalfClosedRemote(local)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// All other transitions result in a protocol error
|
||||
return Err(UnexpectedFrameType);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Opens the receive-half of the stream when a HEADERS frame is received.
|
||||
@@ -146,7 +149,7 @@ impl State {
|
||||
remote,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
ReservedRemote => {
|
||||
initial = true;
|
||||
|
||||
@@ -155,31 +158,32 @@ impl State {
|
||||
} else {
|
||||
HalfClosedLocal(Streaming)
|
||||
}
|
||||
},
|
||||
}
|
||||
Open {
|
||||
local,
|
||||
remote: AwaitingHeaders,
|
||||
} => if eos {
|
||||
HalfClosedRemote(local)
|
||||
} else {
|
||||
Open {
|
||||
local,
|
||||
remote,
|
||||
} => {
|
||||
if eos {
|
||||
HalfClosedRemote(local)
|
||||
} else {
|
||||
Open { local, remote }
|
||||
}
|
||||
},
|
||||
HalfClosedLocal(AwaitingHeaders) => if eos {
|
||||
Closed(Cause::EndStream)
|
||||
} else {
|
||||
HalfClosedLocal(remote)
|
||||
},
|
||||
}
|
||||
HalfClosedLocal(AwaitingHeaders) => {
|
||||
if eos {
|
||||
Closed(Cause::EndStream)
|
||||
} else {
|
||||
HalfClosedLocal(remote)
|
||||
}
|
||||
}
|
||||
state => {
|
||||
// All other transitions result in a protocol error
|
||||
proto_err!(conn: "recv_open: in unexpected state {:?}", state);
|
||||
return Err(RecvError::Connection(Reason::PROTOCOL_ERROR));
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
return Ok(initial);
|
||||
Ok(initial)
|
||||
}
|
||||
|
||||
/// Transition from Idle -> ReservedRemote
|
||||
@@ -188,7 +192,7 @@ impl State {
|
||||
Idle => {
|
||||
self.inner = ReservedRemote;
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
state => {
|
||||
proto_err!(conn: "reserve_remote: in unexpected state {:?}", state);
|
||||
Err(RecvError::Connection(Reason::PROTOCOL_ERROR))
|
||||
@@ -199,19 +203,17 @@ impl State {
|
||||
/// Indicates that the remote side will not send more data to the local.
|
||||
pub fn recv_close(&mut self) -> Result<(), RecvError> {
|
||||
match self.inner {
|
||||
Open {
|
||||
local, ..
|
||||
} => {
|
||||
Open { local, .. } => {
|
||||
// The remote side will continue to receive data.
|
||||
log::trace!("recv_close: Open => HalfClosedRemote({:?})", local);
|
||||
self.inner = HalfClosedRemote(local);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
HalfClosedLocal(..) => {
|
||||
log::trace!("recv_close: HalfClosedLocal => Closed");
|
||||
self.inner = Closed(Cause::EndStream);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
state => {
|
||||
proto_err!(conn: "recv_close: in unexpected state {:?}", state);
|
||||
Err(RecvError::Connection(Reason::PROTOCOL_ERROR))
|
||||
@@ -228,7 +230,7 @@ impl State {
|
||||
match self.inner {
|
||||
// If the stream is already in a `Closed` state, do nothing,
|
||||
// provided that there are no frames still in the send queue.
|
||||
Closed(..) if !queued => {},
|
||||
Closed(..) if !queued => {}
|
||||
// A notionally `Closed` stream may still have queued frames in
|
||||
// the following cases:
|
||||
//
|
||||
@@ -246,11 +248,12 @@ impl State {
|
||||
state => {
|
||||
log::trace!(
|
||||
"recv_reset; reason={:?}; state={:?}; queued={:?}",
|
||||
reason, state, queued
|
||||
reason,
|
||||
state,
|
||||
queued
|
||||
);
|
||||
self.inner = Closed(Cause::Proto(reason));
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,20 +262,20 @@ impl State {
|
||||
use crate::proto::Error::*;
|
||||
|
||||
match self.inner {
|
||||
Closed(..) => {},
|
||||
Closed(..) => {}
|
||||
_ => {
|
||||
log::trace!("recv_err; err={:?}", err);
|
||||
self.inner = Closed(match *err {
|
||||
Proto(reason) => Cause::LocallyReset(reason),
|
||||
Io(..) => Cause::Io,
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recv_eof(&mut self) {
|
||||
match self.inner {
|
||||
Closed(..) => {},
|
||||
Closed(..) => {}
|
||||
s => {
|
||||
log::trace!("recv_eof; state={:?}", s);
|
||||
self.inner = Closed(Cause::Io);
|
||||
@@ -283,17 +286,15 @@ impl State {
|
||||
/// Indicates that the local side will not send more data to the local.
|
||||
pub fn send_close(&mut self) {
|
||||
match self.inner {
|
||||
Open {
|
||||
remote, ..
|
||||
} => {
|
||||
Open { remote, .. } => {
|
||||
// The remote side will continue to receive data.
|
||||
log::trace!("send_close: Open => HalfClosedLocal({:?})", remote);
|
||||
self.inner = HalfClosedLocal(remote);
|
||||
},
|
||||
}
|
||||
HalfClosedRemote(..) => {
|
||||
log::trace!("send_close: HalfClosedRemote => Closed");
|
||||
self.inner = Closed(Cause::EndStream);
|
||||
},
|
||||
}
|
||||
state => panic!("send_close: unexpected state {:?}", state),
|
||||
}
|
||||
}
|
||||
@@ -343,8 +344,7 @@ impl State {
|
||||
pub fn is_send_streaming(&self) -> bool {
|
||||
match self.inner {
|
||||
Open {
|
||||
local: Streaming,
|
||||
..
|
||||
local: Streaming, ..
|
||||
} => true,
|
||||
HalfClosedRemote(Streaming) => true,
|
||||
_ => false,
|
||||
@@ -368,8 +368,7 @@ impl State {
|
||||
pub fn is_recv_streaming(&self) -> bool {
|
||||
match self.inner {
|
||||
Open {
|
||||
remote: Streaming,
|
||||
..
|
||||
remote: Streaming, ..
|
||||
} => true,
|
||||
HalfClosedLocal(Streaming) => true,
|
||||
_ => false,
|
||||
@@ -407,12 +406,11 @@ impl State {
|
||||
pub fn ensure_recv_open(&self) -> Result<bool, proto::Error> {
|
||||
// TODO: Is this correct?
|
||||
match self.inner {
|
||||
Closed(Cause::Proto(reason)) |
|
||||
Closed(Cause::LocallyReset(reason)) |
|
||||
Closed(Cause::Scheduled(reason)) => Err(proto::Error::Proto(reason)),
|
||||
Closed(Cause::Proto(reason))
|
||||
| Closed(Cause::LocallyReset(reason))
|
||||
| Closed(Cause::Scheduled(reason)) => Err(proto::Error::Proto(reason)),
|
||||
Closed(Cause::Io) => Err(proto::Error::Io(io::ErrorKind::BrokenPipe.into())),
|
||||
Closed(Cause::EndStream) |
|
||||
HalfClosedRemote(..) => Ok(false),
|
||||
Closed(Cause::EndStream) | HalfClosedRemote(..) => Ok(false),
|
||||
_ => Ok(true),
|
||||
}
|
||||
}
|
||||
@@ -420,15 +418,15 @@ impl State {
|
||||
/// Returns a reason if the stream has been reset.
|
||||
pub(super) fn ensure_reason(&self, mode: PollReset) -> Result<Option<Reason>, crate::Error> {
|
||||
match self.inner {
|
||||
Closed(Cause::Proto(reason)) |
|
||||
Closed(Cause::LocallyReset(reason)) |
|
||||
Closed(Cause::Scheduled(reason)) => Ok(Some(reason)),
|
||||
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())
|
||||
},
|
||||
Open {
|
||||
local: Streaming, ..
|
||||
}
|
||||
| HalfClosedRemote(Streaming) => match mode {
|
||||
PollReset::AwaitingHeaders => Err(UserError::PollResetAfterSendResponse.into()),
|
||||
PollReset::Streaming => Ok(None),
|
||||
},
|
||||
_ => Ok(None),
|
||||
@@ -438,9 +436,7 @@ impl State {
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> State {
|
||||
State {
|
||||
inner: Inner::Idle,
|
||||
}
|
||||
State { inner: Inner::Idle }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user