Skip to content

Commit cf9747e

Browse files
committed
Add tcp_user_timeout to postgres
1 parent 117e387 commit cf9747e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

postgres/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ use tokio_postgres::{Error, Socket};
4444
/// omitted or the empty string.
4545
/// * `connect_timeout` - The time limit in seconds applied to each socket-level connection attempt. Note that hostnames
4646
/// can resolve to multiple IP addresses, and this limit is applied to each address. Defaults to no timeout.
47+
/// * `tcp_user_timeout` - The time limit that transmitted data may remain unacknowledged before a connection is forcibly closed.
48+
/// This is ignored for Unix domain socket connections. It is only supported on systems where TCP_USER_TIMEOUT is available
49+
/// and will default to the system default if omitted or set to 0; on other systems, it has no effect.
4750
/// * `keepalives` - Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it.
4851
/// This option is ignored when connecting with Unix sockets. Defaults to on.
4952
/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
@@ -256,6 +259,22 @@ impl Config {
256259
self.config.get_connect_timeout()
257260
}
258261

262+
/// Sets the TCP user timeout.
263+
///
264+
/// This is ignored for Unix domain socket connections. It is only supported on systems where
265+
/// TCP_USER_TIMEOUT is available and will default to the system default if omitted or set to 0;
266+
/// on other systems, it has no effect.
267+
pub fn tcp_user_timeout(&mut self, tcp_user_timeout: Duration) -> &mut Config {
268+
self.config.tcp_user_timeout(tcp_user_timeout);
269+
self
270+
}
271+
272+
/// Gets the TCP user timeout, if one has been set with the
273+
/// `user_timeout` method.
274+
pub fn get_tcp_user_timeout(&self) -> Option<&Duration> {
275+
self.config.get_tcp_user_timeout()
276+
}
277+
259278
/// Controls the use of TCP keepalive.
260279
///
261280
/// This is ignored for Unix domain socket connections. Defaults to `true`.

0 commit comments

Comments
 (0)