1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-linux see joyent/libuv#1189
12 // ignore-android needs extra network permissions
13 // exec-env:RUST_LOG=debug
16 #[phase(plugin, link)]
20 use std::sync::mpsc::channel;
21 use std::io::net::tcp::{TcpListener, TcpStream};
22 use std::io::{Acceptor, Listener};
23 use std::thread::{Builder, Thread};
24 use std::time::Duration;
27 // This test has a chance to time out, try to not let it time out
28 Thread::spawn(move|| -> () {
30 timer::sleep(Duration::milliseconds(30 * 1000));
31 println!("timed out!");
32 unsafe { libc::exit(1) }
35 let (tx, rx) = channel();
36 Thread::spawn(move || -> () {
37 let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
38 tx.send(listener.socket_name().unwrap()).unwrap();
39 let mut acceptor = listener.listen();
41 let mut stream = match acceptor.accept() {
44 debug!("accept panicked: {}", error);
52 let addr = rx.recv().unwrap();
54 let (tx, rx) = channel();
55 for _ in range(0u, 1000) {
57 Builder::new().stack_size(64 * 1024).spawn(move|| {
58 match TcpStream::connect(addr) {
60 let mut stream = stream;
63 stream.read(&mut buf);
65 Err(e) => debug!("{}", e)
71 // Wait for all clients to exit, but don't wait for the server to exit. The
72 // server just runs infinitely.
74 for _ in range(0u, 1000) {
77 unsafe { libc::exit(0) }