fix: enable compilation on OpenBSD by removing keepalive interval (fix #1413) (#1453)

This fixes #1413 by conditionally compiling the section that sets a keepalive interval, which isn't supported on OpenBSD.

Tested on OpenBSD 7.8

Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1453
Reviewed-by: Alex <lx@deuxfleurs.fr>
This commit is contained in:
Dave St.Germain
2026-05-14 15:17:20 +00:00
committed by Alex
parent 91573eb028
commit 2bde733e09
+7
View File
@@ -43,6 +43,7 @@ pub(crate) const NETAPP_VERSION_TAG: u64 = 0x6772676e65740010; // grgnet 0x0010
/// Time a connection must be idle before the first keepalive probe is sent.
const TCP_KEEPALIVE_TIME: Duration = Duration::from_secs(30);
/// Interval between keepalive probes after the first.
#[cfg(not(target_os = "openbsd"))]
const TCP_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(10);
/// Timeout for outgoing TCP connection attempts.
@@ -52,9 +53,15 @@ const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
fn set_keepalive(stream: &TcpStream) -> Result<(), std::io::Error> {
let sock_ref = socket2::SockRef::from(stream);
// OpenBSD does not support with_interval method
#[cfg(not(target_os = "openbsd"))]
let keepalive = socket2::TcpKeepalive::new()
.with_time(TCP_KEEPALIVE_TIME)
.with_interval(TCP_KEEPALIVE_INTERVAL);
#[cfg(target_os = "openbsd")]
let keepalive = socket2::TcpKeepalive::new().with_time(TCP_KEEPALIVE_TIME);
sock_ref.set_tcp_keepalive(&keepalive)
}