File tree Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,15 @@ impl Manager<TcpStream, std::io::Error> for TcpConnection {
63
63
64
64
async fn recycle ( & self , conn : & mut TcpStream ) -> RecycleResult < std:: io:: Error > {
65
65
let mut buf = [ 0 ; 4 ] ;
66
- conn. peek ( & mut buf[ ..] ) . await ?;
66
+ let mut cx = Context :: from_waker ( futures:: task:: noop_waker_ref ( ) ) ;
67
+ match Pin :: new ( conn) . poll_read ( & mut cx, & mut buf) {
68
+ Poll :: Ready ( Err ( error) ) => Err ( error) ,
69
+ Poll :: Ready ( Ok ( bytes) ) if bytes == 0 => Err ( std:: io:: Error :: new (
70
+ std:: io:: ErrorKind :: UnexpectedEof ,
71
+ "connection appeared to be closed (EoF)" ,
72
+ ) ) ,
73
+ _ => Ok ( ( ) ) ,
74
+ } ?;
67
75
Ok ( ( ) )
68
76
}
69
77
}
Original file line number Diff line number Diff line change @@ -76,10 +76,16 @@ impl Manager<TlsStream<TcpStream>, Error> for TlsConnection {
76
76
77
77
async fn recycle ( & self , conn : & mut TlsStream < TcpStream > ) -> RecycleResult < Error > {
78
78
let mut buf = [ 0 ; 4 ] ;
79
- conn. get_ref ( )
80
- . peek ( & mut buf[ ..] )
81
- . await
82
- . map_err ( Error :: from) ?;
79
+ let mut cx = Context :: from_waker ( futures:: task:: noop_waker_ref ( ) ) ;
80
+ match Pin :: new ( conn) . poll_read ( & mut cx, & mut buf) {
81
+ Poll :: Ready ( Err ( error) ) => Err ( error) ,
82
+ Poll :: Ready ( Ok ( bytes) ) if bytes == 0 => Err ( std:: io:: Error :: new (
83
+ std:: io:: ErrorKind :: UnexpectedEof ,
84
+ "connection appeared to be closed (EoF)" ,
85
+ ) ) ,
86
+ _ => Ok ( ( ) ) ,
87
+ }
88
+ . map_err ( Error :: from) ?;
83
89
Ok ( ( ) )
84
90
}
85
91
}
Original file line number Diff line number Diff line change @@ -135,3 +135,17 @@ SOFTWARE.
135
135
136
136
Ok ( ( ) )
137
137
}
138
+
139
+ #[ atest]
140
+ async fn keep_alive ( ) {
141
+ let _mock_guard = mockito:: mock ( "GET" , "/report" )
142
+ . with_status ( 200 )
143
+ . expect_at_least ( 2 )
144
+ . create ( ) ;
145
+
146
+ let client = DefaultClient :: new ( ) ;
147
+ let url: Url = format ! ( "{}/report" , mockito:: server_url( ) ) . parse ( ) . unwrap ( ) ;
148
+ let req = Request :: new ( http_types:: Method :: Get , url) ;
149
+ client. send ( req. clone ( ) ) . await . unwrap ( ) ;
150
+ client. send ( req. clone ( ) ) . await . unwrap ( ) ;
151
+ }
You can’t perform that action at this time.
0 commit comments