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 { 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) -> 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 { 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 {