Skip to content

std: Add experimental networking methods #13754

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
May 7, 2014
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/libstd/io/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 47 additions & 1 deletion src/libstd/io/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down