Skip to content

implement set_tcp_keepalive for linux #24594

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
Apr 24, 2015
Merged
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
8 changes: 6 additions & 2 deletions src/libstd/sys/common/net2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,19 @@ impl TcpStream {
setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE,
seconds as c_int)
}
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "linux"))]
fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just add a target_os to the definition right above, on L205?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

diff --git a/src/libstd/sys/common/net2.rs b/src/libstd/sys/common/net2.rs
index 7d42d65..c6cb673 100644
--- a/src/libstd/sys/common/net2.rs
+++ b/src/libstd/sys/common/net2.rs
@@ -197,18 +197,22 @@ impl TcpStream {
         }
     }

-    #[cfg(any(target_os = "macos", target_os = "ios"))]
+    #[cfg(any(target_os = "macos",
+              target_os = "ios"))]
     fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {
         setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE,
                    seconds as c_int)
     }
-    #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+    #[cfg(any(target_os = "linux",
+              target_os = "freebsd",
+              target_os = "dragonfly"))]
     fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {
         setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
                    seconds as c_int)
     }
     #[cfg(not(any(target_os = "macos",
                   target_os = "ios",
+                  target_os = "linux",
                   target_os = "freebsd",
                   target_os = "dragonfly")))]
     fn set_tcp_keepalive(&self, _seconds: u32) -> io::Result<()> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Duberstein. I'm too busy these days, and even haven't got time
turning on my computer. I'll merge this patch tomorrow.

On 2015年4月22日周三 下午10:13 Tamir Duberstein [email protected] wrote:

In src/libstd/sys/common/net2.rs
#24594 (comment):

@@ -207,10 +207,16 @@ impl TcpStream {
setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
seconds as c_int)
}

  • #[cfg(target_os = "linux")]
  • fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {

[image: 👍]

diff --git a/src/libstd/sys/common/net2.rs b/src/libstd/sys/common/net2.rs
index 7d42d65..c6cb673 100644--- a/src/libstd/sys/common/net2.rs+++ b/src/libstd/sys/common/net2.rs@@ -197,18 +197,22 @@ impl TcpStream {
}
}

  • #[cfg(any(target_os = "macos", target_os = "ios"))]+ #[cfg(any(target_os = "macos",+ target_os = "ios"))]
    fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {
    setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE,
    seconds as c_int)
    }- #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]+ #[cfg(any(target_os = "linux",+ target_os = "freebsd",+ target_os = "dragonfly"))]
    fn set_tcp_keepalive(&self, seconds: u32) -> io::Result<()> {
    setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
    seconds as c_int)
    }
    #[cfg(not(any(target_os = "macos",
    target_os = "ios",+ target_os = "linux",
    target_os = "freebsd",
    target_os = "dragonfly")))]
    fn set_tcp_keepalive(&self, _seconds: u32) -> io::Result<()> {


Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/24594/files#r28875540.

setsockopt(&self.inner, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
seconds as c_int)
}

#[cfg(not(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly")))]
target_os = "dragonfly",
target_os = "linux")))]
fn set_tcp_keepalive(&self, _seconds: u32) -> io::Result<()> {
Ok(())
}
Expand Down