about summary refs log tree commit diff
path: root/src/libstd/sys/unix/net.rs
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2016-02-27 21:05:32 -0800
committerSteven Fackler <sfackler@gmail.com>2016-02-28 09:41:33 -0800
commit728d9115e894bd3c8fc3ae03230ea46f85467c04 (patch)
tree3e5867efbe40eb47af9655ba457137cb1d1f82a1 /src/libstd/sys/unix/net.rs
parent5d6ba17f0308d3b8c96cd89f4c0663bae0f2b9f7 (diff)
downloadrust-728d9115e894bd3c8fc3ae03230ea46f85467c04.tar.gz
rust-728d9115e894bd3c8fc3ae03230ea46f85467c04.zip
Fix windows
Also back out keepalive support for TCP since the API is perhaps not
actually what we want. You can't read the interval on Windows, and
we should probably separate the functionality of turning keepalive on
and overriding the interval.
Diffstat (limited to 'src/libstd/sys/unix/net.rs')
-rw-r--r--src/libstd/sys/unix/net.rs44
1 files changed, 5 insertions, 39 deletions
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 7a2ac7257af..8785da51986 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -35,16 +35,6 @@ use libc::SOCK_CLOEXEC;
 #[cfg(not(target_os = "linux"))]
 const SOCK_CLOEXEC: c_int = 0;
 
-#[cfg(any(target_os = "openbsd", taret_os = "freebsd"))]
-use libc::SO_KEEPALIVE as TCP_KEEPALIVE;
-#[cfg(any(target_os = "macos", taret_os = "ios"))]
-use libc::TCP_KEEPALIVE;
-#[cfg(not(any(target_os = "openbsd",
-              target_os = "freebsd",
-              target_os = "macos",
-              target_os = "ios")))]
-use libc::TCP_KEEPIDLE as TCP_KEEPALIVE;
-
 pub struct Socket(FileDesc);
 
 pub fn init() {}
@@ -179,37 +169,13 @@ impl Socket {
         Ok(())
     }
 
-    pub fn set_keepalive(&self, keepalive: Option<Duration>) -> io::Result<()> {
-        try!(setsockopt(self,
-                        libc::SOL_SOCKET,
-                        libc::SO_KEEPALIVE,
-                        keepalive.is_some() as libc::c_int));
-        if let Some(dur) = keepalive {
-            let mut raw = dur.as_secs();
-            if dur.subsec_nanos() > 0 {
-                raw = raw.saturating_add(1);
-            }
-
-            let raw = if raw > libc::c_int::max_value() as u64 {
-                libc::c_int::max_value()
-            } else {
-                raw as libc::c_int
-            };
-
-            try!(setsockopt(self, libc::IPPROTO_TCP, TCP_KEEPALIVE, raw));
-        }
-
-        Ok(())
+    pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
+        setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int)
     }
 
-    pub fn keepalive(&self) -> io::Result<Option<Duration>> {
-        let raw: c_int = try!(getsockopt(self, libc::SOL_SOCKET, libc::SO_KEEPALIVE));
-        if raw == 0 {
-            return Ok(None);
-        }
-
-        let raw: c_int = try!(getsockopt(self, libc::IPPROTO_TCP, TCP_KEEPALIVE));
-        Ok(Some(Duration::from_secs(raw as u64)))
+    pub fn nodelay(&self) -> io::Result<bool> {
+        let raw: c_int = try!(getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY));
+        Ok(raw != 0)
     }
 
     pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {