[pbs-devel] [PATCH proxmox 05/13] proxmox: takeover socket helper from proxmox_backup

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri May 14 15:44:41 CEST 2021


Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 proxmox/src/sys/linux/mod.rs    |  1 +
 proxmox/src/sys/linux/socket.rs | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 proxmox/src/sys/linux/socket.rs

diff --git a/proxmox/src/sys/linux/mod.rs b/proxmox/src/sys/linux/mod.rs
index ee616a3..ccd710c 100644
--- a/proxmox/src/sys/linux/mod.rs
+++ b/proxmox/src/sys/linux/mod.rs
@@ -6,6 +6,7 @@ pub mod magic;
 pub mod pid;
 pub mod procfs;
 pub mod pty;
+pub mod socket;
 pub mod tty;
 
 /// Get pseudo random data (/dev/urandom)
diff --git a/proxmox/src/sys/linux/socket.rs b/proxmox/src/sys/linux/socket.rs
new file mode 100644
index 0000000..6c63c3c
--- /dev/null
+++ b/proxmox/src/sys/linux/socket.rs
@@ -0,0 +1,21 @@
+use std::os::unix::io::RawFd;
+
+use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle};
+use nix::sys::socket::setsockopt;
+
+/// Set TCP keepalive time on a socket
+///
+/// See "man 7 tcp" for details.
+///
+/// The default on Linux is 7200 (2 hours) which is far too long for
+/// many of our use cases.
+pub fn set_tcp_keepalive(
+    socket_fd: RawFd,
+    tcp_keepalive_time: u32,
+) -> nix::Result<()> {
+
+    setsockopt(socket_fd, KeepAlive, &true)?;
+    setsockopt(socket_fd, TcpKeepIdle, &tcp_keepalive_time)?;
+
+    Ok(())
+}
-- 
2.20.1






More information about the pbs-devel mailing list