Update Tokio to Rust 2018 (#1082)

This commit is contained in:
Carl Lerche
2019-05-14 10:27:36 -07:00
committed by GitHub
parent 79d8820050
commit cb4aea394e
343 changed files with 1725 additions and 2813 deletions
+1 -19
View File
@@ -25,25 +25,7 @@ name = "hyper"
path = "src/hyper.rs"
[dependencies]
tokio = { version = "0.1.18", features = ["async-await-preview"] }
tokio = { version = "0.2.0", features = ["async-await-preview"], path = "../tokio" }
futures = "0.1.23"
bytes = "0.4.9"
hyper = "0.12.8"
# Avoid using crates.io for Tokio dependencies
[patch.crates-io]
tokio = { path = "../tokio" }
tokio-codec = { path = "../tokio-codec" }
tokio-current-thread = { path = "../tokio-current-thread" }
tokio-executor = { path = "../tokio-executor" }
tokio-fs = { path = "../tokio-fs" }
tokio-futures = { path = "../tokio-futures" }
tokio-io = { path = "../tokio-io" }
tokio-reactor = { path = "../tokio-reactor" }
tokio-signal = { path = "../tokio-signal" }
tokio-tcp = { path = "../tokio-tcp" }
tokio-threadpool = { path = "../tokio-threadpool" }
tokio-timer = { path = "../tokio-timer" }
tokio-tls = { path = "../tokio-tls" }
tokio-udp = { path = "../tokio-udp" }
tokio-uds = { path = "../tokio-uds" }
+7 -7
View File
@@ -1,6 +1,6 @@
#![feature(await_macro, async_await)]
use tokio::await;
use tokio::async_wait;
use tokio::codec::{LinesCodec, Decoder};
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
@@ -33,7 +33,7 @@ async fn process(stream: TcpStream, state: Arc<Mutex<Shared>>) -> io::Result<()>
let mut lines = LinesCodec::new().framed(stream);
// Extract the peer's name
let name = match await!(lines.next()) {
let name = match async_wait!(lines.next()) {
Some(name) => name?,
None => {
// Disconnected early
@@ -56,15 +56,15 @@ async fn process(stream: TcpStream, state: Arc<Mutex<Shared>>) -> io::Result<()>
// Spawn a task that receives all lines broadcasted to us from other peers
// and writes it to the client.
tokio::spawn_async(async move {
while let Some(line) = await!(rx.next()) {
while let Some(line) = async_wait!(rx.next()) {
let line = line.unwrap();
await!(lines_tx.send_async(line)).unwrap();
async_wait!(lines_tx.send_async(line)).unwrap();
}
});
// Use the current task to read lines from the socket and broadcast them to
// other peers.
while let Some(message) = await!(lines_rx.next()) {
while let Some(message) = async_wait!(lines_rx.next()) {
// TODO: Error handling
let message = message.unwrap();
@@ -113,7 +113,7 @@ async fn main() {
// Start the Tokio runtime.
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
while let Some(stream) = async_wait!(incoming.next()) {
let stream = match stream {
Ok(stream) => stream,
Err(_) => continue,
@@ -122,7 +122,7 @@ async fn main() {
let state = state.clone();
tokio::spawn_async(async move {
if let Err(_) = await!(process(stream, state)) {
if let Err(_) = async_wait!(process(stream, state)) {
eprintln!("failed to process connection");
}
});
+5 -5
View File
@@ -1,6 +1,6 @@
#![feature(await_macro, async_await)]
use tokio::await;
use tokio::async_wait;
use tokio::net::TcpStream;
use tokio::prelude::*;
@@ -14,7 +14,7 @@ const MESSAGES: &[&str] = &[
];
async fn run_client(addr: &SocketAddr) -> io::Result<()> {
let mut stream = await!(TcpStream::connect(addr))?;
let mut stream = async_wait!(TcpStream::connect(addr))?;
// Buffer to read into
let mut buf = [0; 128];
@@ -23,10 +23,10 @@ async fn run_client(addr: &SocketAddr) -> io::Result<()> {
println!(" > write = {:?}", msg);
// Write the message to the server
await!(stream.write_all_async(msg.as_bytes()))?;
async_wait!(stream.write_all_async(msg.as_bytes()))?;
// Read the message back from the server
await!(stream.read_exact_async(&mut buf[..msg.len()]))?;
async_wait!(stream.read_exact_async(&mut buf[..msg.len()]))?;
assert_eq!(&buf[..msg.len()], msg.as_bytes());
}
@@ -43,7 +43,7 @@ async fn main() {
// Connect to the echo serveer
match await!(run_client(&addr)) {
match async_wait!(run_client(&addr)) {
Ok(_) => println!("done."),
Err(e) => eprintln!("echo client failed; error = {:?}", e),
}
+4 -4
View File
@@ -1,6 +1,6 @@
#![feature(await_macro, async_await)]
use tokio::await;
use tokio::async_wait;
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
@@ -11,11 +11,11 @@ fn handle(mut stream: TcpStream) {
let mut buf = [0; 1024];
loop {
match await!(stream.read_async(&mut buf)).unwrap() {
match async_wait!(stream.read_async(&mut buf)).unwrap() {
0 => break, // Socket closed
n => {
// Send the data back
await!(stream.write_all_async(&buf[0..n])).unwrap();
async_wait!(stream.write_all_async(&buf[0..n])).unwrap();
}
}
}
@@ -35,7 +35,7 @@ async fn main() {
let mut incoming = listener.incoming();
while let Some(stream) = await!(incoming.next()) {
while let Some(stream) = async_wait!(incoming.next()) {
let stream = stream.unwrap();
handle(stream);
}
+3 -3
View File
@@ -1,6 +1,6 @@
#![feature(await_macro, async_await)]
use tokio::await;
use tokio::async_wait;
use tokio::prelude::*;
use hyper::Client;
@@ -13,7 +13,7 @@ async fn main() {
let uri = "http://httpbin.org/ip".parse().unwrap();
let response = await!({
let response = async_wait!({
client.get(uri)
.timeout(Duration::from_secs(10))
}).unwrap();
@@ -22,7 +22,7 @@ async fn main() {
let mut body = response.into_body();
while let Some(chunk) = await!(body.next()) {
while let Some(chunk) = async_wait!(body.next()) {
let chunk = chunk.unwrap();
println!("chunk = {}", str::from_utf8(&chunk[..]).unwrap());
}
+2 -2
View File
@@ -1,6 +1,6 @@
#![feature(await_macro, async_await)]
use tokio::await;
use tokio::async_wait;
use tokio::timer::Delay;
use std::time::{Duration, Instant};
@@ -18,5 +18,5 @@ async fn fail_no_async() {
#[tokio::test]
async fn use_timer() {
let when = Instant::now() + Duration::from_millis(10);
await!(Delay::new(when));
async_wait!(Delay::new(when));
}