@@ -96,6 +96,9 @@ pub enum Host {
96
96
/// omitted or the empty string.
97
97
/// * `connect_timeout` - The time limit in seconds applied to each socket-level connection attempt. Note that hostnames
98
98
/// can resolve to multiple IP addresses, and this limit is applied to each address. Defaults to no timeout.
99
+ /// * `tcp_user_timeout` - The time limit that transmitted data may remain unacknowledged before a connection is forcibly closed.
100
+ /// This is ignored for Unix domain socket connections. It is only supported on systems where TCP_USER_TIMEOUT is available
101
+ /// and will default to the system default if omitted or set to 0; on other systems, it has no effect.
99
102
/// * `keepalives` - Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it.
100
103
/// This option is ignored when connecting with Unix sockets. Defaults to on.
101
104
/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
@@ -160,6 +163,7 @@ pub struct Config {
160
163
pub ( crate ) host : Vec < Host > ,
161
164
pub ( crate ) port : Vec < u16 > ,
162
165
pub ( crate ) connect_timeout : Option < Duration > ,
166
+ pub ( crate ) tcp_user_timeout : Option < Duration > ,
163
167
pub ( crate ) keepalives : bool ,
164
168
pub ( crate ) keepalive_config : KeepaliveConfig ,
165
169
pub ( crate ) target_session_attrs : TargetSessionAttrs ,
@@ -190,6 +194,7 @@ impl Config {
190
194
host : vec ! [ ] ,
191
195
port : vec ! [ ] ,
192
196
connect_timeout : None ,
197
+ tcp_user_timeout : None ,
193
198
keepalives : true ,
194
199
keepalive_config,
195
200
target_session_attrs : TargetSessionAttrs :: Any ,
@@ -340,6 +345,22 @@ impl Config {
340
345
self . connect_timeout . as_ref ( )
341
346
}
342
347
348
+ /// Sets the TCP user timeout.
349
+ ///
350
+ /// This is ignored for Unix domain socket connections. It is only supported on systems where
351
+ /// TCP_USER_TIMEOUT is available and will default to the system default if omitted or set to 0;
352
+ /// on other systems, it has no effect.
353
+ pub fn tcp_user_timeout ( & mut self , tcp_user_timeout : Duration ) -> & mut Config {
354
+ self . tcp_user_timeout = Some ( tcp_user_timeout) ;
355
+ self
356
+ }
357
+
358
+ /// Gets the TCP user timeout, if one has been set with the
359
+ /// `user_timeout` method.
360
+ pub fn get_tcp_user_timeout ( & self ) -> Option < & Duration > {
361
+ self . tcp_user_timeout . as_ref ( )
362
+ }
363
+
343
364
/// Controls the use of TCP keepalive.
344
365
///
345
366
/// This is ignored for Unix domain socket connections. Defaults to `true`.
@@ -474,6 +495,14 @@ impl Config {
474
495
self . connect_timeout ( Duration :: from_secs ( timeout as u64 ) ) ;
475
496
}
476
497
}
498
+ "tcp_user_timeout" => {
499
+ let timeout = value
500
+ . parse :: < i64 > ( )
501
+ . map_err ( |_| Error :: config_parse ( Box :: new ( InvalidValue ( "tcp_user_timeout" ) ) ) ) ?;
502
+ if timeout > 0 {
503
+ self . tcp_user_timeout ( Duration :: from_secs ( timeout as u64 ) ) ;
504
+ }
505
+ }
477
506
"keepalives" => {
478
507
let keepalives = value
479
508
. parse :: < u64 > ( )
@@ -595,6 +624,7 @@ impl fmt::Debug for Config {
595
624
. field ( "host" , & self . host )
596
625
. field ( "port" , & self . port )
597
626
. field ( "connect_timeout" , & self . connect_timeout )
627
+ . field ( "tcp_user_timeout" , & self . tcp_user_timeout )
598
628
. field ( "keepalives" , & self . keepalives )
599
629
. field ( "keepalives_idle" , & self . keepalive_config . idle )
600
630
. field ( "keepalives_interval" , & self . keepalive_config . interval )
0 commit comments