@@ -10,23 +10,22 @@ use std::{
1010 ops:: { Deref , DerefMut } ,
1111 pin:: Pin ,
1212 sync:: Arc ,
13- task:: { Context , Poll } ,
13+ task:: { self , Poll } ,
1414 time:: Duration ,
1515} ;
1616
1717use crate :: {
1818 config:: { ConfigType , ServerAddr , ServerConfig } ,
19- context:: SharedContext ,
19+ context:: Context ,
2020 relay:: { socks5:: Address , utils:: try_timeout} ,
2121} ;
2222
2323use bytes:: BytesMut ;
2424use futures:: { future:: FusedFuture , ready, select, Future } ;
2525use log:: trace;
2626use tokio:: {
27- io:: { BufReader , ReadHalf , WriteHalf } ,
27+ io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt , BufReader , ReadHalf , WriteHalf } ,
2828 net:: TcpStream ,
29- prelude:: * ,
3029 time:: { self , Delay } ,
3130} ;
3231
@@ -78,7 +77,7 @@ impl<S> Connection<S> {
7877 ErrorKind :: TimedOut . into ( )
7978 }
8079
81- fn poll_timeout ( & mut self , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
80+ fn poll_timeout ( & mut self , cx : & mut task :: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
8281 loop {
8382 if let Some ( ref mut timer) = self . timer {
8483 ready ! ( Pin :: new( timer) . poll( cx) ) ;
@@ -135,7 +134,7 @@ impl<S> AsyncRead for Connection<S>
135134where
136135 S : AsyncRead + Unpin ,
137136{
138- fn poll_read ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > , buf : & mut [ u8 ] ) -> Poll < io:: Result < usize > > {
137+ fn poll_read ( mut self : Pin < & mut Self > , cx : & mut task :: Context < ' _ > , buf : & mut [ u8 ] ) -> Poll < io:: Result < usize > > {
139138 match Pin :: new ( & mut self . stream ) . poll_read ( cx, buf) {
140139 Poll :: Ready ( r) => {
141140 self . cancel_timeout ( ) ;
@@ -153,7 +152,7 @@ impl<S> AsyncWrite for Connection<S>
153152where
154153 S : AsyncRead + AsyncWrite + Unpin ,
155154{
156- fn poll_write ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > , buf : & [ u8 ] ) -> Poll < io:: Result < usize > > {
155+ fn poll_write ( mut self : Pin < & mut Self > , cx : & mut task :: Context < ' _ > , buf : & [ u8 ] ) -> Poll < io:: Result < usize > > {
157156 match Pin :: new ( & mut self . stream ) . poll_write ( cx, buf) {
158157 Poll :: Ready ( r) => {
159158 self . cancel_timeout ( ) ;
@@ -166,7 +165,7 @@ where
166165 }
167166 }
168167
169- fn poll_flush ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
168+ fn poll_flush ( mut self : Pin < & mut Self > , cx : & mut task :: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
170169 match Pin :: new ( & mut self . stream ) . poll_flush ( cx) {
171170 Poll :: Ready ( r) => {
172171 self . cancel_timeout ( ) ;
@@ -179,15 +178,15 @@ where
179178 }
180179 }
181180
182- fn poll_shutdown ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
181+ fn poll_shutdown ( mut self : Pin < & mut Self > , cx : & mut task :: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
183182 Pin :: new ( & mut self . stream ) . poll_shutdown ( cx)
184183 }
185184}
186185
187186pub type STcpStream = Connection < TcpStream > ;
188187
189188/// Connect to proxy server with `ServerConfig`
190- async fn connect_proxy_server ( context : SharedContext , svr_cfg : Arc < ServerConfig > ) -> io:: Result < STcpStream > {
189+ async fn connect_proxy_server ( context : & Context , svr_cfg : & ServerConfig ) -> io:: Result < STcpStream > {
191190 let timeout = svr_cfg. timeout ( ) ;
192191
193192 let svr_addr = match context. config ( ) . config_type {
@@ -213,7 +212,7 @@ async fn connect_proxy_server(context: SharedContext, svr_cfg: Arc<ServerConfig>
213212 let mut last_err: Option < io:: Error > = None ;
214213 for addr in & vec_ipaddr {
215214 match try_timeout ( TcpStream :: connect ( addr) , timeout) . await {
216- Ok ( s) => return Ok ( STcpStream :: new ( BufReader :: new ( s ) , timeout) ) ,
215+ Ok ( s) => return Ok ( STcpStream :: new ( s , timeout) ) ,
217216 Err ( e) => {
218217 error ! (
219218 "Failed to connect {}:{}, resolved address {}, try another (err: {})" ,
0 commit comments