From 183e30f4862cbd09af322283914c4e0bd3cb3bcb Mon Sep 17 00:00:00 2001 From: quininer Date: Thu, 23 May 2019 00:05:42 +0800 Subject: [PATCH] use futures::ready! --- .travis.yml | 2 ++ src/client.rs | 12 ++++++------ src/common/mod.rs | 4 ++-- src/common/test_stream.rs | 4 ++-- src/lib.rs | 10 ---------- src/server.rs | 4 ++-- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9efee9d..79678c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ matrix: os: osx - rust: nightly os: osx + allow_failures: + - rust: stable script: - cargo test diff --git a/src/client.rs b/src/client.rs index 9f1f7f6..7bce1b8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -53,11 +53,11 @@ where let mut stream = Stream::new(io, session).set_eof(eof); if stream.session.is_handshaking() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } if stream.session.wants_write() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } } @@ -91,13 +91,13 @@ where // complete handshake if stream.session.is_handshaking() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } // write early data (fallback) if !stream.session.is_early_data_accepted() { while *pos < data.len() { - let len = try_ready!(stream.pin().poll_write(cx, &data[*pos..])); + let len = futures::ready!(stream.pin().poll_write(cx, &data[*pos..]))?; *pos += len; } } @@ -161,13 +161,13 @@ where // complete handshake if stream.session.is_handshaking() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } // write early data (fallback) if !stream.session.is_early_data_accepted() { while *pos < data.len() { - let len = try_ready!(stream.pin().poll_write(cx, &data[*pos..])); + let len = futures::ready!(stream.pin().poll_write(cx, &data[*pos..]))?; *pos += len; } } diff --git a/src/common/mod.rs b/src/common/mod.rs index 4d65be7..bff9990 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -227,7 +227,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> AsyncWrite for Stream<' this.session.flush()?; while this.session.wants_write() { - try_ready!(this.complete_inner_io(cx, Focus::Writable)); + futures::ready!(this.complete_inner_io(cx, Focus::Writable))?; } Pin::new(&mut this.io).poll_flush(cx) } @@ -236,7 +236,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> AsyncWrite for Stream<' let this = self.get_mut(); while this.session.wants_write() { - try_ready!(this.complete_inner_io(cx, Focus::Writable)); + futures::ready!(this.complete_inner_io(cx, Focus::Writable))?; } Pin::new(&mut this.io).poll_close(cx) } diff --git a/src/common/test_stream.rs b/src/common/test_stream.rs index 67b9146..1f7c14c 100644 --- a/src/common/test_stream.rs +++ b/src/common/test_stream.rs @@ -206,11 +206,11 @@ fn do_handshake(client: &mut ClientSession, server: &mut ServerSession, cx: &mut let mut stream = Stream::new(&mut good, client); if stream.session.is_handshaking() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } if stream.session.wants_write() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } Poll::Ready(Ok(())) diff --git a/src/lib.rs b/src/lib.rs index cca1c85..a928b87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,16 +2,6 @@ #![feature(async_await)] -macro_rules! try_ready { - ( $e:expr ) => { - match $e { - Poll::Ready(Ok(output)) => output, - Poll::Ready(Err(err)) => return Poll::Ready(Err(err.into())), - Poll::Pending => return Poll::Pending - } - } -} - mod common; pub mod client; pub mod server; diff --git a/src/server.rs b/src/server.rs index 21cc5e6..2ed7ba9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -48,11 +48,11 @@ where let mut stream = Stream::new(io, session).set_eof(eof); if stream.session.is_handshaking() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } if stream.session.wants_write() { - try_ready!(stream.complete_io(cx)); + futures::ready!(stream.complete_io(cx))?; } }