Skip to content

Fix compilation on Haiku and OpenBSD with --features all #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,11 +1404,22 @@ impl Socket {
impl Socket {
/// Get the value of the `TCP_KEEPIDLE` option on this socket.
///
/// This returns the value of `SO_KEEPALIVE` on OpenBSD and Haiku,
/// `TCP_KEEPALIVE` on macOS and iOS, and `TCP_KEEPIDLE` on all other Unix
/// operating systems.
#[cfg(any(doc, all(feature = "all", not(windows))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", not(windows)))))]
/// This returns the value of `TCP_KEEPALIVE` on macOS and iOS and `TCP_KEEPIDLE` on all other
/// supported Unix operating systems.
#[cfg(any(
doc,
all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
)
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
)))
)]
pub fn keepalive_time(&self) -> io::Result<Duration> {
sys::keepalive_time(self.as_raw())
}
Expand Down
1 change: 1 addition & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
}

#[cfg(feature = "all")]
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
unsafe {
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)
Expand Down
5 changes: 4 additions & 1 deletion tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,10 @@ fn tcp_keepalive() {
// Set the parameters.
socket.set_tcp_keepalive(&params).unwrap();

#[cfg(all(feature = "all", not(windows)))]
#[cfg(all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
))]
assert_eq!(socket.keepalive_time().unwrap(), Duration::from_secs(200));

#[cfg(all(
Expand Down