@@ -78,6 +78,8 @@ struct Config {
78
78
recv_buffer_size : Option < usize > ,
79
79
#[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
80
80
interface : Option < String > ,
81
+ #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
82
+ tcp_user_timeout : Option < Duration > ,
81
83
}
82
84
83
85
#[ derive( Default , Debug , Clone , Copy ) ]
@@ -182,6 +184,8 @@ impl<R> HttpConnector<R> {
182
184
recv_buffer_size : None ,
183
185
#[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
184
186
interface : None ,
187
+ #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
188
+ tcp_user_timeout : None ,
185
189
} ) ,
186
190
resolver,
187
191
}
@@ -324,6 +328,13 @@ impl<R> HttpConnector<R> {
324
328
self
325
329
}
326
330
331
+ /// Sets the value of the TCP_USER_TIMEOUT option on the socket.
332
+ #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
333
+ #[ inline]
334
+ pub fn set_tcp_user_timeout ( & mut self , time : Option < Duration > ) {
335
+ self . config_mut ( ) . set_tcp_user_timeout = time;
336
+ }
337
+
327
338
// private
328
339
329
340
fn config_mut ( & mut self ) -> & mut Config {
@@ -728,6 +739,13 @@ fn connect(
728
739
. map_err ( ConnectError :: m ( "tcp bind interface error" ) ) ?;
729
740
}
730
741
742
+ #[ cfg( any( target_os = "android" , target_os = "fuchsia" , target_os = "linux" ) ) ]
743
+ if let Some ( tcp_user_timeout) = & config. tcp_user_timeout_config . into_tcpkeepalive ( ) {
744
+ if let Err ( e) = socket. set_tcp_user_timeout ( tcp_user_timeout) {
745
+ warn ! ( "tcp set_tcp_user_timeout error: {}" , e) ;
746
+ }
747
+ }
748
+
731
749
bind_local_address (
732
750
& socket,
733
751
addr,
0 commit comments