@@ -116,6 +116,9 @@ pub enum Host {
116116/// omitted or the empty string.
117117/// * `connect_timeout` - The time limit in seconds applied to each socket-level connection attempt. Note that hostnames
118118/// can resolve to multiple IP addresses, and this limit is applied to each address. Defaults to no timeout.
119+ /// * `tcp_user_timeout` - The time limit that transmitted data may remain unacknowledged before a connection is forcibly closed.
120+ /// This is ignored for Unix domain socket connections. It is only supported on systems where TCP_USER_TIMEOUT is available
121+ /// and will default to the system default if omitted or set to 0; on other systems, it has no effect.
119122/// * `keepalives` - Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it.
120123/// This option is ignored when connecting with Unix sockets. Defaults to on.
121124/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
@@ -183,6 +186,7 @@ pub struct Config {
183186 pub ( crate ) host : Vec < Host > ,
184187 pub ( crate ) port : Vec < u16 > ,
185188 pub ( crate ) connect_timeout : Option < Duration > ,
189+ pub ( crate ) tcp_user_timeout : Option < Duration > ,
186190 pub ( crate ) keepalives : bool ,
187191 pub ( crate ) keepalive_config : KeepaliveConfig ,
188192 pub ( crate ) target_session_attrs : TargetSessionAttrs ,
@@ -217,6 +221,7 @@ impl Config {
217221 host : vec ! [ ] ,
218222 port : vec ! [ ] ,
219223 connect_timeout : None ,
224+ tcp_user_timeout : None ,
220225 keepalives : true ,
221226 keepalive_config,
222227 target_session_attrs : TargetSessionAttrs :: Any ,
@@ -407,6 +412,21 @@ impl Config {
407412 self . connect_timeout . as_ref ( )
408413 }
409414
415+ /// Sets the TCP user timeout.
416+ ///
417+ /// This is ignored for Unix domain socket connections. It is only supported on systems where
418+ /// TCP_USER_TIMEOUT is available and will default to the system default if omitted or set to 0;
419+ /// on other systems, it has no effect.
420+ pub fn tcp_user_timeout ( & mut self , tcp_user_timeout : Duration ) -> & mut Config {
421+ self . tcp_user_timeout = Some ( tcp_user_timeout) ;
422+ self
423+ }
424+
425+ /// Gets the TCP user timeout, if one has been set with the
426+ /// `user_timeout` method.
427+ pub fn get_tcp_user_timeout ( & self ) -> Option < & Duration > {
428+ self . tcp_user_timeout . as_ref ( )
429+ }
410430 /// Controls the use of TCP keepalive.
411431 ///
412432 /// This is ignored for Unix domain socket connections. Defaults to `true`.
@@ -578,6 +598,14 @@ impl Config {
578598 self . connect_timeout ( Duration :: from_secs ( timeout as u64 ) ) ;
579599 }
580600 }
601+ "tcp_user_timeout" => {
602+ let timeout = value
603+ . parse :: < i64 > ( )
604+ . map_err ( |_| Error :: config_parse ( Box :: new ( InvalidValue ( "tcp_user_timeout" ) ) ) ) ?;
605+ if timeout > 0 {
606+ self . tcp_user_timeout ( Duration :: from_secs ( timeout as u64 ) ) ;
607+ }
608+ }
581609 "keepalives" => {
582610 let keepalives = value
583611 . parse :: < u64 > ( )
@@ -713,6 +741,7 @@ impl fmt::Debug for Config {
713741 . field ( "host" , & self . host )
714742 . field ( "port" , & self . port )
715743 . field ( "connect_timeout" , & self . connect_timeout )
744+ . field ( "tcp_user_timeout" , & self . tcp_user_timeout )
716745 . field ( "keepalives" , & self . keepalives )
717746 . field ( "keepalives_idle" , & self . keepalive_config . idle )
718747 . field ( "keepalives_interval" , & self . keepalive_config . interval )
0 commit comments