Skip to content

Commit

Permalink
refactor(h1): use futures::ready! in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind authored Jun 23, 2020
1 parent 981d26d commit 07f2fd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ where

let (reading, ret) = match self.state.reading {
Reading::Body(ref mut decoder) => {
match decoder.decode(cx, &mut self.io) {
Poll::Ready(Ok(slice)) => {
match ready!(decoder.decode(cx, &mut self.io)) {
Ok(slice) => {
let (reading, chunk) = if decoder.is_eof() {
debug!("incoming body completed");
(
Expand All @@ -237,8 +237,7 @@ where
};
(reading, Poll::Ready(chunk))
}
Poll::Pending => return Poll::Pending,
Poll::Ready(Err(e)) => {
Err(e) => {
debug!("incoming body decode error: {}", e);
(Reading::Closed, Poll::Ready(Some(Err(e))))
}
Expand Down
16 changes: 4 additions & 12 deletions src/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::io;
use std::net::{SocketAddr, TcpListener as StdTcpListener};
use std::time::Duration;

use futures_util::FutureExt as _;
use tokio::net::TcpListener;
use tokio::time::Delay;

Expand Down Expand Up @@ -91,19 +90,13 @@ impl AddrIncoming {
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.
if let Some(ref mut to) = self.timeout {
match Pin::new(to).poll(cx) {
Poll::Ready(()) => {}
Poll::Pending => return Poll::Pending,
}
ready!(Pin::new(to).poll(cx));
}
self.timeout = None;

let accept = self.listener.accept();
futures_util::pin_mut!(accept);

loop {
match accept.poll_unpin(cx) {
Poll::Ready(Ok((socket, addr))) => {
match ready!(self.listener.poll_accept(cx)) {
Ok((socket, addr)) => {
if let Some(dur) = self.tcp_keepalive_timeout {
if let Err(e) = socket.set_keepalive(Some(dur)) {
trace!("error trying to set TCP keepalive: {}", e);
Expand All @@ -114,8 +107,7 @@ impl AddrIncoming {
}
return Poll::Ready(Ok(AddrStream::new(socket, addr)));
}
Poll::Pending => return Poll::Pending,
Poll::Ready(Err(e)) => {
Err(e) => {
// Connection errors can be ignored directly, continue by
// accepting the next request.
if is_connection_error(&e) {
Expand Down

0 comments on commit 07f2fd1

Please sign in to comment.