2015-01-29 08:19:28 +01:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-03-10 21:27:34 -07:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
// ignore-android needs extra network permissions
|
2015-03-23 12:48:42 -07:00
|
|
|
// ignore-bitrig system ulimit (Too many open files)
|
2015-06-30 20:37:11 -07:00
|
|
|
// ignore-netbsd system ulimit (Too many open files)
|
|
|
|
// ignore-openbsd system ulimit (Too many open files)
|
2016-02-11 12:34:41 +01:00
|
|
|
// ignore-emscripten no threads or sockets support
|
2014-03-16 21:18:17 +08:00
|
|
|
|
2015-04-10 13:51:53 -07:00
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::net::{TcpListener, TcpStream};
|
|
|
|
use std::process;
|
2015-01-02 12:05:24 -08:00
|
|
|
use std::sync::mpsc::channel;
|
2015-03-31 18:59:36 -07:00
|
|
|
use std::thread::{self, Builder};
|
2014-04-05 22:18:52 -07:00
|
|
|
|
2014-03-10 21:27:34 -07:00
|
|
|
fn main() {
|
|
|
|
// This test has a chance to time out, try to not let it time out
|
2015-03-31 18:59:36 -07:00
|
|
|
thread::spawn(move|| -> () {
|
2015-04-10 13:51:53 -07:00
|
|
|
thread::sleep_ms(30 * 1000);
|
|
|
|
process::exit(1);
|
2015-01-05 21:59:45 -08:00
|
|
|
});
|
2014-03-10 21:27:34 -07:00
|
|
|
|
2015-04-10 13:51:53 -07:00
|
|
|
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
|
|
let addr = listener.local_addr().unwrap();
|
2015-03-31 18:59:36 -07:00
|
|
|
thread::spawn(move || -> () {
|
2014-03-10 21:27:34 -07:00
|
|
|
loop {
|
2015-04-10 13:51:53 -07:00
|
|
|
let mut stream = match listener.accept() {
|
|
|
|
Ok(stream) => stream.0,
|
|
|
|
Err(error) => continue,
|
2014-03-10 21:27:34 -07:00
|
|
|
};
|
2015-04-10 13:51:53 -07:00
|
|
|
stream.read(&mut [0]);
|
2014-11-18 13:49:09 +13:00
|
|
|
stream.write(&[2]);
|
2014-03-10 21:27:34 -07:00
|
|
|
}
|
2015-01-05 21:59:45 -08:00
|
|
|
});
|
2014-03-10 21:27:34 -07:00
|
|
|
|
2014-03-13 23:26:14 -05:00
|
|
|
let (tx, rx) = channel();
|
2015-03-03 10:42:26 +02:00
|
|
|
for _ in 0..1000 {
|
2014-03-13 23:26:14 -05:00
|
|
|
let tx = tx.clone();
|
2014-12-14 00:05:32 -08:00
|
|
|
Builder::new().stack_size(64 * 1024).spawn(move|| {
|
2014-10-30 23:22:40 +03:00
|
|
|
match TcpStream::connect(addr) {
|
2015-04-10 13:51:53 -07:00
|
|
|
Ok(mut stream) => {
|
2014-11-18 13:49:09 +13:00
|
|
|
stream.write(&[1]);
|
2015-04-10 13:51:53 -07:00
|
|
|
stream.read(&mut [0]);
|
2014-03-10 21:27:34 -07:00
|
|
|
},
|
2015-04-10 13:51:53 -07:00
|
|
|
Err(..) => {}
|
2014-03-10 21:27:34 -07:00
|
|
|
}
|
2015-01-02 12:05:24 -08:00
|
|
|
tx.send(()).unwrap();
|
2015-01-05 21:59:45 -08:00
|
|
|
});
|
2014-03-10 21:27:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all clients to exit, but don't wait for the server to exit. The
|
|
|
|
// server just runs infinitely.
|
2014-03-13 23:26:14 -05:00
|
|
|
drop(tx);
|
2015-03-03 10:42:26 +02:00
|
|
|
for _ in 0..1000 {
|
2015-01-02 12:05:24 -08:00
|
|
|
rx.recv().unwrap();
|
2014-03-10 21:27:34 -07:00
|
|
|
}
|
2015-04-10 13:51:53 -07:00
|
|
|
process::exit(0);
|
2014-03-10 21:27:34 -07:00
|
|
|
}
|