@@ -2,9 +2,10 @@ use std::future::Future;
2
2
use std:: io;
3
3
use std:: pin:: Pin ;
4
4
use std:: task:: { Context , Poll } ;
5
+ use std:: time:: Duration ;
5
6
6
7
use tokio:: io:: { AsyncRead , AsyncWrite } ;
7
- use tokio:: time:: { timeout, Duration } ;
8
+ use tokio:: time:: timeout;
8
9
use tokio_io_timeout:: TimeoutStream ;
9
10
10
11
use hyper:: client:: connect:: { Connect , Connected , Connection } ;
@@ -58,33 +59,28 @@ where
58
59
}
59
60
60
61
fn call ( & mut self , dst : Uri ) -> Self :: Future {
62
+ let connect_timeout = self . connect_timeout ;
61
63
let read_timeout = self . read_timeout ;
62
64
let write_timeout = self . write_timeout ;
63
65
let connecting = self . connector . call ( dst) ;
64
66
65
- if self . connect_timeout . is_none ( ) {
66
- let fut = async move {
67
- let io = connecting. await . map_err ( Into :: into) ?;
68
-
69
- let mut tm = TimeoutConnectorStream :: new ( TimeoutStream :: new ( io) ) ;
70
- tm. set_read_timeout ( read_timeout) ;
71
- tm. set_write_timeout ( write_timeout) ;
72
- Ok ( Box :: pin ( tm) )
73
- } ;
74
-
75
- return Box :: pin ( fut) ;
76
- }
77
-
78
- let connect_timeout = self . connect_timeout . expect ( "Connect timeout should be set" ) ;
79
- let timeout = timeout ( connect_timeout, connecting) ;
80
-
81
67
let fut = async move {
82
- let connecting = timeout
83
- . await
84
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: TimedOut , e) ) ?;
85
- let io = connecting. map_err ( Into :: into) ?;
68
+ let stream = match connect_timeout {
69
+ None => {
70
+ let io = connecting. await . map_err ( Into :: into) ?;
71
+ TimeoutStream :: new ( io)
72
+ }
73
+ Some ( connect_timeout) => {
74
+ let timeout = timeout ( connect_timeout, connecting) ;
75
+ let connecting = timeout
76
+ . await
77
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: TimedOut , e) ) ?;
78
+ let io = connecting. map_err ( Into :: into) ?;
79
+ TimeoutStream :: new ( io)
80
+ }
81
+ } ;
86
82
87
- let mut tm = TimeoutConnectorStream :: new ( TimeoutStream :: new ( io ) ) ;
83
+ let mut tm = TimeoutConnectorStream :: new ( stream ) ;
88
84
tm. set_read_timeout ( read_timeout) ;
89
85
tm. set_write_timeout ( write_timeout) ;
90
86
Ok ( Box :: pin ( tm) )
0 commit comments