Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Tokio and Bytes 1.0 #504

Merged
merged 1 commit into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ members = [
futures-core = { version = "0.3", default-features = false }
futures-sink = { version = "0.3", default-features = false }
futures-util = { version = "0.3", default-features = false }
tokio-util = { version = "0.5", features = ["codec"] }
tokio = { version = "0.3.4", features = ["io-util"] }
bytes = "0.6"
tokio-util = { version = "0.6", features = ["codec"] }
tokio = { version = "1", features = ["io-util"] }
bytes = "1"
http = "0.2"
tracing = { version = "0.1.13", default-features = false, features = ["std"] }
tracing-futures = { version = "0.2", default-features = false, features = ["std-future"]}
Expand All @@ -68,9 +68,9 @@ serde = "1.0.0"
serde_json = "1.0.0"

# Examples
tokio = { version = "0.3.4", features = ["rt-multi-thread", "macros", "sync", "net"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "net"] }
env_logger = { version = "0.5.3", default-features = false }
rustls = "0.18"
tokio-rustls = "0.20.0"
webpki = "0.21"
webpki-roots = "0.17"
#rustls = "0.18"
#tokio-rustls = "0.20.0"
#webpki = "0.21"
#webpki-roots = "0.17"
5 changes: 5 additions & 0 deletions examples/akamai.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
fn main() {
eprintln!("TODO: Re-enable when tokio-rustls is upgraded.");
}
/*
use h2::client;
use http::{Method, Request};
use tokio::net::TcpStream;
Expand Down Expand Up @@ -73,3 +77,4 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
}
Ok(())
}
*/
8 changes: 4 additions & 4 deletions src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,23 @@ where
// could just use `poll_write_buf`...
let n = if self.is_write_vectored {
let mut bufs = [IoSlice::new(&[]); MAX_IOVS];
let cnt = buf.bytes_vectored(&mut bufs);
let cnt = buf.chunks_vectored(&mut bufs);
ready!(Pin::new(&mut self.inner).poll_write_vectored(cx, &bufs[..cnt]))?
} else {
ready!(Pin::new(&mut self.inner).poll_write(cx, buf.bytes()))?
ready!(Pin::new(&mut self.inner).poll_write(cx, buf.chunk()))?
};
buf.advance(n);
}
_ => {
tracing::trace!(queued_data_frame = false);
let n = if self.is_write_vectored {
let mut iovs = [IoSlice::new(&[]); MAX_IOVS];
let cnt = self.buf.bytes_vectored(&mut iovs);
let cnt = self.buf.chunks_vectored(&mut iovs);
ready!(
Pin::new(&mut self.inner).poll_write_vectored(cx, &mut iovs[..cnt])
)?
} else {
ready!(Pin::new(&mut self.inner).poll_write(cx, &mut self.buf.bytes()))?
ready!(Pin::new(&mut self.inner).poll_write(cx, &mut self.buf.chunk()))?
};
self.buf.advance(n);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hpack/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Decoder {

if huff {
let ret = {
let raw = &buf.bytes()[..len];
let raw = &buf.chunk()[..len];
huffman::decode(raw, &mut self.buffer).map(BytesMut::freeze)
};

Expand Down Expand Up @@ -419,7 +419,7 @@ fn decode_int<B: Buf>(buf: &mut B, prefix_size: u8) -> Result<usize, DecoderErro

fn peek_u8<B: Buf>(buf: &mut B) -> Option<u8> {
if buf.has_remaining() {
Some(buf.bytes()[0])
Some(buf.chunk()[0])
} else {
None
}
Expand Down
8 changes: 6 additions & 2 deletions src/proto/streams/prioritize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,12 @@ where
self.inner.remaining()
}

fn bytes(&self) -> &[u8] {
self.inner.bytes()
fn chunk(&self) -> &[u8] {
self.inner.chunk()
}

fn chunks_vectored<'a>(&'a self, dst: &mut [std::io::IoSlice<'a>]) -> usize {
self.inner.chunks_vectored(dst)
}

fn advance(&mut self, cnt: usize) {
Expand Down
4 changes: 2 additions & 2 deletions tests/h2-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ h2 = { path = "../.." }
env_logger = { version = "0.5.3", default-features = false }
futures = { version = "0.3", default-features = false, features = ["std"] }
honggfuzz = "0.5"
http = { git = "https://github.com/paolobarbolini/http.git", branch = "bytes06" }
tokio = { version = "0.3.2", features = [] }
http = "0.2"
tokio = "1"
6 changes: 3 additions & 3 deletions tests/h2-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2018"
[dependencies]
h2 = { path = "../..", features = ["stream", "unstable"] }

bytes = "0.6"
bytes = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "chrono", "ansi"] }
futures = { version = "0.3", default-features = false }
http = "0.2"
tokio = { version = "0.3.2", features = ["time"] }
tokio-test = "0.3"
tokio = { version = "1", features = ["time"] }
tokio-test = "0.4"
2 changes: 1 addition & 1 deletion tests/h2-support/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Handle {
poll_fn(move |cx| {
while buf.has_remaining() {
let res = Pin::new(self.codec.get_mut())
.poll_write(cx, &mut buf.bytes())
.poll_write(cx, &mut buf.chunk())
.map_err(|e| panic!("write err={:?}", e));

let n = ready!(res).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/h2-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ edition = "2018"
h2-support = { path = "../h2-support" }
tracing = "0.1.13"
futures = { version = "0.3", default-features = false, features = ["alloc"] }
tokio = { version = "0.3.2", features = ["macros", "net", "rt", "io-util"] }
tokio = { version = "1", features = ["macros", "net", "rt", "io-util"] }
15 changes: 6 additions & 9 deletions tests/h2-tests/tests/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ async fn recv_no_init_window_then_receive_some_init_window() {
#[tokio::test]
async fn settings_lowered_capacity_returns_capacity_to_connection() {
use futures::channel::oneshot;
use futures::future::{select, Either};

h2_support::trace_init!();
let (io, mut srv) = mock::new();
Expand Down Expand Up @@ -972,10 +971,9 @@ async fn settings_lowered_capacity_returns_capacity_to_connection() {
//
// A timeout is used here to avoid blocking forever if there is a
// failure
let result = select(rx2, tokio::time::sleep(Duration::from_secs(5))).await;
if let Either::Right((_, _)) = result {
panic!("Timed out");
}
let _ = tokio::time::timeout(Duration::from_secs(5), rx2)
.await
.unwrap();

idle_ms(500).await;

Expand Down Expand Up @@ -1004,10 +1002,9 @@ async fn settings_lowered_capacity_returns_capacity_to_connection() {
});

// Wait for server handshake to complete.
let result = select(rx1, tokio::time::sleep(Duration::from_secs(5))).await;
if let Either::Right((_, _)) = result {
panic!("Timed out");
}
let _ = tokio::time::timeout(Duration::from_secs(5), rx1)
.await
.unwrap();

let request = Request::post("https://example.com/one").body(()).unwrap();

Expand Down