1 // Copyright 2012-2015 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-android needs extra network permissions
12 // ignore-bitrig system ulimit (Too many open files)
13 // ignore-netbsd system ulimit (Too many open files)
14 // ignore-openbsd system ulimit (Too many open files)
16 use std::io::prelude::*;
17 use std::net::{TcpListener, TcpStream};
19 use std::sync::mpsc::channel;
20 use std::thread::{self, Builder};
23 // This test has a chance to time out, try to not let it time out
24 thread::spawn(move|| -> () {
25 thread::sleep_ms(30 * 1000);
29 let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
30 let addr = listener.local_addr().unwrap();
31 thread::spawn(move || -> () {
33 let mut stream = match listener.accept() {
34 Ok(stream) => stream.0,
35 Err(error) => continue,
37 stream.read(&mut [0]);
42 let (tx, rx) = channel();
45 Builder::new().stack_size(64 * 1024).spawn(move|| {
46 match TcpStream::connect(addr) {
49 stream.read(&mut [0]);
57 // Wait for all clients to exit, but don't wait for the server to exit. The
58 // server just runs infinitely.