]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/io/net/tcp.rs
rollup merge of #20273: alexcrichton/second-pass-comm
[rust.git] / src / libstd / io / net / tcp.rs
index 4492e679cd5f1a1425e80f8dbd69fc4b57fa4721..3e59aaa05efd285d8b7f5f3af68273e0d6ac5f37 100644 (file)
@@ -484,14 +484,15 @@ fn as_inner(&self) -> &TcpAcceptorImp {
 mod test {
     use prelude::v1::*;
 
-    use comm::channel;
+    use sync::mpsc::channel;
     use thread::Thread;
     use io::net::tcp::*;
     use io::net::ip::*;
-    use io::{EndOfFile, TimedOut, IoError, ShortWrite, OtherIoError, ConnectionAborted};
-    use io::{ConnectionRefused, ConnectionReset, BrokenPipe, NotConnected};
-    use io::{PermissionDenied, Listener, Acceptor};
     use io::test::*;
+    use io::{EndOfFile, TimedOut, ShortWrite, IoError};
+    use io::{ConnectionRefused, BrokenPipe, ConnectionAborted};
+    use io::{ConnectionReset, NotConnected, PermissionDenied, OtherIoError};
+    use io::{Acceptor, Listener};
 
     // FIXME #11530 this fails on android because tests are run as root
     #[cfg_attr(any(windows, target_os = "android"), ignore)]
@@ -696,11 +697,11 @@ fn write_close_ip4() {
         let (tx, rx) = channel();
         let _t = Thread::spawn(move|| {
             drop(TcpStream::connect(addr));
-            tx.send(());
+            tx.send(()).unwrap();
         });
 
         let mut stream = acceptor.accept();
-        rx.recv();
+        rx.recv().unwrap();
         let buf = [0];
         match stream.write(&buf) {
             Ok(..) => {}
@@ -721,11 +722,11 @@ fn write_close_ip6() {
         let (tx, rx) = channel();
         let _t = Thread::spawn(move|| {
             drop(TcpStream::connect(addr));
-            tx.send(());
+            tx.send(()).unwrap();
         });
 
         let mut stream = acceptor.accept();
-        rx.recv();
+        rx.recv().unwrap();
         let buf = [0];
         match stream.write(&buf) {
             Ok(..) => {}
@@ -971,20 +972,20 @@ fn partial_read() {
         let (tx, rx) = channel();
         let _t = Thread::spawn(move|| {
             let mut srv = TcpListener::bind(addr).listen().unwrap();
-            tx.send(());
+            tx.send(()).unwrap();
             let mut cl = srv.accept().unwrap();
             cl.write(&[10]).unwrap();
             let mut b = [0];
             cl.read(&mut b).unwrap();
-            tx.send(());
+            tx.send(()).unwrap();
         });
 
-        rx.recv();
+        rx.recv().unwrap();
         let mut c = TcpStream::connect(addr).unwrap();
         let mut b = [0; 10];
         assert_eq!(c.read(&mut b), Ok(1));
         c.write(&[1]).unwrap();
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -1007,19 +1008,19 @@ fn fast_rebind() {
         let (tx, rx) = channel();
 
         let _t = Thread::spawn(move|| {
-            rx.recv();
+            rx.recv().unwrap();
             let _stream = TcpStream::connect(addr).unwrap();
             // Close
-            rx.recv();
+            rx.recv().unwrap();
         });
 
         {
             let mut acceptor = TcpListener::bind(addr).listen();
-            tx.send(());
+            tx.send(()).unwrap();
             {
                 let _stream = acceptor.accept().unwrap();
                 // Close client
-                tx.send(());
+                tx.send(()).unwrap();
             }
             // Close listener
         }
@@ -1046,14 +1047,14 @@ fn tcp_clone_smoke() {
         let (tx2, rx2) = channel();
         let _t = Thread::spawn(move|| {
             let mut s2 = s2;
-            rx1.recv();
+            rx1.recv().unwrap();
             s2.write(&[1]).unwrap();
-            tx2.send(());
+            tx2.send(()).unwrap();
         });
-        tx1.send(());
+        tx1.send(()).unwrap();
         let mut buf = [0, 0];
         assert_eq!(s1.read(&mut buf), Ok(1));
-        rx2.recv();
+        rx2.recv().unwrap();
     }
 
     #[test]
@@ -1066,9 +1067,9 @@ fn tcp_clone_two_read() {
         let _t = Thread::spawn(move|| {
             let mut s = TcpStream::connect(addr);
             s.write(&[1]).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             s.write(&[2]).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
         });
 
         let mut s1 = acceptor.accept().unwrap();
@@ -1079,14 +1080,14 @@ fn tcp_clone_two_read() {
             let mut s2 = s2;
             let mut buf = [0, 0];
             s2.read(&mut buf).unwrap();
-            tx2.send(());
-            done.send(());
+            tx2.send(()).unwrap();
+            done.send(()).unwrap();
         });
         let mut buf = [0, 0];
         s1.read(&mut buf).unwrap();
-        tx1.send(());
+        tx1.send(()).unwrap();
 
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -1108,11 +1109,11 @@ fn tcp_clone_two_write() {
         let _t = Thread::spawn(move|| {
             let mut s2 = s2;
             s2.write(&[1]).unwrap();
-            done.send(());
+            done.send(()).unwrap();
         });
         s1.write(&[2]).unwrap();
 
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -1154,9 +1155,9 @@ fn accept_timeout() {
         if !cfg!(target_os = "freebsd") {
             let (tx, rx) = channel();
             let _t = Thread::spawn(move|| {
-                tx.send(TcpStream::connect(addr).unwrap());
+                tx.send(TcpStream::connect(addr).unwrap()).unwrap();
             });
-            let _l = rx.recv();
+            let _l = rx.recv().unwrap();
             for i in range(0i, 1001) {
                 match a.accept() {
                     Ok(..) => break,
@@ -1184,7 +1185,7 @@ fn close_readwrite_smoke() {
         Thread::spawn(move|| {
             let mut a = a;
             let _s = a.accept().unwrap();
-            let _ = rx.recv_opt();
+            let _ = rx.recv().unwrap();
         }).detach();
 
         let mut b = [0];
@@ -1221,7 +1222,7 @@ fn close_read_wakes_up() {
         Thread::spawn(move|| {
             let mut a = a;
             let _s = a.accept().unwrap();
-            let _ = rx.recv_opt();
+            let _ = rx.recv().unwrap();
         }).detach();
 
         let mut s = TcpStream::connect(addr).unwrap();
@@ -1230,13 +1231,13 @@ fn close_read_wakes_up() {
         let _t = Thread::spawn(move|| {
             let mut s2 = s2;
             assert!(s2.read(&mut [0]).is_err());
-            tx.send(());
+            tx.send(()).unwrap();
         });
         // this should wake up the child task
         s.close_read().unwrap();
 
         // this test will never finish if the child doesn't wake up
-        rx.recv();
+        rx.recv().unwrap();
     }
 
     #[test]
@@ -1246,9 +1247,9 @@ fn readwrite_timeouts() {
         let (tx, rx) = channel::<()>();
         Thread::spawn(move|| {
             let mut s = TcpStream::connect(addr).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
-            let _ = rx.recv_opt();
+            let _ = rx.recv();
         }).detach();
 
         let mut s = a.accept().unwrap();
@@ -1267,7 +1268,7 @@ fn readwrite_timeouts() {
         }
         assert_eq!(s.write(&[0]).err().unwrap().kind, TimedOut);
 
-        tx.send(());
+        tx.send(()).unwrap();
         s.set_timeout(None);
         assert_eq!(s.read(&mut [0, 0]), Ok(1));
     }
@@ -1279,7 +1280,7 @@ fn read_timeouts() {
         let (tx, rx) = channel::<()>();
         Thread::spawn(move|| {
             let mut s = TcpStream::connect(addr).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             let mut amt = 0;
             while amt < 100 * 128 * 1024 {
                 match s.read(&mut [0;128 * 1024]) {
@@ -1287,7 +1288,7 @@ fn read_timeouts() {
                     Err(e) => panic!("{}", e),
                 }
             }
-            let _ = rx.recv_opt();
+            let _ = rx.recv();
         }).detach();
 
         let mut s = a.accept().unwrap();
@@ -1295,7 +1296,7 @@ fn read_timeouts() {
         assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
         assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
 
-        tx.send(());
+        tx.send(()).unwrap();
         for _ in range(0i, 100) {
             assert!(s.write(&[0;128 * 1024]).is_ok());
         }
@@ -1308,9 +1309,9 @@ fn write_timeouts() {
         let (tx, rx) = channel::<()>();
         Thread::spawn(move|| {
             let mut s = TcpStream::connect(addr).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             assert!(s.write(&[0]).is_ok());
-            let _ = rx.recv_opt();
+            let _ = rx.recv();
         }).detach();
 
         let mut s = a.accept().unwrap();
@@ -1325,7 +1326,7 @@ fn write_timeouts() {
         }
         assert_eq!(s.write(&[0]).err().unwrap().kind, TimedOut);
 
-        tx.send(());
+        tx.send(()).unwrap();
         assert!(s.read(&mut [0]).is_ok());
     }
 
@@ -1336,9 +1337,9 @@ fn timeout_concurrent_read() {
         let (tx, rx) = channel::<()>();
         Thread::spawn(move|| {
             let mut s = TcpStream::connect(addr).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             assert_eq!(s.write(&[0]), Ok(()));
-            let _ = rx.recv_opt();
+            let _ = rx.recv();
         }).detach();
 
         let mut s = a.accept().unwrap();
@@ -1347,14 +1348,14 @@ fn timeout_concurrent_read() {
         let _t = Thread::spawn(move|| {
             let mut s2 = s2;
             assert_eq!(s2.read(&mut [0]), Ok(1));
-            tx2.send(());
+            tx2.send(()).unwrap();
         });
 
         s.set_read_timeout(Some(20));
         assert_eq!(s.read(&mut [0]).err().unwrap().kind, TimedOut);
-        tx.send(());
+        tx.send(()).unwrap();
 
-        rx2.recv();
+        rx2.recv().unwrap();
     }
 
     #[test]
@@ -1369,9 +1370,9 @@ fn clone_while_reading() {
         let txdone2 = txdone.clone();
         let _t = Thread::spawn(move|| {
             let mut tcp = TcpStream::connect(addr).unwrap();
-            rx.recv();
+            rx.recv().unwrap();
             tcp.write_u8(0).unwrap();
-            txdone2.send(());
+            txdone2.send(()).unwrap();
         });
 
         // Spawn off a reading clone
@@ -1381,7 +1382,7 @@ fn clone_while_reading() {
         let _t = Thread::spawn(move|| {
             let mut tcp2 = tcp2;
             tcp2.read_u8().unwrap();
-            txdone3.send(());
+            txdone3.send(()).unwrap();
         });
 
         // Try to ensure that the reading clone is indeed reading
@@ -1392,9 +1393,9 @@ fn clone_while_reading() {
         // clone the handle again while it's reading, then let it finish the
         // read.
         let _ = tcp.clone();
-        tx.send(());
-        rxdone.recv();
-        rxdone.recv();
+        tx.send(()).unwrap();
+        rxdone.recv().unwrap();
+        rxdone.recv().unwrap();
     }
 
     #[test]
@@ -1425,8 +1426,14 @@ fn clone_accept_concurrent() {
         let (tx, rx) = channel();
         let tx2 = tx.clone();
 
-        let _t = Thread::spawn(move|| { let mut a = a; tx.send(a.accept()) });
-        let _t = Thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
+        let _t = Thread::spawn(move|| {
+            let mut a = a;
+            tx.send(a.accept()).unwrap();
+        });
+        let _t = Thread::spawn(move|| {
+            let mut a = a2;
+            tx2.send(a.accept()).unwrap();
+        });
 
         let _t = Thread::spawn(move|| {
             let _ = TcpStream::connect(addr);
@@ -1435,8 +1442,8 @@ fn clone_accept_concurrent() {
             let _ = TcpStream::connect(addr);
         });
 
-        assert!(rx.recv().is_ok());
-        assert!(rx.recv().is_ok());
+        assert!(rx.recv().unwrap().is_ok());
+        assert!(rx.recv().unwrap().is_ok());
     }
 
     #[test]
@@ -1459,10 +1466,10 @@ fn close_accept_concurrent() {
         let (tx, rx) = channel();
         let _t = Thread::spawn(move|| {
             let mut a = a;
-            tx.send(a.accept());
+            tx.send(a.accept()).unwrap();
         });
         a2.close_accept().unwrap();
 
-        assert_eq!(rx.recv().err().unwrap().kind, EndOfFile);
+        assert_eq!(rx.recv().unwrap().err().unwrap().kind, EndOfFile);
     }
 }