diff --git a/Cargo.toml b/Cargo.toml index 9a4de87d..da5fac3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,35 +20,28 @@ include = [ ] [dependencies] -bytes = "0.4.6" -futures-core = "0.3.1" -futures-channel = "0.3.1" -futures-util = "0.3.1" -http = "0.1.15" -http-body = "=0.2.0-alpha.3" +bytes = "0.5" +futures-core = { version = "0.3", default-features = false } +futures-channel = "0.3" +futures-util = { version = "0.3", default-features = false } +http = "0.2" +http-body = "0.2" httparse = "1.0" -h2 = "=0.2.0-alpha.3" -iovec = "0.1" +h2 = "0.2" itoa = "0.4.1" log = "0.4" pin-project = "0.4" time = "0.1" tower-service = "=0.3.0-alpha.2" -tokio-executor = "=0.2.0-alpha.6" -tokio-io = "=0.2.0-alpha.6" -tokio-sync = "=0.2.0-alpha.6" +tokio = { version = "0.2", features = ["sync"] } want = "0.3" # Optional net2 = { version = "0.2.32", optional = true } -tokio = { version = "=0.2.0-alpha.6", optional = true, default-features = false, features = ["rt-full"] } -tokio-net = { version = "=0.2.0-alpha.6", optional = true, features = ["tcp"] } -tokio-timer = { version = "=0.3.0-alpha.6", optional = true } - [dev-dependencies] -futures-util-a19 = { version = "=0.3.0-alpha.19", package = "futures-util-preview" } +futures-util = { version = "0.3", default-features = false, features = ["alloc"] } matches = "0.1" num_cpus = "1.0" pretty_env_logger = "0.3" @@ -56,9 +49,8 @@ spmc = "0.3" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -tokio = "=0.2.0-alpha.6" # using #[tokio::test] attributes -tokio-fs = "=0.2.0-alpha.6" -tokio-test = "=0.2.0-alpha.6" +tokio = { version = "0.2.2", features = ["fs", "macros", "rt-util", "sync", "time", "test-util"] } +tokio-test = "0.2" url = "1.0" [features] @@ -68,13 +60,13 @@ default = [ ] runtime = [ "tcp", - "tokio", + "tokio/time", ] tcp = [ "net2", - "tokio-executor/blocking", - "tokio-net", - "tokio-timer", + "tokio/blocking", + "tokio/tcp", + "tokio/time", ] # unstable features @@ -206,3 +198,4 @@ required-features = ["runtime", "unstable-stream"] name = "server" path = "tests/server.rs" required-features = ["runtime"] + diff --git a/benches/connect.rs b/benches/connect.rs index 323ca0b8..e249af9e 100644 --- a/benches/connect.rs +++ b/benches/connect.rs @@ -3,8 +3,8 @@ extern crate test; +use std::net::SocketAddr; use tokio::net::TcpListener; -use tokio::runtime::current_thread::Runtime; use hyper::client::connect::{Destination, HttpConnector}; use hyper::service::Service; use http::Uri; @@ -12,8 +12,12 @@ use http::Uri; #[bench] fn http_connector(b: &mut test::Bencher) { let _ = pretty_env_logger::try_init(); - let mut rt = Runtime::new().unwrap(); - let mut listener = rt.block_on(TcpListener::bind("127.0.0.1:0")).expect("bind"); + let mut rt = tokio::runtime::Builder::new() + .enable_all() + .basic_scheduler() + .build() + .expect("rt build"); + let mut listener = rt.block_on(TcpListener::bind(&SocketAddr::from(([127, 0, 0, 1], 0)))).expect("bind"); let addr = listener.local_addr().expect("local_addr"); let uri: Uri = format!("http://{}/", addr).parse().expect("uri parse"); let dst = Destination::try_from_uri(uri).expect("destination"); diff --git a/benches/end_to_end.rs b/benches/end_to_end.rs index 05f508c5..0f217b16 100644 --- a/benches/end_to_end.rs +++ b/benches/end_to_end.rs @@ -6,9 +6,8 @@ extern crate test; use std::net::SocketAddr; use futures_util::future::join_all; -use tokio::runtime::current_thread::Runtime; -use hyper::{Body, Method, Request, Response, Server}; +use hyper::{body::HttpBody as _, Body, Method, Request, Response, Server}; use hyper::client::HttpConnector; // HTTP1 @@ -264,8 +263,12 @@ impl Opts { fn bench(self, b: &mut test::Bencher) { let _ = pretty_env_logger::try_init(); // Create a runtime of current thread. - let mut rt = Runtime::new().unwrap(); - let exec = rt.handle(); + let mut rt = tokio::runtime::Builder::new() + .enable_all() + .basic_scheduler() + .build() + .expect("rt build"); + let exec = rt.handle().clone(); let req_len = self.request_body.map(|b| b.len()).unwrap_or(0) as u64; let req_len = if self.request_chunks > 0 { @@ -297,7 +300,7 @@ impl Opts { for _ in 0..chunk_cnt { tx.send_data(chunk.into()).await.expect("send_data"); } - }).expect("body tx spawn"); + }); body } else { self @@ -340,22 +343,24 @@ impl Opts { } } -fn spawn_server(rt: &mut Runtime, opts: &Opts) -> SocketAddr { +fn spawn_server(rt: &mut tokio::runtime::Runtime, opts: &Opts) -> SocketAddr { use hyper::service::{make_service_fn, service_fn}; let addr = "127.0.0.1:0".parse().unwrap(); let body = opts.response_body; - let srv = Server::bind(&addr) - .http2_only(opts.http2) - .http2_initial_stream_window_size(opts.http2_stream_window) - .http2_initial_connection_window_size(opts.http2_conn_window) - .serve(make_service_fn( move |_| async move { - Ok::<_, hyper::Error>(service_fn(move |req: Request
| async move { - let mut req_body = req.into_body(); - while let Some(_chunk) = req_body.next().await {} - Ok::<_, hyper::Error>(Response::new(Body::from(body))) + let srv = rt.block_on(async move { + Server::bind(&addr) + .http2_only(opts.http2) + .http2_initial_stream_window_size(opts.http2_stream_window) + .http2_initial_connection_window_size(opts.http2_conn_window) + .serve(make_service_fn( move |_| async move { + Ok::<_, hyper::Error>(service_fn(move |req: Request| async move { + let mut req_body = req.into_body(); + while let Some(_chunk) = req_body.next().await {} + Ok::<_, hyper::Error>(Response::new(Body::from(body))) + })) })) - })); + }); let addr = srv.local_addr(); rt.spawn(async { if let Err(err) = srv.await { diff --git a/benches/pipeline.rs b/benches/pipeline.rs index af9a4f51..562c3735 100644 --- a/benches/pipeline.rs +++ b/benches/pipeline.rs @@ -8,7 +8,6 @@ use std::net::{TcpStream}; use std::sync::mpsc; use std::time::Duration; -use tokio::runtime::current_thread; use tokio::sync::oneshot; use hyper::{Body, Response, Server}; @@ -31,9 +30,17 @@ fn hello_world(b: &mut test::Bencher) { Ok::<_, hyper::Error>(Response::new(Body::from("Hello, World!"))) })) }); - let srv = Server::bind(&addr) - .http1_pipeline_flush(true) - .serve(make_svc); + + let mut rt = tokio::runtime::Builder::new() + .enable_all() + .basic_scheduler() + .build() + .expect("rt build"); + let srv = rt.block_on(async move { + Server::bind(&addr) + .http1_pipeline_flush(true) + .serve(make_svc) + }); addr_tx.send(srv.local_addr()).unwrap(); @@ -42,13 +49,11 @@ fn hello_world(b: &mut test::Bencher) { until_rx.await.ok(); }); - let mut rt = current_thread::Runtime::new().unwrap(); - rt.spawn(async { + rt.block_on(async { if let Err(e) = graceful.await { panic!("server error: {}", e); } }); - rt.run().unwrap(); }); addr_rx.recv().unwrap() diff --git a/benches/server.rs b/benches/server.rs index 4901eabb..28f8f21e 100644 --- a/benches/server.rs +++ b/benches/server.rs @@ -9,7 +9,6 @@ use std::sync::mpsc; use std::time::Duration; use futures_util::{stream, StreamExt}; -use tokio::runtime::current_thread; use tokio::sync::oneshot; use hyper::{Body, Response, Server}; @@ -33,8 +32,17 @@ macro_rules! bench_server { ) })) }); - let srv = Server::bind(&addr) - .serve(make_svc); + + let mut rt = tokio::runtime::Builder::new() + .enable_all() + .basic_scheduler() + .build() + .expect("rt build"); + + let srv = rt.block_on(async move { + Server::bind(&addr) + .serve(make_svc) + }); addr_tx.send(srv.local_addr()).unwrap(); @@ -42,13 +50,11 @@ macro_rules! bench_server { .with_graceful_shutdown(async { until_rx.await.ok(); }); - let mut rt = current_thread::Runtime::new().unwrap(); - rt.spawn(async { + rt.block_on(async move { if let Err(e) = graceful.await { panic!("server error: {}", e); } }); - rt.run().unwrap(); }); addr_rx.recv().unwrap() diff --git a/examples/client.rs b/examples/client.rs index 00ae1c26..2057bc74 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -4,6 +4,7 @@ use std::env; use std::io::{self, Write}; use hyper::Client; +use futures_util::StreamExt; // A simple type alias so as to DRY. type Result