Skip to content

Commit 9d5299b

Browse files
yotamofekseanmonstar
authored andcommitted
refactor(server): work around deprecation of poll_accept method in tokio (#1890)
1 parent a543c8e commit 9d5299b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

examples/send_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![deny(warnings)]
33

44
use tokio::io::AsyncReadExt;
5-
use tokio_fs::file::File;
5+
use tokio_fs::File;
66

77
use hyper::{Body, Method, Result, Request, Response, Server, StatusCode};
88
use hyper::service::{make_service_fn, service_fn};

src/common/drain.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::mem;
33
use tokio_sync::{mpsc, watch};
44

55
use super::{Future, Never, Poll, Pin, task};
6+
use futures_util::FutureExt as _;
67

78
// Sentinel value signaling that the watch is still open
89
enum Action {
@@ -99,7 +100,9 @@ where
99100
loop {
100101
match mem::replace(&mut me.state, State::Draining) {
101102
State::Watch(on_drain) => {
102-
match me.watch.rx.poll_ref(cx) {
103+
let mut recv_fut = me.watch.rx.recv_ref().boxed();
104+
105+
match recv_fut.poll_unpin(cx) {
103106
Poll::Ready(None) => {
104107
// Drain has been triggered!
105108
on_drain(unsafe { Pin::new_unchecked(&mut me.future) });

src/server/tcp.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::net::{SocketAddr, TcpListener as StdTcpListener};
44
use std::time::{Duration, Instant};
55

66
use futures_core::Stream;
7+
use futures_util::FutureExt as _;
78
use tokio_reactor::Handle;
89
use tokio_tcp::TcpListener;
910
use tokio_timer::Delay;
@@ -105,8 +106,10 @@ impl AddrIncoming {
105106
}
106107
self.timeout = None;
107108

109+
let mut accept_fut = self.listener.accept().boxed();
110+
108111
loop {
109-
match Pin::new(&mut self.listener).poll_accept(cx) {
112+
match accept_fut.poll_unpin(cx) {
110113
Poll::Ready(Ok((socket, addr))) => {
111114
if let Some(dur) = self.tcp_keepalive_timeout {
112115
if let Err(e) = socket.set_keepalive(Some(dur)) {

0 commit comments

Comments
 (0)