Skip to content

Commit 07f2fd1

Browse files
author
Markus Westerlind
authored
refactor(h1): use futures::ready! in a few places
1 parent 981d26d commit 07f2fd1

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/proto/h1/conn.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ where
214214

215215
let (reading, ret) = match self.state.reading {
216216
Reading::Body(ref mut decoder) => {
217-
match decoder.decode(cx, &mut self.io) {
218-
Poll::Ready(Ok(slice)) => {
217+
match ready!(decoder.decode(cx, &mut self.io)) {
218+
Ok(slice) => {
219219
let (reading, chunk) = if decoder.is_eof() {
220220
debug!("incoming body completed");
221221
(
@@ -237,8 +237,7 @@ where
237237
};
238238
(reading, Poll::Ready(chunk))
239239
}
240-
Poll::Pending => return Poll::Pending,
241-
Poll::Ready(Err(e)) => {
240+
Err(e) => {
242241
debug!("incoming body decode error: {}", e);
243242
(Reading::Closed, Poll::Ready(Some(Err(e))))
244243
}

src/server/tcp.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::io;
33
use std::net::{SocketAddr, TcpListener as StdTcpListener};
44
use std::time::Duration;
55

6-
use futures_util::FutureExt as _;
76
use tokio::net::TcpListener;
87
use tokio::time::Delay;
98

@@ -91,19 +90,13 @@ impl AddrIncoming {
9190
fn poll_next_(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<AddrStream>> {
9291
// Check if a previous timeout is active that was set by IO errors.
9392
if let Some(ref mut to) = self.timeout {
94-
match Pin::new(to).poll(cx) {
95-
Poll::Ready(()) => {}
96-
Poll::Pending => return Poll::Pending,
97-
}
93+
ready!(Pin::new(to).poll(cx));
9894
}
9995
self.timeout = None;
10096

101-
let accept = self.listener.accept();
102-
futures_util::pin_mut!(accept);
103-
10497
loop {
105-
match accept.poll_unpin(cx) {
106-
Poll::Ready(Ok((socket, addr))) => {
98+
match ready!(self.listener.poll_accept(cx)) {
99+
Ok((socket, addr)) => {
107100
if let Some(dur) = self.tcp_keepalive_timeout {
108101
if let Err(e) = socket.set_keepalive(Some(dur)) {
109102
trace!("error trying to set TCP keepalive: {}", e);
@@ -114,8 +107,7 @@ impl AddrIncoming {
114107
}
115108
return Poll::Ready(Ok(AddrStream::new(socket, addr)));
116109
}
117-
Poll::Pending => return Poll::Pending,
118-
Poll::Ready(Err(e)) => {
110+
Err(e) => {
119111
// Connection errors can be ignored directly, continue by
120112
// accepting the next request.
121113
if is_connection_error(&e) {

0 commit comments

Comments
 (0)