Skip to content

Commit ee5a139

Browse files
committed
add in to param parsing; update doc
1 parent b4c05f4 commit ee5a139

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

tokio-postgres/src/cancel_query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
&config.host,
3939
config.port,
4040
config.connect_timeout,
41-
config.user_timeout,
41+
config.tcp_user_timeout,
4242
config.keepalive.as_ref(),
4343
)
4444
.await?;

tokio-postgres/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub(crate) struct SocketConfig {
156156
pub host: Host,
157157
pub port: u16,
158158
pub connect_timeout: Option<Duration>,
159-
pub user_timeout: Option<Duration>,
159+
pub tcp_user_timeout: Option<Duration>,
160160
pub keepalive: Option<KeepaliveConfig>,
161161
}
162162

tokio-postgres/src/config.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ pub enum Host {
9696
/// omitted or the empty string.
9797
/// * `connect_timeout` - The time limit in seconds applied to each socket-level connection attempt. Note that hostnames
9898
/// 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; on other systems, it has no effect.
99102
/// * `keepalives` - Controls the use of TCP keepalive. A value of 0 disables keepalive and nonzero integers enable it.
100103
/// This option is ignored when connecting with Unix sockets. Defaults to on.
101104
/// * `keepalives_idle` - The number of seconds of inactivity after which a keepalive message is sent to the server.
@@ -160,7 +163,7 @@ pub struct Config {
160163
pub(crate) host: Vec<Host>,
161164
pub(crate) port: Vec<u16>,
162165
pub(crate) connect_timeout: Option<Duration>,
163-
pub(crate) user_timeout: Option<Duration>,
166+
pub(crate) tcp_user_timeout: Option<Duration>,
164167
pub(crate) keepalives: bool,
165168
pub(crate) keepalive_config: KeepaliveConfig,
166169
pub(crate) target_session_attrs: TargetSessionAttrs,
@@ -191,7 +194,7 @@ impl Config {
191194
host: vec![],
192195
port: vec![],
193196
connect_timeout: None,
194-
user_timeout: None,
197+
tcp_user_timeout: None,
195198
keepalives: true,
196199
keepalive_config,
197200
target_session_attrs: TargetSessionAttrs::Any,
@@ -343,15 +346,19 @@ impl Config {
343346
}
344347

345348
/// Sets the TCP user timeout.
346-
pub fn user_timeout(&mut self, user_timeout: Duration) -> &mut Config {
347-
self.user_timeout = Some(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; on other systems,
352+
/// 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);
348355
self
349356
}
350357

351358
/// Gets the TCP user timeout, if one has been set with the
352359
/// `user_timeout` method.
353-
pub fn get_user_timeout(&self) -> Option<&Duration> {
354-
self.user_timeout.as_ref()
360+
pub fn get_tcp_user_timeout(&self) -> Option<&Duration> {
361+
self.tcp_user_timeout.as_ref()
355362
}
356363

357364
/// Controls the use of TCP keepalive.
@@ -488,6 +495,14 @@ impl Config {
488495
self.connect_timeout(Duration::from_secs(timeout as u64));
489496
}
490497
}
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+
}
491506
"keepalives" => {
492507
let keepalives = value
493508
.parse::<u64>()
@@ -609,6 +624,7 @@ impl fmt::Debug for Config {
609624
.field("host", &self.host)
610625
.field("port", &self.port)
611626
.field("connect_timeout", &self.connect_timeout)
627+
.field("tcp_user_timeout", &self.tcp_user_timeout)
612628
.field("keepalives", &self.keepalives)
613629
.field("keepalives_idle", &self.keepalive_config.idle)
614630
.field("keepalives_interval", &self.keepalive_config.interval)

tokio-postgres/src/connect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
host,
6666
port,
6767
config.connect_timeout,
68-
config.user_timeout,
68+
config.tcp_user_timeout,
6969
if config.keepalives {
7070
Some(&config.keepalive_config)
7171
} else {
@@ -119,7 +119,7 @@ where
119119
host: host.clone(),
120120
port,
121121
connect_timeout: config.connect_timeout,
122-
user_timeout: config.user_timeout,
122+
tcp_user_timeout: config.tcp_user_timeout,
123123
keepalive: if config.keepalives {
124124
Some(config.keepalive_config.clone())
125125
} else {

tokio-postgres/src/connect_socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) async fn connect_socket(
1414
host: &Host,
1515
port: u16,
1616
connect_timeout: Option<Duration>,
17-
user_timeout: Option<Duration>,
17+
tcp_user_timeout: Option<Duration>,
1818
keepalive_config: Option<&KeepaliveConfig>,
1919
) -> Result<Socket, Error> {
2020
match host {
@@ -41,7 +41,7 @@ pub(crate) async fn connect_socket(
4141
#[cfg(target_os = "linux")]
4242
{
4343
sock_ref
44-
.set_tcp_user_timeout(user_timeout)
44+
.set_tcp_user_timeout(tcp_user_timeout)
4545
.map_err(Error::timeout)?;
4646
}
4747

0 commit comments

Comments
 (0)