use futures::ready!

This commit is contained in:
quininer 2019-05-23 00:05:42 +08:00
parent b8e3fcb79e
commit 183e30f486
6 changed files with 14 additions and 22 deletions

View File

@ -11,6 +11,8 @@ matrix:
os: osx os: osx
- rust: nightly - rust: nightly
os: osx os: osx
allow_failures:
- rust: stable
script: script:
- cargo test - cargo test

View File

@ -53,11 +53,11 @@ where
let mut stream = Stream::new(io, session).set_eof(eof); let mut stream = Stream::new(io, session).set_eof(eof);
if stream.session.is_handshaking() { if stream.session.is_handshaking() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
if stream.session.wants_write() { if stream.session.wants_write() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
} }
@ -91,13 +91,13 @@ where
// complete handshake // complete handshake
if stream.session.is_handshaking() { if stream.session.is_handshaking() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
// write early data (fallback) // write early data (fallback)
if !stream.session.is_early_data_accepted() { if !stream.session.is_early_data_accepted() {
while *pos < data.len() { 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; *pos += len;
} }
} }
@ -161,13 +161,13 @@ where
// complete handshake // complete handshake
if stream.session.is_handshaking() { if stream.session.is_handshaking() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
// write early data (fallback) // write early data (fallback)
if !stream.session.is_early_data_accepted() { if !stream.session.is_early_data_accepted() {
while *pos < data.len() { 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; *pos += len;
} }
} }

View File

@ -227,7 +227,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> AsyncWrite for Stream<'
this.session.flush()?; this.session.flush()?;
while this.session.wants_write() { 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) 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(); let this = self.get_mut();
while this.session.wants_write() { 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) Pin::new(&mut this.io).poll_close(cx)
} }

View File

@ -206,11 +206,11 @@ fn do_handshake(client: &mut ClientSession, server: &mut ServerSession, cx: &mut
let mut stream = Stream::new(&mut good, client); let mut stream = Stream::new(&mut good, client);
if stream.session.is_handshaking() { if stream.session.is_handshaking() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
if stream.session.wants_write() { if stream.session.wants_write() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
Poll::Ready(Ok(())) Poll::Ready(Ok(()))

View File

@ -2,16 +2,6 @@
#![feature(async_await)] #![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; mod common;
pub mod client; pub mod client;
pub mod server; pub mod server;

View File

@ -48,11 +48,11 @@ where
let mut stream = Stream::new(io, session).set_eof(eof); let mut stream = Stream::new(io, session).set_eof(eof);
if stream.session.is_handshaking() { if stream.session.is_handshaking() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
if stream.session.wants_write() { if stream.session.wants_write() {
try_ready!(stream.complete_io(cx)); futures::ready!(stream.complete_io(cx))?;
} }
} }