Skip to content

Commit cddb67b

Browse files
link2xtThomasdezeeuw
authored andcommitted
Fix compilation on Haiku and OpenBSD with --features all
`keepalive_time()` is not available on these platforms
1 parent 877a789 commit cddb67b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/socket.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,11 +1404,22 @@ impl Socket {
14041404
impl Socket {
14051405
/// Get the value of the `TCP_KEEPIDLE` option on this socket.
14061406
///
1407-
/// This returns the value of `SO_KEEPALIVE` on OpenBSD and Haiku,
1408-
/// `TCP_KEEPALIVE` on macOS and iOS, and `TCP_KEEPIDLE` on all other Unix
1409-
/// operating systems.
1410-
#[cfg(any(doc, all(feature = "all", not(windows))))]
1411-
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", not(windows)))))]
1407+
/// This returns the value of `TCP_KEEPALIVE` on macOS and iOS and `TCP_KEEPIDLE` on all other
1408+
/// supported Unix operating systems.
1409+
#[cfg(any(
1410+
doc,
1411+
all(
1412+
feature = "all",
1413+
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1414+
)
1415+
))]
1416+
#[cfg_attr(
1417+
docsrs,
1418+
doc(cfg(all(
1419+
feature = "all",
1420+
not(any(windows, target_os = "haiku", target_os = "openbsd"))
1421+
)))
1422+
)]
14121423
pub fn keepalive_time(&self) -> io::Result<Duration> {
14131424
sys::keepalive_time(self.as_raw())
14141425
}

src/sys/unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
866866
}
867867

868868
#[cfg(feature = "all")]
869+
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
869870
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
870871
unsafe {
871872
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)

tests/socket.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,10 @@ fn tcp_keepalive() {
729729
// Set the parameters.
730730
socket.set_tcp_keepalive(&params).unwrap();
731731

732-
#[cfg(all(feature = "all", not(windows)))]
732+
#[cfg(all(
733+
feature = "all",
734+
not(any(windows, target_os = "haiku", target_os = "openbsd"))
735+
))]
733736
assert_eq!(socket.keepalive_time().unwrap(), Duration::from_secs(200));
734737

735738
#[cfg(all(

0 commit comments

Comments
 (0)