proxmox: takeover socket helper from proxmox_backup

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-05-14 15:44:41 +02:00 committed by Dietmar Maurer
parent cbaa3b45bc
commit caef9a3b20
2 changed files with 22 additions and 0 deletions

View File

@ -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)

View File

@ -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(())
}