From d5d47b08ca3a48d5de95571e09b2058af754304f Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Sat, 22 Jul 2017 18:30:32 +0000 Subject: [PATCH] testing, debugging, making things private --- src/frame/mod.rs | 9 --------- src/lib.rs | 6 +++--- src/proto/framed_read.rs | 6 +++++- src/proto/stream_recv_open.rs | 20 +++++--------------- src/proto/stream_send_open.rs | 1 + tests/client_request.rs | 9 ++++++--- 6 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 8abd97f..2547741 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -112,15 +112,6 @@ impl Frame { &Reset(_) => true, } } - - pub fn is_reset(&self) -> bool { - use self::Frame::*; - - match self { - &Reset(_) => true, - _ => false, - } - } } /// Errors that can occur during parsing an HTTP/2 frame. diff --git a/src/lib.rs b/src/lib.rs index 67b7c83..af9786b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,9 +27,9 @@ extern crate log; pub mod client; pub mod error; -pub mod hpack; -pub mod proto; -pub mod frame; +mod hpack; +mod proto; +mod frame; pub mod server; mod util; diff --git a/src/proto/framed_read.rs b/src/proto/framed_read.rs index 71b8d69..cb97c91 100644 --- a/src/proto/framed_read.rs +++ b/src/proto/framed_read.rs @@ -39,6 +39,8 @@ impl FramedRead { } fn decode_frame(&mut self, mut bytes: Bytes) -> Result, ConnectionError> { + trace!("decoding frame from {}B", bytes.len()); + // Parse the head let head = frame::Head::parse(&bytes); @@ -47,7 +49,7 @@ impl FramedRead { } let kind = head.kind(); - debug!("received {:?}", kind); + debug!("decoded; kind={:?}", kind); let frame = match kind { Kind::Settings => { @@ -121,11 +123,13 @@ impl Stream for FramedRead fn poll(&mut self) -> Poll, ConnectionError> { loop { + trace!("poll"); let bytes = match try_ready!(self.inner.poll()) { Some(bytes) => bytes.freeze(), None => return Ok(Async::Ready(None)), }; + trace!("poll; bytes={}B", bytes.len()); if let Some(frame) = try!(self.decode_frame(bytes)) { debug!("poll; frame={:?}", frame); return Ok(Async::Ready(Some(frame))); diff --git a/src/proto/stream_recv_open.rs b/src/proto/stream_recv_open.rs index 69c9972..fed4020 100644 --- a/src/proto/stream_recv_open.rs +++ b/src/proto/stream_recv_open.rs @@ -110,29 +110,19 @@ impl Stream for StreamRecvOpen trace!("poll"); loop { - let frame = match self.inner.poll()? { - Async::NotReady => { - panic!("poll: NotReady"); - } - Async::Ready(None) => { - panic!("poll: None"); - } - Async::Ready(Some(f)) => { - trace!("poll: id={:?} eos={}", f.stream_id(), f.is_end_stream()); - f - } + let frame = match try_ready!(self.inner.poll()) { + None => return Ok(Async::Ready(None)), + Some(f) => f, }; - // let frame = match try_ready!(self.inner.poll()) { - // None => return Ok(Async::Ready(None)), - // Some(f) => f, - // }; let id = frame.stream_id(); trace!("poll: id={:?}", id); + if id.is_zero() { if !frame.is_connection_frame() { return Err(ProtocolError.into()) } + // Nothing to do on connection frames. return Ok(Async::Ready(Some(frame))); } diff --git a/src/proto/stream_send_open.rs b/src/proto/stream_send_open.rs index 6b754ab..f59e017 100644 --- a/src/proto/stream_send_open.rs +++ b/src/proto/stream_send_open.rs @@ -87,6 +87,7 @@ impl Sink for StreamSendOpen if !frame.is_connection_frame() { return Err(InvalidStreamId.into()) } + // Nothing to do on connection frames. return self.inner.start_send(frame); } diff --git a/tests/client_request.rs b/tests/client_request.rs index 4407266..b52efaf 100644 --- a/tests/client_request.rs +++ b/tests/client_request.rs @@ -1,9 +1,11 @@ +extern crate bytes; extern crate h2; extern crate http; -extern crate futures; -extern crate mock_io; extern crate env_logger; -extern crate bytes; +extern crate futures; +#[macro_use] +extern crate log; +extern crate mock_io; // scoped so `cargo test client_request` dtrt. mod client_request { @@ -48,6 +50,7 @@ mod client_request { let h2 = client::handshake(mock) .wait().unwrap(); + trace!("hands have been shook"); // At this point, the connection should be closed assert!(Stream::wait(h2).next().is_none());