wire through knob for TCP user timeout
This commit is contained in:
parent
70616712a4
commit
b4c05f4f81
@ -55,7 +55,7 @@ pin-project-lite = "0.2"
|
||||
phf = "0.11"
|
||||
postgres-protocol = { version = "0.6.4", path = "../postgres-protocol" }
|
||||
postgres-types = { version = "0.2.4", path = "../postgres-types" }
|
||||
socket2 = "0.4"
|
||||
socket2 = { version = "0.4", features = ["all"] }
|
||||
tokio = { version = "1.0", features = ["io-util"] }
|
||||
tokio-util = { version = "0.7", features = ["codec"] }
|
||||
|
||||
|
@ -38,6 +38,7 @@ where
|
||||
&config.host,
|
||||
config.port,
|
||||
config.connect_timeout,
|
||||
config.user_timeout,
|
||||
config.keepalive.as_ref(),
|
||||
)
|
||||
.await?;
|
||||
|
@ -156,6 +156,7 @@ pub(crate) struct SocketConfig {
|
||||
pub host: Host,
|
||||
pub port: u16,
|
||||
pub connect_timeout: Option<Duration>,
|
||||
pub user_timeout: Option<Duration>,
|
||||
pub keepalive: Option<KeepaliveConfig>,
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,7 @@ pub struct Config {
|
||||
pub(crate) host: Vec<Host>,
|
||||
pub(crate) port: Vec<u16>,
|
||||
pub(crate) connect_timeout: Option<Duration>,
|
||||
pub(crate) user_timeout: Option<Duration>,
|
||||
pub(crate) keepalives: bool,
|
||||
pub(crate) keepalive_config: KeepaliveConfig,
|
||||
pub(crate) target_session_attrs: TargetSessionAttrs,
|
||||
@ -190,6 +191,7 @@ impl Config {
|
||||
host: vec![],
|
||||
port: vec![],
|
||||
connect_timeout: None,
|
||||
user_timeout: None,
|
||||
keepalives: true,
|
||||
keepalive_config,
|
||||
target_session_attrs: TargetSessionAttrs::Any,
|
||||
@ -340,6 +342,18 @@ impl Config {
|
||||
self.connect_timeout.as_ref()
|
||||
}
|
||||
|
||||
/// Sets the TCP user timeout.
|
||||
pub fn user_timeout(&mut self, user_timeout: Duration) -> &mut Config {
|
||||
self.user_timeout = Some(user_timeout);
|
||||
self
|
||||
}
|
||||
|
||||
/// Gets the TCP user timeout, if one has been set with the
|
||||
/// `user_timeout` method.
|
||||
pub fn get_user_timeout(&self) -> Option<&Duration> {
|
||||
self.user_timeout.as_ref()
|
||||
}
|
||||
|
||||
/// Controls the use of TCP keepalive.
|
||||
///
|
||||
/// This is ignored for Unix domain socket connections. Defaults to `true`.
|
||||
|
@ -65,6 +65,7 @@ where
|
||||
host,
|
||||
port,
|
||||
config.connect_timeout,
|
||||
config.user_timeout,
|
||||
if config.keepalives {
|
||||
Some(&config.keepalive_config)
|
||||
} else {
|
||||
@ -118,6 +119,7 @@ where
|
||||
host: host.clone(),
|
||||
port,
|
||||
connect_timeout: config.connect_timeout,
|
||||
user_timeout: config.user_timeout,
|
||||
keepalive: if config.keepalives {
|
||||
Some(config.keepalive_config.clone())
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@ pub(crate) async fn connect_socket(
|
||||
host: &Host,
|
||||
port: u16,
|
||||
connect_timeout: Option<Duration>,
|
||||
user_timeout: Option<Duration>,
|
||||
keepalive_config: Option<&KeepaliveConfig>,
|
||||
) -> Result<Socket, Error> {
|
||||
match host {
|
||||
@ -35,8 +36,17 @@ pub(crate) async fn connect_socket(
|
||||
};
|
||||
|
||||
stream.set_nodelay(true).map_err(Error::connect)?;
|
||||
|
||||
let sock_ref = SockRef::from(&stream);
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
sock_ref
|
||||
.set_tcp_user_timeout(user_timeout)
|
||||
.map_err(Error::timeout)?;
|
||||
}
|
||||
|
||||
if let Some(keepalive_config) = keepalive_config {
|
||||
SockRef::from(&stream)
|
||||
sock_ref
|
||||
.set_tcp_keepalive(&TcpKeepalive::from(keepalive_config))
|
||||
.map_err(Error::connect)?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user