Skip to content

Commit ad7ffa7

Browse files
95thseanmonstar
authored andcommitted
Updated as per review comments
1 parent 0a4bd39 commit ad7ffa7

File tree

10 files changed

+42
-124
lines changed

10 files changed

+42
-124
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ members = [
4141
]
4242

4343
[dependencies]
44-
futures-preview = "0.3.0-alpha.18"
45-
tokio-io = { git = "https://github.com/tokio-rs/tokio" }
46-
tokio-codec = { git = "https://github.com/tokio-rs/tokio" }
44+
futures-preview = "0.3.0-alpha.17"
45+
tokio-io = "0.2.0-alpha.1"
46+
tokio-codec = "0.2.0-alpha.1"
4747
bytes = "0.4.7"
4848
http = "0.1.8"
4949
log = "0.4.1"
@@ -65,7 +65,7 @@ serde = "1.0.0"
6565
serde_json = "1.0.0"
6666

6767
# Akamai example
68-
tokio = { git = "https://github.com/tokio-rs/tokio" }
68+
tokio = "0.2.0-alpha.1"
6969
env_logger = { version = "0.5.3", default-features = false }
7070
rustls = "0.12"
7171
tokio-rustls = "0.5.0"

examples/client.rs

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
11
#![feature(async_await)]
22

3-
use futures::{ready, Stream};
3+
use futures::future::poll_fn;
4+
use futures::StreamExt;
45
use h2::client;
5-
use h2::RecvStream;
66
use http::{HeaderMap, Request};
7-
use std::future::Future;
8-
use std::pin::Pin;
9-
use std::task::{Context, Poll};
107

118
use std::error::Error;
129

1310
use tokio::net::TcpStream;
1411

15-
struct Process {
16-
body: RecvStream,
17-
trailers: bool,
18-
}
19-
20-
impl Future for Process {
21-
type Output = Result<(), h2::Error>;
22-
23-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
24-
loop {
25-
if self.trailers {
26-
let trailers = ready!(self.body.poll_trailers(cx));
27-
28-
println!("GOT TRAILERS: {:?}", trailers);
29-
30-
return Poll::Ready(Ok(()));
31-
} else {
32-
match ready!(Pin::new(&mut self.body).poll_next(cx)) {
33-
Some(Ok(chunk)) => {
34-
println!("GOT CHUNK = {:?}", chunk);
35-
}
36-
Some(Err(e)) => return Poll::Ready(Err(e)),
37-
None => {
38-
self.trailers = true;
39-
}
40-
}
41-
}
42-
}
43-
}
44-
}
45-
4612
#[tokio::main]
4713
pub async fn main() -> Result<(), Box<dyn Error>> {
4814
let _ = env_logger::try_init();
@@ -76,12 +42,15 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
7642
println!("GOT RESPONSE: {:?}", response);
7743

7844
// Get the body
79-
let (_, body) = response.into_parts();
45+
let (_, mut body) = response.into_parts();
46+
47+
while let Some(chunk) = body.next().await {
48+
println!("GOT CHUNK = {:?}", chunk?);
49+
}
8050

81-
Process {
82-
body,
83-
trailers: false,
51+
if let Some(trailers) = poll_fn(|cx| body.poll_trailers(cx)).await {
52+
println!("GOT TRAILERS: {:?}", trailers?);
8453
}
85-
.await?;
54+
8655
Ok(())
8756
}

src/codec/framed_write.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ impl<T: AsyncRead + Unpin, B: Unpin> AsyncRead for FramedWrite<T, B> {
280280
) -> Poll<io::Result<usize>> {
281281
Pin::new(&mut self.inner).poll_read(cx, buf)
282282
}
283+
284+
fn poll_read_buf<Buf: BufMut>(
285+
mut self: Pin<&mut Self>,
286+
cx: &mut Context<'_>,
287+
buf: &mut Buf,
288+
) -> Poll<io::Result<usize>> {
289+
Pin::new(&mut self.inner).poll_read_buf(cx, buf)
290+
}
283291
}
284292

285293
#[cfg(feature = "unstable")]

src/proto/connection.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ where
289289
// The order here matters:
290290
// - poll_go_away may buffer a graceful shutdown GOAWAY frame
291291
// - If it has, we've also added a PING to be sent in poll_ready
292-
match ready!(self.poll_go_away(cx)) {
293-
Some(Ok(reason)) => {
292+
match ready!(self.poll_go_away(cx)?) {
293+
Some(reason) => {
294294
if self.go_away.should_close_now() {
295295
if self.go_away.is_user_initiated() {
296296
// A user initiated abrupt shutdown shouldn't return
@@ -307,33 +307,32 @@ where
307307
"graceful GOAWAY should be NO_ERROR"
308308
);
309309
}
310-
Some(Err(e)) => return Poll::Ready(Err(e.into())),
311310
None => (),
312311
}
313312
ready!(self.poll_ready(cx))?;
314313

315-
match ready!(Pin::new(&mut self.codec).poll_next(cx)) {
316-
Some(Ok(Headers(frame))) => {
314+
match ready!(Pin::new(&mut self.codec).poll_next(cx)?) {
315+
Some(Headers(frame)) => {
317316
log::trace!("recv HEADERS; frame={:?}", frame);
318317
self.streams.recv_headers(frame)?;
319318
}
320-
Some(Ok(Data(frame))) => {
319+
Some(Data(frame)) => {
321320
log::trace!("recv DATA; frame={:?}", frame);
322321
self.streams.recv_data(frame)?;
323322
}
324-
Some(Ok(Reset(frame))) => {
323+
Some(Reset(frame)) => {
325324
log::trace!("recv RST_STREAM; frame={:?}", frame);
326325
self.streams.recv_reset(frame)?;
327326
}
328-
Some(Ok(PushPromise(frame))) => {
327+
Some(PushPromise(frame)) => {
329328
log::trace!("recv PUSH_PROMISE; frame={:?}", frame);
330329
self.streams.recv_push_promise(frame)?;
331330
}
332-
Some(Ok(Settings(frame))) => {
331+
Some(Settings(frame)) => {
333332
log::trace!("recv SETTINGS; frame={:?}", frame);
334333
self.settings.recv_settings(frame);
335334
}
336-
Some(Ok(GoAway(frame))) => {
335+
Some(GoAway(frame)) => {
337336
log::trace!("recv GOAWAY; frame={:?}", frame);
338337
// This should prevent starting new streams,
339338
// but should allow continuing to process current streams
@@ -342,7 +341,7 @@ where
342341
self.streams.recv_go_away(&frame)?;
343342
self.error = Some(frame.reason());
344343
}
345-
Some(Ok(Ping(frame))) => {
344+
Some(Ping(frame)) => {
346345
log::trace!("recv PING; frame={:?}", frame);
347346
let status = self.ping_pong.recv_ping(frame);
348347
if status.is_shutdown() {
@@ -355,15 +354,14 @@ where
355354
self.go_away(last_processed_id, Reason::NO_ERROR);
356355
}
357356
}
358-
Some(Ok(WindowUpdate(frame))) => {
357+
Some(WindowUpdate(frame)) => {
359358
log::trace!("recv WINDOW_UPDATE; frame={:?}", frame);
360359
self.streams.recv_window_update(frame)?;
361360
}
362-
Some(Ok(Priority(frame))) => {
361+
Some(Priority(frame)) => {
363362
log::trace!("recv PRIORITY; frame={:?}", frame);
364363
// TODO: handle
365364
}
366-
Some(Err(e)) => return Poll::Ready(Err(e)),
367365
None => {
368366
log::trace!("codec closed");
369367
self.streams.recv_eof(false).ok().expect("mutex poisoned");

tests/h2-fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2018"
99
h2 = { path = "../.." }
1010

1111
env_logger = { version = "0.5.3", default-features = false }
12-
futures-preview = "0.3.0-alpha.18"
12+
futures-preview = "0.3.0-alpha.17"
1313
honggfuzz = "0.5"
1414
http = "0.1.3"
15-
tokio = { git = "https://github.com/tokio-rs/tokio" }
15+
tokio = "0.2.0-alpha.1"

tests/h2-support/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ h2 = { path = "../..", features = ["unstable"] }
99

1010
bytes = "0.4.7"
1111
env_logger = "0.5.9"
12-
futures-preview = "0.3.0-alpha.18"
12+
futures-preview = "0.3.0-alpha.17"
1313
http = "0.1.5"
1414
string = "0.2"
15-
tokio = { git = "https://github.com/tokio-rs/tokio" }
15+
tokio = "0.2.0-alpha.1"

tests/h2-support/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ pub mod assert;
77
pub mod raw;
88

99
pub mod frames;
10-
pub mod prelude;
1110
pub mod mock;
1211
pub mod mock_io;
13-
pub mod notify;
12+
pub mod prelude;
1413
pub mod util;
1514

1615
mod client_ext;
1716
mod future_ext;
1817

19-
pub use crate::client_ext::{SendRequestExt};
18+
pub use crate::client_ext::SendRequestExt;
2019
pub use crate::future_ext::TestFuture;
2120

2221
pub type WindowSize = usize;

tests/h2-support/src/notify.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/h2-support/src/prelude.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ pub use super::mock::{self, idle_ms};
1212
// Re-export frames helpers
1313
pub use super::frames;
1414

15-
// Re-export mock notify
16-
pub use super::notify::MockNotify;
17-
1815
// Re-export utility mod
1916
pub use super::util;
2017

tests/h2-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ edition = "2018"
1010
[dev-dependencies]
1111
h2-support = { path = "../h2-support" }
1212
log = "0.4.1"
13-
futures-preview = "0.3.0-alpha.18"
14-
tokio = { git = "https://github.com/tokio-rs/tokio" }
13+
futures-preview = "0.3.0-alpha.17"
14+
tokio = "0.2.0-alpha.1"

0 commit comments

Comments
 (0)