-
Notifications
You must be signed in to change notification settings - Fork 67
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
OpenBSD: Fix keepalive_ms and set_keepalive_ms. #99
Conversation
I've fixed things up so the |
Will do. Thank you! |
…BSD. OpenBSD (as of release 6.6) does not support the socket option TCP_KEEPIDLE. To be using SO_KEEPALIVE was not correct and was failing at runtime. NetBSD supports the option and it should therefore be treated like generic unix. The use of SO_KEEPALIVE as the KEEPALIVE_OPTION on NetBSD also does not seem to be correct.
@pfmooney: Thank you for the CI fixes! I stacked my patch on top of the new CI checks pass, and the fix worked in my testing in combination with the http client in The test program is the hyper::client example. |
@@ -667,8 +667,9 @@ impl<T: AsRawSocket> AsSock for T { | |||
cfg_if! { | |||
if #[cfg(any(target_os = "macos", target_os = "ios"))] { | |||
use libc::TCP_KEEPALIVE as KEEPALIVE_OPTION; | |||
} else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { | |||
use libc::SO_KEEPALIVE as KEEPALIVE_OPTION; | |||
} else if #[cfg(target_os = "openbsd")] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dropping the netbsd
case. Is it safe to do so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. NetBSD understands TCP_KEEPIDLE
(tcp(4)), the cfg(unix)
case just below this one applies to it correctly.
src/ext.rs
Outdated
@@ -737,7 +738,25 @@ impl TcpStreamExt for TcpStream { | |||
Ok(Some((secs as u32) * 1000)) | |||
} | |||
|
|||
#[cfg(unix)] | |||
#[cfg(target_os = "openbsd")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: Would you mind moving these two function definitions down to after their respective counterparts with the #[cfg(all(unix, not(target_os = "openbsd")))]
gates? I think it would be nice list the specific openbsd
case after the more general unix
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done in f98618d.
OpenBSD (as of release 6.6) does not support the socket option
TCP_KEEPIDLE
(tcp(4)). To be usingSO_KEEPALIVE
instead made it compile but was not correct and was failing at run-time.This pull request fixes #82. That github issue has a good description of the problem.
NetBSD supports the option (tcp(4)) and NetBSD should therefore be treated like generic unix. It therefore also did not seem right to use
SO_KEEPALIVE
as theKEEPALIVE_OPTION
on NetBSD.I have tested the patched
net2
as of f061e5e in combination with the http client inhyper
version=0.12.35
. I have tested on OpenBSD 6.6 amd64 withrustc 1.38.0
, on Linux x86_64 withrustc 1.43.1
and on NetBSD 9.0 amd64 withrustc 1.42.0
.