refactor: move socket helper to proxmox crate

and constant to tools module.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-05-14 15:44:51 +02:00 committed by Dietmar Maurer
parent c474a66b41
commit 3241392117
4 changed files with 8 additions and 32 deletions

View File

@ -11,6 +11,7 @@ use serde_json::Value;
use proxmox::try_block;
use proxmox::api::RpcEnvironmentType;
use proxmox::sys::linux::socket::set_tcp_keepalive;
use proxmox_backup::{
backup::DataStore,
@ -38,6 +39,7 @@ use proxmox_backup::buildcfg;
use proxmox_backup::server;
use proxmox_backup::auth_helpers::*;
use proxmox_backup::tools::{
PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
daemon,
disks::{
DiskManage,
@ -45,10 +47,6 @@ use proxmox_backup::tools::{
get_pool_from_dataset,
},
logrotate::LogRotate,
socket::{
set_tcp_keepalive,
PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
},
};
use proxmox_backup::api2::pull::do_sync_job;

View File

@ -43,7 +43,6 @@ pub mod lru_cache;
pub mod nom;
pub mod runtime;
pub mod serde_filter;
pub mod socket;
pub mod statistics;
pub mod subscription;
pub mod systemd;
@ -483,6 +482,9 @@ impl<T: Any> AsAny for T {
}
}
/// The default 2 hours are far too long for PBS
pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
/// This used to be: `SIMPLE_ENCODE_SET` plus space, `"`, `#`, `<`, `>`, backtick, `?`, `{`, `}`
pub const DEFAULT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS // 0..1f and 7e
// The SIMPLE_ENCODE_SET adds space and anything >= 0x7e (7e itself is already included above)

View File

@ -18,12 +18,11 @@ use tokio::{
};
use tokio_openssl::SslStream;
use proxmox::sys::linux::socket::set_tcp_keepalive;
use crate::tools::{
PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
async_io::MaybeTlsStream,
socket::{
set_tcp_keepalive,
PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
},
};
// Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses

View File

@ -1,23 +0,0 @@
use std::os::unix::io::RawFd;
use nix::sys::socket::sockopt::{KeepAlive, TcpKeepIdle};
use nix::sys::socket::setsockopt;
pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120;
/// 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
/// our backup tools.
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(())
}