Skip to content

Commit

Permalink
Refactor: replace tokio_timer::Timer with Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Dec 18, 2017
1 parent e77e9e3 commit 1884bd6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use std::io::{self, Write, ErrorKind};
use std::iter::FromIterator;
use std::collections::VecDeque;
use tokio_core::net::TcpStream;
use tokio_core::reactor::Handle;
use tokio_timer::{Timer, Sleep};
use tokio_core::reactor::{Handle, Timeout};
use futures::{Future, Poll, Async};
use proxy::{ProxyServer, Destination, Connect};
use client::RcBox;

struct TryConnect {
server: Rc<ProxyServer>,
state: TryConnectState,
timer: Sleep,
timer: Timeout,
}

enum TryConnectState {
Expand All @@ -34,7 +33,8 @@ fn try_connect(dest: &Destination, server: Rc<ProxyServer>,
connect: server.connect(dest.clone(), &handle),
wait_response, pending_data,
};
let timer = Timer::default().sleep(server.max_wait);
let timer = Timeout::new(server.max_wait, &handle)
.expect("error on get timeout from reactor");
TryConnect { server, state, timer }
}

Expand All @@ -43,7 +43,7 @@ impl Future for TryConnect {
type Error = io::Error;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
if self.timer.is_expired() {
if self.timer.poll()?.is_ready() {
return Err(io::Error::new(ErrorKind::TimedOut, "connect timeout"));
}
let new_state = match self.state {
Expand Down

0 comments on commit 1884bd6

Please sign in to comment.