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-linux see joyent/libuv#1189
|
|
|
|
// ignore-android needs extra network permissions
|
2015-01-29 08:19:28 +01:00
|
|
|
// ignore-openbsd system ulimit (Too many open files)
|
2014-03-10 21:27:34 -07:00
|
|
|
// exec-env:RUST_LOG=debug
|
|
|
|
|
2015-03-23 15:54:39 -07:00
|
|
|
#![feature(rustc_private, libc, old_io, io, std_misc)]
|
|
|
|
#![allow(deprecated, unused_must_use)]
|
|
|
|
|
2014-12-31 20:43:46 -08:00
|
|
|
#[macro_use]
|
2014-03-16 21:18:17 +08:00
|
|
|
extern crate log;
|
2014-02-26 12:58:41 -05:00
|
|
|
extern crate libc;
|
2014-03-16 21:18:17 +08:00
|
|
|
|
2015-01-02 12:05:24 -08:00
|
|
|
use std::sync::mpsc::channel;
|
2015-01-23 10:46:14 -08:00
|
|
|
use std::old_io::net::tcp::{TcpListener, TcpStream};
|
2015-03-17 13:33:26 -07:00
|
|
|
use std::old_io::{Acceptor, Listener, Reader, Writer};
|
2015-03-31 18:59:36 -07:00
|
|
|
use std::thread::{self, Builder};
|
2014-08-13 15:26:48 -07:00
|
|
|
use std::time::Duration;
|
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-01-23 10:46:14 -08:00
|
|
|
use std::old_io::timer;
|
2014-08-13 15:26:48 -07:00
|
|
|
timer::sleep(Duration::milliseconds(30 * 1000));
|
2014-03-10 21:27:34 -07:00
|
|
|
println!("timed out!");
|
|
|
|
unsafe { libc::exit(1) }
|
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-31 18:59:36 -07:00
|
|
|
thread::spawn(move || -> () {
|
2014-10-30 23:22:40 +03:00
|
|
|
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
2015-01-02 12:05:24 -08:00
|
|
|
tx.send(listener.socket_name().unwrap()).unwrap();
|
2014-03-10 21:27:34 -07:00
|
|
|
let mut acceptor = listener.listen();
|
|
|
|
loop {
|
|
|
|
let mut stream = match acceptor.accept() {
|
|
|
|
Ok(stream) => stream,
|
|
|
|
Err(error) => {
|
2014-10-09 15:17:22 -04:00
|
|
|
debug!("accept panicked: {}", error);
|
2014-03-10 21:27:34 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
stream.read_byte();
|
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
|
|
|
});
|
2015-01-02 12:16:41 -08:00
|
|
|
let addr = rx.recv().unwrap();
|
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) {
|
2014-03-10 21:27:34 -07:00
|
|
|
Ok(stream) => {
|
|
|
|
let mut stream = stream;
|
2014-11-18 13:49:09 +13:00
|
|
|
stream.write(&[1]);
|
2014-03-10 21:27:34 -07:00
|
|
|
let mut buf = [0];
|
2014-11-18 13:49:09 +13:00
|
|
|
stream.read(&mut buf);
|
2014-03-10 21:27:34 -07:00
|
|
|
},
|
2014-10-14 21:07:11 -04:00
|
|
|
Err(e) => debug!("{}", e)
|
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
|
|
|
}
|
|
|
|
unsafe { libc::exit(0) }
|
|
|
|
}
|