Skip to content

Commit 3c9565d

Browse files
authored
Add support for tcp_user_timeout (#503)
* Add support for tcp_user_timeout * option * duration * Some() * docs * fmt, compile
1 parent 67579c9 commit 3c9565d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CONFIG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ path: general.tcp_keepalives_interval
151151
default: 5
152152
```
153153

154-
Number of seconds between keepalive packets.
154+
### tcp_user_timeout
155+
```
156+
path: general.tcp_user_timeout
157+
default: 10000
158+
```
159+
A linux-only parameters that defines the amount of time in milliseconds that transmitted data may remain unacknowledged or buffered data may remain untransmitted (due to zero window size) before TCP will forcibly disconnect
160+
155161

156162
### tls_certificate
157163
```

src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ pub struct General {
261261
pub tcp_keepalives_count: u32,
262262
#[serde(default = "General::default_tcp_keepalives_interval")]
263263
pub tcp_keepalives_interval: u64,
264+
#[serde(default = "General::default_tcp_user_timeout")]
265+
pub tcp_user_timeout: u64,
264266

265267
#[serde(default)] // False
266268
pub log_client_connections: bool,
@@ -360,6 +362,10 @@ impl General {
360362
5 // 5 seconds
361363
}
362364

365+
pub fn default_tcp_user_timeout() -> u64 {
366+
10000 // 10000 milliseconds
367+
}
368+
363369
pub fn default_idle_timeout() -> u64 {
364370
600000 // 10 minutes
365371
}
@@ -427,6 +433,7 @@ impl Default for General {
427433
tcp_keepalives_idle: Self::default_tcp_keepalives_idle(),
428434
tcp_keepalives_count: Self::default_tcp_keepalives_count(),
429435
tcp_keepalives_interval: Self::default_tcp_keepalives_interval(),
436+
tcp_user_timeout: Self::default_tcp_user_timeout(),
430437
log_client_connections: false,
431438
log_client_disconnections: false,
432439
autoreload: None,

src/messages.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,13 @@ pub fn configure_socket(stream: &TcpStream) {
669669
let sock_ref = SockRef::from(stream);
670670
let conf = get_config();
671671

672+
#[cfg(target_os = "linux")]
673+
match sock_ref.set_tcp_user_timeout(Some(Duration::from_millis(conf.general.tcp_user_timeout)))
674+
{
675+
Ok(_) => (),
676+
Err(err) => error!("Could not configure tcp_user_timeout for socket: {}", err),
677+
}
678+
672679
match sock_ref.set_keepalive(true) {
673680
Ok(_) => {
674681
match sock_ref.set_tcp_keepalive(
@@ -678,7 +685,7 @@ pub fn configure_socket(stream: &TcpStream) {
678685
.with_time(Duration::from_secs(conf.general.tcp_keepalives_idle)),
679686
) {
680687
Ok(_) => (),
681-
Err(err) => error!("Could not configure socket: {}", err),
688+
Err(err) => error!("Could not configure tcp_keepalive for socket: {}", err),
682689
}
683690
}
684691
Err(err) => error!("Could not configure socket: {}", err),

0 commit comments

Comments
 (0)