about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-05-06 22:01:43 -0700
committerbors <bors@rust-lang.org>2014-05-06 22:01:43 -0700
commit2dcbad5bc40b3ef7d1150db12fba1d653b1c3b16 (patch)
treecd27bb3c9cf0f6d120c225c213c4cec68698b740 /src/libstd
parent24f6f26e633e50b5b59f9d0f6cca0b1e49e215d9 (diff)
parent022a01d40c7fd9693f1b10607912605a6fc898b8 (diff)
downloadrust-2dcbad5bc40b3ef7d1150db12fba1d653b1c3b16.tar.gz
rust-2dcbad5bc40b3ef7d1150db12fba1d653b1c3b16.zip
auto merge of #13754 : alexcrichton/rust/net-experimental, r=brson
The underlying I/O objects implement a good deal of various options here and
there for tuning network sockets and how they perform. Most of this is a relic
of "whatever libuv provides", but these options are genuinely useful.

It is unclear at this time whether these options should be well supported or
not, or whether they have correct names or not. For now, I believe it's better
to expose the functionality than to not, but all new methods are added with
an #[experimental] annotation.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/net/tcp.rs23
-rw-r--r--src/libstd/io/net/udp.rs48
2 files changed, 70 insertions, 1 deletions
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs
index 0619c89aac1..c6a8702b674 100644
--- a/src/libstd/io/net/tcp.rs
+++ b/src/libstd/io/net/tcp.rs
@@ -85,6 +85,29 @@ impl TcpStream {
     pub fn socket_name(&mut self) -> IoResult<SocketAddr> {
         self.obj.socket_name()
     }
+
+    /// Sets the nodelay flag on this connection to the boolean specified
+    #[experimental]
+    pub fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> {
+        if nodelay {
+            self.obj.nodelay()
+        } else {
+            self.obj.control_congestion()
+        }
+    }
+
+    /// Sets the keepalive timeout to the timeout specified.
+    ///
+    /// If the value specified is `None`, then the keepalive flag is cleared on
+    /// this connection. Otherwise, the keepalive timeout will be set to the
+    /// specified time, in seconds.
+    #[experimental]
+    pub fn set_keepalive(&mut self, delay_in_seconds: Option<uint>) -> IoResult<()> {
+        match delay_in_seconds {
+            Some(i) => self.obj.keepalive(i),
+            None => self.obj.letdie(),
+        }
+    }
 }
 
 impl Clone for TcpStream {
diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs
index 184069bab33..a9708ed5fa1 100644
--- a/src/libstd/io/net/udp.rs
+++ b/src/libstd/io/net/udp.rs
@@ -16,7 +16,7 @@
 //! datagram protocol.
 
 use clone::Clone;
-use io::net::ip::SocketAddr;
+use io::net::ip::{SocketAddr, IpAddr};
 use io::{Reader, Writer, IoResult};
 use kinds::Send;
 use result::{Ok, Err};
@@ -95,6 +95,52 @@ impl UdpSocket {
     pub fn socket_name(&mut self) -> IoResult<SocketAddr> {
         self.obj.socket_name()
     }
+
+    /// Joins a multicast IP address (becomes a member of it)
+    #[experimental]
+    pub fn join_multicast(&mut self, multi: IpAddr) -> IoResult<()> {
+        self.obj.join_multicast(multi)
+    }
+
+    /// Leaves a multicast IP address (drops membership from it)
+    #[experimental]
+    pub fn leave_multicast(&mut self, multi: IpAddr) -> IoResult<()> {
+        self.obj.leave_multicast(multi)
+    }
+
+    /// Set the multicast loop flag to the specified value
+    ///
+    /// This lets multicast packets loop back to local sockets (if enabled)
+    #[experimental]
+    pub fn set_multicast_loop(&mut self, on: bool) -> IoResult<()> {
+        if on {
+            self.obj.loop_multicast_locally()
+        } else {
+            self.obj.dont_loop_multicast_locally()
+        }
+    }
+
+    /// Sets the multicast TTL
+    #[experimental]
+    pub fn set_multicast_ttl(&mut self, ttl: int) -> IoResult<()> {
+        self.obj.multicast_time_to_live(ttl)
+    }
+
+    /// Sets this socket's TTL
+    #[experimental]
+    pub fn set_ttl(&mut self, ttl: int) -> IoResult<()> {
+        self.obj.time_to_live(ttl)
+    }
+
+    /// Sets the broadcast flag on or off
+    #[experimental]
+    pub fn set_broadast(&mut self, broadcast: bool) -> IoResult<()> {
+        if broadcast {
+            self.obj.hear_broadcasts()
+        } else {
+            self.obj.ignore_broadcasts()
+        }
+    }
 }
 
 impl Clone for UdpSocket {