|
16 | 16 | //! datagram protocol.
|
17 | 17 |
|
18 | 18 | use clone::Clone;
|
19 |
| -use io::net::ip::SocketAddr; |
| 19 | +use io::net::ip::{SocketAddr, IpAddr}; |
20 | 20 | use io::{Reader, Writer, IoResult};
|
21 | 21 | use kinds::Send;
|
22 | 22 | use result::{Ok, Err};
|
@@ -95,6 +95,52 @@ impl UdpSocket {
|
95 | 95 | pub fn socket_name(&mut self) -> IoResult<SocketAddr> {
|
96 | 96 | self.obj.socket_name()
|
97 | 97 | }
|
| 98 | + |
| 99 | + /// Joins a multicast IP address (becomes a member of it) |
| 100 | + #[experimental] |
| 101 | + pub fn join_multicast(&mut self, multi: IpAddr) -> IoResult<()> { |
| 102 | + self.obj.join_multicast(multi) |
| 103 | + } |
| 104 | + |
| 105 | + /// Leaves a multicast IP address (drops membership from it) |
| 106 | + #[experimental] |
| 107 | + pub fn leave_multicast(&mut self, multi: IpAddr) -> IoResult<()> { |
| 108 | + self.obj.leave_multicast(multi) |
| 109 | + } |
| 110 | + |
| 111 | + /// Set the multicast loop flag to the specified value |
| 112 | + /// |
| 113 | + /// This lets multicast packets loop back to local sockets (if enabled) |
| 114 | + #[experimental] |
| 115 | + pub fn set_multicast_loop(&mut self, on: bool) -> IoResult<()> { |
| 116 | + if on { |
| 117 | + self.obj.loop_multicast_locally() |
| 118 | + } else { |
| 119 | + self.obj.dont_loop_multicast_locally() |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + /// Sets the multicast TTL |
| 124 | + #[experimental] |
| 125 | + pub fn set_multicast_ttl(&mut self, ttl: int) -> IoResult<()> { |
| 126 | + self.obj.multicast_time_to_live(ttl) |
| 127 | + } |
| 128 | + |
| 129 | + /// Sets this socket's TTL |
| 130 | + #[experimental] |
| 131 | + pub fn set_ttl(&mut self, ttl: int) -> IoResult<()> { |
| 132 | + self.obj.time_to_live(ttl) |
| 133 | + } |
| 134 | + |
| 135 | + /// Sets the broadcast flag on or off |
| 136 | + #[experimental] |
| 137 | + pub fn set_broadast(&mut self, broadcast: bool) -> IoResult<()> { |
| 138 | + if broadcast { |
| 139 | + self.obj.hear_broadcasts() |
| 140 | + } else { |
| 141 | + self.obj.ignore_broadcasts() |
| 142 | + } |
| 143 | + } |
98 | 144 | }
|
99 | 145 |
|
100 | 146 | impl Clone for UdpSocket {
|
|
0 commit comments