refactor(server): work around deprecation of poll_accept method in tokio (#1890)
This commit is contained in:
committed by
Sean McArthur
parent
a543c8eef2
commit
9d5299b655
@@ -2,7 +2,7 @@
|
|||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio_fs::file::File;
|
use tokio_fs::File;
|
||||||
|
|
||||||
use hyper::{Body, Method, Result, Request, Response, Server, StatusCode};
|
use hyper::{Body, Method, Result, Request, Response, Server, StatusCode};
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::mem;
|
|||||||
use tokio_sync::{mpsc, watch};
|
use tokio_sync::{mpsc, watch};
|
||||||
|
|
||||||
use super::{Future, Never, Poll, Pin, task};
|
use super::{Future, Never, Poll, Pin, task};
|
||||||
|
use futures_util::FutureExt as _;
|
||||||
|
|
||||||
// Sentinel value signaling that the watch is still open
|
// Sentinel value signaling that the watch is still open
|
||||||
enum Action {
|
enum Action {
|
||||||
@@ -99,7 +100,9 @@ where
|
|||||||
loop {
|
loop {
|
||||||
match mem::replace(&mut me.state, State::Draining) {
|
match mem::replace(&mut me.state, State::Draining) {
|
||||||
State::Watch(on_drain) => {
|
State::Watch(on_drain) => {
|
||||||
match me.watch.rx.poll_ref(cx) {
|
let mut recv_fut = me.watch.rx.recv_ref().boxed();
|
||||||
|
|
||||||
|
match recv_fut.poll_unpin(cx) {
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
// Drain has been triggered!
|
// Drain has been triggered!
|
||||||
on_drain(unsafe { Pin::new_unchecked(&mut me.future) });
|
on_drain(unsafe { Pin::new_unchecked(&mut me.future) });
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::net::{SocketAddr, TcpListener as StdTcpListener};
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
|
use futures_util::FutureExt as _;
|
||||||
use tokio_reactor::Handle;
|
use tokio_reactor::Handle;
|
||||||
use tokio_tcp::TcpListener;
|
use tokio_tcp::TcpListener;
|
||||||
use tokio_timer::Delay;
|
use tokio_timer::Delay;
|
||||||
@@ -105,8 +106,10 @@ impl AddrIncoming {
|
|||||||
}
|
}
|
||||||
self.timeout = None;
|
self.timeout = None;
|
||||||
|
|
||||||
|
let mut accept_fut = self.listener.accept().boxed();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match Pin::new(&mut self.listener).poll_accept(cx) {
|
match accept_fut.poll_unpin(cx) {
|
||||||
Poll::Ready(Ok((socket, addr))) => {
|
Poll::Ready(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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user