Skip to content

Commit

Permalink
fix: Align the cfg compilation with the socket2
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Dec 28, 2024
1 parent dce81a0 commit 9ced5f1
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions src/client/legacy/connect/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,48 +111,55 @@ impl TcpKeepaliveConfig {
}
}

#[cfg(not(any(
target_os = "aix",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris"
)))]
fn ka_with_interval(ka: TcpKeepalive, interval: Duration, dirty: &mut bool) -> TcpKeepalive {
*dirty = true;
ka.with_interval(interval)
}

#[cfg(any(
target_os = "aix",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris"
))]
fn ka_with_interval(ka: TcpKeepalive, _: Duration, _: &mut bool) -> TcpKeepalive {
ka // no-op as keepalive interval is not supported on this platform
if cfg!(
// See https://docs.rs/socket2/0.5.8/src/socket2/lib.rs.html#511-525
any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "ios",
target_os = "visionos",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "windows",
)
) {
*dirty = true;
ka.with_interval(interval)
} else {
ka
}
}

#[cfg(not(any(
target_os = "aix",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "windows"
)))]
fn ka_with_retries(ka: TcpKeepalive, retries: u32, dirty: &mut bool) -> TcpKeepalive {
*dirty = true;
ka.with_retries(retries)
}

#[cfg(any(
target_os = "aix",
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "windows"
))]
fn ka_with_retries(ka: TcpKeepalive, _: u32, _: &mut bool) -> TcpKeepalive {
ka // no-op as keepalive retries is not supported on this platform
if cfg!(
// See https://docs.rs/socket2/0.5.8/src/socket2/lib.rs.html#557-570
any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "ios",
target_os = "visionos",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
)
) {
*dirty = true;
ka.with_retries(retries)
} else {
ka
}
}
}

Expand Down

0 comments on commit 9ced5f1

Please sign in to comment.