refactor(h1): use futures::ready! in a few places

This commit is contained in:
Markus Westerlind
2020-06-23 17:06:39 +02:00
committed by GitHub
parent 981d26d5a1
commit 07f2fd1775
2 changed files with 7 additions and 16 deletions

View File

@@ -214,8 +214,8 @@ where
let (reading, ret) = match self.state.reading { let (reading, ret) = match self.state.reading {
Reading::Body(ref mut decoder) => { Reading::Body(ref mut decoder) => {
match decoder.decode(cx, &mut self.io) { match ready!(decoder.decode(cx, &mut self.io)) {
Poll::Ready(Ok(slice)) => { Ok(slice) => {
let (reading, chunk) = if decoder.is_eof() { let (reading, chunk) = if decoder.is_eof() {
debug!("incoming body completed"); debug!("incoming body completed");
( (
@@ -237,8 +237,7 @@ where
}; };
(reading, Poll::Ready(chunk)) (reading, Poll::Ready(chunk))
} }
Poll::Pending => return Poll::Pending, Err(e) => {
Poll::Ready(Err(e)) => {
debug!("incoming body decode error: {}", e); debug!("incoming body decode error: {}", e);
(Reading::Closed, Poll::Ready(Some(Err(e)))) (Reading::Closed, Poll::Ready(Some(Err(e))))
} }

View File

@@ -3,7 +3,6 @@ use std::io;
use std::net::{SocketAddr, TcpListener as StdTcpListener}; use std::net::{SocketAddr, TcpListener as StdTcpListener};
use std::time::Duration; use std::time::Duration;
use futures_util::FutureExt as _;
use tokio::net::TcpListener; use tokio::net::TcpListener;
use tokio::time::Delay; use tokio::time::Delay;
@@ -91,19 +90,13 @@ impl AddrIncoming {
fn poll_next_(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<AddrStream>> { fn poll_next_(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<AddrStream>> {
// Check if a previous timeout is active that was set by IO errors. // Check if a previous timeout is active that was set by IO errors.
if let Some(ref mut to) = self.timeout { if let Some(ref mut to) = self.timeout {
match Pin::new(to).poll(cx) { ready!(Pin::new(to).poll(cx));
Poll::Ready(()) => {}
Poll::Pending => return Poll::Pending,
}
} }
self.timeout = None; self.timeout = None;
let accept = self.listener.accept();
futures_util::pin_mut!(accept);
loop { loop {
match accept.poll_unpin(cx) { match ready!(self.listener.poll_accept(cx)) {
Poll::Ready(Ok((socket, addr))) => { Ok((socket, addr)) => {
if let Some(dur) = self.tcp_keepalive_timeout { if let Some(dur) = self.tcp_keepalive_timeout {
if let Err(e) = socket.set_keepalive(Some(dur)) { if let Err(e) = socket.set_keepalive(Some(dur)) {
trace!("error trying to set TCP keepalive: {}", e); trace!("error trying to set TCP keepalive: {}", e);
@@ -114,8 +107,7 @@ impl AddrIncoming {
} }
return Poll::Ready(Ok(AddrStream::new(socket, addr))); return Poll::Ready(Ok(AddrStream::new(socket, addr)));
} }
Poll::Pending => return Poll::Pending, Err(e) => {
Poll::Ready(Err(e)) => {
// Connection errors can be ignored directly, continue by // Connection errors can be ignored directly, continue by
// accepting the next request. // accepting the next request.
if is_connection_error(&e) { if is_connection_error(&e) {