2013-04-17 17:55:21 -07:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-02-24 00:31:08 -08:00
|
|
|
#[allow(missing_doc)];
|
|
|
|
|
2014-01-22 19:32:16 -08:00
|
|
|
use clone::Clone;
|
2013-06-19 17:23:55 -07:00
|
|
|
use result::{Ok, Err};
|
2013-11-10 22:46:32 -08:00
|
|
|
use io::net::ip::SocketAddr;
|
2014-01-29 16:33:57 -08:00
|
|
|
use io::{Reader, Writer, IoResult};
|
2013-12-05 17:25:48 -08:00
|
|
|
use rt::rtio::{RtioSocket, RtioUdpSocket, IoFactory, LocalIo};
|
2013-06-19 17:23:55 -07:00
|
|
|
|
2013-10-02 18:52:03 -07:00
|
|
|
pub struct UdpSocket {
|
2013-10-16 14:48:05 -07:00
|
|
|
priv obj: ~RtioUdpSocket
|
2013-10-02 18:52:03 -07:00
|
|
|
}
|
2013-06-19 17:23:55 -07:00
|
|
|
|
|
|
|
impl UdpSocket {
|
2014-01-29 16:33:57 -08:00
|
|
|
pub fn bind(addr: SocketAddr) -> IoResult<UdpSocket> {
|
2013-12-12 17:30:41 -08:00
|
|
|
LocalIo::maybe_raise(|io| {
|
|
|
|
io.udp_bind(addr).map(|s| UdpSocket { obj: s })
|
|
|
|
})
|
2013-06-19 17:23:55 -07:00
|
|
|
}
|
|
|
|
|
2014-01-29 16:33:57 -08:00
|
|
|
pub fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, SocketAddr)> {
|
|
|
|
self.obj.recvfrom(buf)
|
2013-06-19 17:23:55 -07:00
|
|
|
}
|
|
|
|
|
2014-01-29 16:33:57 -08:00
|
|
|
pub fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> IoResult<()> {
|
|
|
|
self.obj.sendto(buf, dst)
|
2013-06-19 17:23:55 -07:00
|
|
|
}
|
|
|
|
|
2013-08-03 02:06:24 +04:00
|
|
|
pub fn connect(self, other: SocketAddr) -> UdpStream {
|
2013-06-19 17:23:55 -07:00
|
|
|
UdpStream { socket: self, connectedTo: other }
|
|
|
|
}
|
2013-07-25 02:33:43 -04:00
|
|
|
|
2014-01-29 16:33:57 -08:00
|
|
|
pub fn socket_name(&mut self) -> IoResult<SocketAddr> {
|
|
|
|
self.obj.socket_name()
|
2013-07-25 02:33:43 -04:00
|
|
|
}
|
2013-06-19 17:23:55 -07:00
|
|
|
}
|
2013-04-17 17:55:21 -07:00
|
|
|
|
2014-01-22 19:32:16 -08:00
|
|
|
impl Clone for UdpSocket {
|
|
|
|
/// Creates a new handle to this UDP socket, allowing for simultaneous reads
|
|
|
|
/// and writes of the socket.
|
|
|
|
///
|
|
|
|
/// The underlying UDP socket will not be closed until all handles to the
|
|
|
|
/// socket have been deallocated. Two concurrent reads will not receive the
|
|
|
|
/// same data. Instead, the first read will receive the first packet
|
|
|
|
/// received, and the second read will receive the second packet.
|
|
|
|
fn clone(&self) -> UdpSocket {
|
|
|
|
UdpSocket { obj: self.obj.clone() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 12:34:58 -07:00
|
|
|
pub struct UdpStream {
|
2013-10-02 18:52:03 -07:00
|
|
|
priv socket: UdpSocket,
|
|
|
|
priv connectedTo: SocketAddr
|
2013-06-17 12:34:58 -07:00
|
|
|
}
|
2013-04-17 17:55:21 -07:00
|
|
|
|
|
|
|
impl UdpStream {
|
2013-11-18 21:15:42 -08:00
|
|
|
pub fn as_socket<T>(&mut self, f: |&mut UdpSocket| -> T) -> T {
|
|
|
|
f(&mut self.socket)
|
|
|
|
}
|
2013-06-17 12:34:58 -07:00
|
|
|
|
2013-06-25 17:05:59 -07:00
|
|
|
pub fn disconnect(self) -> UdpSocket { self.socket }
|
2013-04-17 17:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Reader for UdpStream {
|
2014-01-29 16:33:57 -08:00
|
|
|
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
|
2013-07-17 15:16:44 -07:00
|
|
|
let peer = self.connectedTo;
|
2013-11-20 14:17:12 -08:00
|
|
|
self.as_socket(|sock| {
|
2013-06-25 11:43:40 -07:00
|
|
|
match sock.recvfrom(buf) {
|
2014-01-29 16:33:57 -08:00
|
|
|
Ok((_nread, src)) if src != peer => Ok(0),
|
|
|
|
Ok((nread, _src)) => Ok(nread),
|
|
|
|
Err(e) => Err(e),
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2013-11-20 14:17:12 -08:00
|
|
|
})
|
2013-06-19 17:23:55 -07:00
|
|
|
}
|
2013-04-17 17:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Writer for UdpStream {
|
2014-01-29 16:33:57 -08:00
|
|
|
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
2014-02-15 16:15:03 -05:00
|
|
|
let connected_to = self.connectedTo;
|
|
|
|
self.as_socket(|sock| sock.sendto(buf, connected_to))
|
2013-04-17 17:55:21 -07:00
|
|
|
}
|
|
|
|
}
|
2013-06-25 11:43:40 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2014-01-05 13:05:02 -05:00
|
|
|
use io::net::ip::{SocketAddr};
|
2013-06-25 11:43:40 -07:00
|
|
|
|
2014-01-13 19:45:08 -08:00
|
|
|
// FIXME #11530 this fails on android because tests are run as root
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn bind_error() {
|
2014-01-30 14:10:53 -08:00
|
|
|
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };
|
|
|
|
match UdpSocket::bind(addr) {
|
|
|
|
Ok(..) => fail!(),
|
|
|
|
Err(e) => assert_eq!(e.kind, PermissionDenied),
|
|
|
|
}
|
2014-01-13 19:45:08 -08:00
|
|
|
} #[ignore(cfg(windows))] #[ignore(cfg(target_os = "android"))])
|
2013-06-25 11:43:40 -07:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn socket_smoke_test_ip4() {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server_ip = next_test_ip4();
|
|
|
|
let client_ip = next_test_ip4();
|
2013-12-12 21:38:57 -08:00
|
|
|
let (port, chan) = Chan::new();
|
2013-12-28 16:40:15 -08:00
|
|
|
let (port2, chan2) = Chan::new();
|
2013-06-25 11:43:40 -07:00
|
|
|
|
2014-01-26 22:42:26 -05:00
|
|
|
spawn(proc() {
|
2013-12-05 18:19:06 -08:00
|
|
|
match UdpSocket::bind(client_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(ref mut client) => {
|
2013-12-05 18:19:06 -08:00
|
|
|
port.recv();
|
2014-01-30 14:10:53 -08:00
|
|
|
client.sendto([99], server_ip).unwrap()
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
chan2.send(());
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-06-25 11:43:40 -07:00
|
|
|
|
2013-12-12 17:20:58 -08:00
|
|
|
match UdpSocket::bind(server_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(ref mut server) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
chan.send(());
|
|
|
|
let mut buf = [0];
|
|
|
|
match server.recvfrom(buf) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok((nread, src)) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
assert_eq!(nread, 1);
|
|
|
|
assert_eq!(buf[0], 99);
|
|
|
|
assert_eq!(src, client_ip);
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-12-12 17:20:58 -08:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
port2.recv();
|
|
|
|
})
|
2013-07-02 16:40:57 -07:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn socket_smoke_test_ip6() {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server_ip = next_test_ip6();
|
|
|
|
let client_ip = next_test_ip6();
|
2013-12-12 21:38:57 -08:00
|
|
|
let (port, chan) = Chan::<()>::new();
|
2013-12-12 17:20:58 -08:00
|
|
|
|
2014-01-26 22:42:26 -05:00
|
|
|
spawn(proc() {
|
2013-12-05 18:19:06 -08:00
|
|
|
match UdpSocket::bind(client_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(ref mut client) => {
|
2013-12-05 18:19:06 -08:00
|
|
|
port.recv();
|
2014-01-30 14:10:53 -08:00
|
|
|
client.sendto([99], server_ip).unwrap()
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-07-02 16:40:57 -07:00
|
|
|
|
2013-12-12 17:20:58 -08:00
|
|
|
match UdpSocket::bind(server_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(ref mut server) => {
|
2013-12-12 21:38:57 -08:00
|
|
|
chan.send(());
|
2013-12-12 17:20:58 -08:00
|
|
|
let mut buf = [0];
|
|
|
|
match server.recvfrom(buf) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok((nread, src)) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
assert_eq!(nread, 1);
|
|
|
|
assert_eq!(buf[0], 99);
|
|
|
|
assert_eq!(src, client_ip);
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-12-12 17:20:58 -08:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
})
|
2013-12-12 17:20:58 -08:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn stream_smoke_test_ip4() {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server_ip = next_test_ip4();
|
|
|
|
let client_ip = next_test_ip4();
|
2013-12-12 21:38:57 -08:00
|
|
|
let (port, chan) = Chan::new();
|
2013-12-28 16:40:15 -08:00
|
|
|
let (port2, chan2) = Chan::new();
|
2013-07-02 16:40:57 -07:00
|
|
|
|
2014-01-26 22:42:26 -05:00
|
|
|
spawn(proc() {
|
2013-12-05 18:19:06 -08:00
|
|
|
match UdpSocket::bind(client_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(client) => {
|
2013-12-05 18:19:06 -08:00
|
|
|
let client = ~client;
|
|
|
|
let mut stream = client.connect(server_ip);
|
|
|
|
port.recv();
|
2014-01-30 14:10:53 -08:00
|
|
|
stream.write([99]).unwrap();
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-07-02 16:40:57 -07:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
chan2.send(());
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-07-02 16:40:57 -07:00
|
|
|
|
2013-12-12 17:20:58 -08:00
|
|
|
match UdpSocket::bind(server_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(server) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server = ~server;
|
|
|
|
let mut stream = server.connect(client_ip);
|
|
|
|
chan.send(());
|
|
|
|
let mut buf = [0];
|
|
|
|
match stream.read(buf) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(nread) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
assert_eq!(nread, 1);
|
|
|
|
assert_eq!(buf[0], 99);
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-12-12 17:20:58 -08:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
port2.recv();
|
|
|
|
})
|
2013-12-12 17:20:58 -08:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn stream_smoke_test_ip6() {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server_ip = next_test_ip6();
|
|
|
|
let client_ip = next_test_ip6();
|
2013-12-12 21:38:57 -08:00
|
|
|
let (port, chan) = Chan::new();
|
2013-12-28 16:40:15 -08:00
|
|
|
let (port2, chan2) = Chan::new();
|
2013-06-25 11:43:40 -07:00
|
|
|
|
2014-01-26 22:42:26 -05:00
|
|
|
spawn(proc() {
|
2013-12-05 18:19:06 -08:00
|
|
|
match UdpSocket::bind(client_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(client) => {
|
2013-12-05 18:19:06 -08:00
|
|
|
let client = ~client;
|
|
|
|
let mut stream = client.connect(server_ip);
|
|
|
|
port.recv();
|
2014-01-30 14:10:53 -08:00
|
|
|
stream.write([99]).unwrap();
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
chan2.send(());
|
2014-01-26 22:42:26 -05:00
|
|
|
});
|
2013-12-12 17:20:58 -08:00
|
|
|
|
|
|
|
match UdpSocket::bind(server_ip) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(server) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server = ~server;
|
|
|
|
let mut stream = server.connect(client_ip);
|
|
|
|
chan.send(());
|
|
|
|
let mut buf = [0];
|
|
|
|
match stream.read(buf) {
|
2014-01-30 14:10:53 -08:00
|
|
|
Ok(nread) => {
|
2013-12-12 17:20:58 -08:00
|
|
|
assert_eq!(nread, 1);
|
|
|
|
assert_eq!(buf[0], 99);
|
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-12-12 17:20:58 -08:00
|
|
|
}
|
|
|
|
}
|
2014-01-30 14:10:53 -08:00
|
|
|
Err(..) => fail!()
|
2013-12-12 17:20:58 -08:00
|
|
|
}
|
2013-12-28 16:40:15 -08:00
|
|
|
port2.recv();
|
|
|
|
})
|
2013-07-26 05:02:53 -04:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
pub fn socket_name(addr: SocketAddr) {
|
2013-12-12 17:20:58 -08:00
|
|
|
let server = UdpSocket::bind(addr);
|
2013-07-26 05:02:53 -04:00
|
|
|
|
2014-01-30 14:10:53 -08:00
|
|
|
assert!(server.is_ok());
|
2013-12-12 17:20:58 -08:00
|
|
|
let mut server = server.unwrap();
|
2013-07-26 05:02:53 -04:00
|
|
|
|
2013-12-12 17:20:58 -08:00
|
|
|
// Make sure socket_name gives
|
|
|
|
// us the socket we binded to.
|
|
|
|
let so_name = server.socket_name();
|
2014-01-30 14:10:53 -08:00
|
|
|
assert!(so_name.is_ok());
|
2013-12-12 17:20:58 -08:00
|
|
|
assert_eq!(addr, so_name.unwrap());
|
2013-07-26 05:02:53 -04:00
|
|
|
}
|
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn socket_name_ip4() {
|
2013-07-26 05:02:53 -04:00
|
|
|
socket_name(next_test_ip4());
|
2013-12-28 16:40:15 -08:00
|
|
|
})
|
2013-07-26 05:02:53 -04:00
|
|
|
|
2013-12-28 16:40:15 -08:00
|
|
|
iotest!(fn socket_name_ip6() {
|
2013-07-26 05:02:53 -04:00
|
|
|
socket_name(next_test_ip6());
|
2013-12-28 16:40:15 -08:00
|
|
|
})
|
2014-01-22 19:32:16 -08:00
|
|
|
|
|
|
|
iotest!(fn udp_clone_smoke() {
|
|
|
|
let addr1 = next_test_ip4();
|
|
|
|
let addr2 = next_test_ip4();
|
|
|
|
let mut sock1 = UdpSocket::bind(addr1).unwrap();
|
|
|
|
let sock2 = UdpSocket::bind(addr2).unwrap();
|
|
|
|
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock2 = sock2;
|
|
|
|
let mut buf = [0, 0];
|
|
|
|
assert_eq!(sock2.recvfrom(buf), Ok((1, addr1)));
|
|
|
|
assert_eq!(buf[0], 1);
|
|
|
|
sock2.sendto([2], addr1).unwrap();
|
|
|
|
});
|
|
|
|
|
|
|
|
let sock3 = sock1.clone();
|
|
|
|
|
|
|
|
let (p1, c1) = Chan::new();
|
|
|
|
let (p2, c2) = Chan::new();
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock3 = sock3;
|
|
|
|
p1.recv();
|
|
|
|
sock3.sendto([1], addr2).unwrap();
|
|
|
|
c2.send(());
|
|
|
|
});
|
|
|
|
c1.send(());
|
|
|
|
let mut buf = [0, 0];
|
|
|
|
assert_eq!(sock1.recvfrom(buf), Ok((1, addr2)));
|
|
|
|
p2.recv();
|
|
|
|
})
|
|
|
|
|
|
|
|
iotest!(fn udp_clone_two_read() {
|
|
|
|
let addr1 = next_test_ip4();
|
|
|
|
let addr2 = next_test_ip4();
|
|
|
|
let mut sock1 = UdpSocket::bind(addr1).unwrap();
|
|
|
|
let sock2 = UdpSocket::bind(addr2).unwrap();
|
2014-02-11 16:33:34 -08:00
|
|
|
let (p, c) = Chan::new();
|
2014-01-22 19:32:16 -08:00
|
|
|
let c2 = c.clone();
|
|
|
|
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock2 = sock2;
|
|
|
|
sock2.sendto([1], addr1).unwrap();
|
|
|
|
p.recv();
|
|
|
|
sock2.sendto([2], addr1).unwrap();
|
|
|
|
p.recv();
|
|
|
|
});
|
|
|
|
|
|
|
|
let sock3 = sock1.clone();
|
|
|
|
|
|
|
|
let (p, done) = Chan::new();
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock3 = sock3;
|
|
|
|
let mut buf = [0, 0];
|
|
|
|
sock3.recvfrom(buf).unwrap();
|
|
|
|
c2.send(());
|
|
|
|
done.send(());
|
|
|
|
});
|
|
|
|
let mut buf = [0, 0];
|
|
|
|
sock1.recvfrom(buf).unwrap();
|
|
|
|
c.send(());
|
|
|
|
|
|
|
|
p.recv();
|
|
|
|
})
|
|
|
|
|
|
|
|
iotest!(fn udp_clone_two_write() {
|
|
|
|
let addr1 = next_test_ip4();
|
|
|
|
let addr2 = next_test_ip4();
|
|
|
|
let mut sock1 = UdpSocket::bind(addr1).unwrap();
|
|
|
|
let sock2 = UdpSocket::bind(addr2).unwrap();
|
|
|
|
|
2014-02-11 16:33:34 -08:00
|
|
|
let (p, c) = Chan::new();
|
2014-02-05 16:09:59 -08:00
|
|
|
let (serv_port, serv_chan) = Chan::new();
|
2014-01-22 19:32:16 -08:00
|
|
|
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock2 = sock2;
|
|
|
|
let mut buf = [0, 1];
|
|
|
|
|
2014-02-05 16:09:59 -08:00
|
|
|
p.recv();
|
|
|
|
match sock2.recvfrom(buf) {
|
|
|
|
Ok(..) => {}
|
|
|
|
Err(e) => fail!("failed receive: {}", e),
|
2014-01-22 19:32:16 -08:00
|
|
|
}
|
2014-02-05 16:09:59 -08:00
|
|
|
serv_chan.send(());
|
2014-01-22 19:32:16 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
let sock3 = sock1.clone();
|
|
|
|
|
|
|
|
let (p, done) = Chan::new();
|
|
|
|
let c2 = c.clone();
|
|
|
|
spawn(proc() {
|
|
|
|
let mut sock3 = sock3;
|
|
|
|
match sock3.sendto([1], addr2) {
|
2014-02-05 16:09:59 -08:00
|
|
|
Ok(..) => { let _ = c2.try_send(()); }
|
2014-01-22 19:32:16 -08:00
|
|
|
Err(..) => {}
|
|
|
|
}
|
|
|
|
done.send(());
|
|
|
|
});
|
|
|
|
match sock1.sendto([2], addr2) {
|
2014-02-05 16:09:59 -08:00
|
|
|
Ok(..) => { let _ = c.try_send(()); }
|
2014-01-22 19:32:16 -08:00
|
|
|
Err(..) => {}
|
|
|
|
}
|
2014-02-05 16:09:59 -08:00
|
|
|
drop(c);
|
2014-01-22 19:32:16 -08:00
|
|
|
|
|
|
|
p.recv();
|
2014-02-05 16:09:59 -08:00
|
|
|
serv_port.recv();
|
2014-01-22 19:32:16 -08:00
|
|
|
})
|
2013-06-25 11:43:40 -07:00
|
|
|
}
|