]>
Commit | Line | Data |
---|---|---|
85aaf69f | 1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
1a4d82fc JJ |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
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. | |
10 | ||
1a4d82fc | 11 | // ignore-android needs extra network permissions |
9346a6ac | 12 | // ignore-bitrig system ulimit (Too many open files) |
c1a9b12d SL |
13 | // ignore-netbsd system ulimit (Too many open files) |
14 | // ignore-openbsd system ulimit (Too many open files) | |
1a4d82fc | 15 | |
9346a6ac AL |
16 | use std::io::prelude::*; |
17 | use std::net::{TcpListener, TcpStream}; | |
18 | use std::process; | |
1a4d82fc | 19 | use std::sync::mpsc::channel; |
c34b1796 | 20 | use std::thread::{self, Builder}; |
1a4d82fc JJ |
21 | |
22 | fn main() { | |
23 | // This test has a chance to time out, try to not let it time out | |
c34b1796 | 24 | thread::spawn(move|| -> () { |
9346a6ac AL |
25 | thread::sleep_ms(30 * 1000); |
26 | process::exit(1); | |
1a4d82fc JJ |
27 | }); |
28 | ||
9346a6ac AL |
29 | let mut listener = TcpListener::bind("127.0.0.1:0").unwrap(); |
30 | let addr = listener.local_addr().unwrap(); | |
c34b1796 | 31 | thread::spawn(move || -> () { |
1a4d82fc | 32 | loop { |
9346a6ac AL |
33 | let mut stream = match listener.accept() { |
34 | Ok(stream) => stream.0, | |
35 | Err(error) => continue, | |
1a4d82fc | 36 | }; |
9346a6ac | 37 | stream.read(&mut [0]); |
1a4d82fc JJ |
38 | stream.write(&[2]); |
39 | } | |
40 | }); | |
1a4d82fc JJ |
41 | |
42 | let (tx, rx) = channel(); | |
c34b1796 | 43 | for _ in 0..1000 { |
1a4d82fc JJ |
44 | let tx = tx.clone(); |
45 | Builder::new().stack_size(64 * 1024).spawn(move|| { | |
46 | match TcpStream::connect(addr) { | |
9346a6ac | 47 | Ok(mut stream) => { |
1a4d82fc | 48 | stream.write(&[1]); |
9346a6ac | 49 | stream.read(&mut [0]); |
1a4d82fc | 50 | }, |
9346a6ac | 51 | Err(..) => {} |
1a4d82fc JJ |
52 | } |
53 | tx.send(()).unwrap(); | |
54 | }); | |
55 | } | |
56 | ||
57 | // Wait for all clients to exit, but don't wait for the server to exit. The | |
58 | // server just runs infinitely. | |
59 | drop(tx); | |
c34b1796 | 60 | for _ in 0..1000 { |
1a4d82fc JJ |
61 | rx.recv().unwrap(); |
62 | } | |
9346a6ac | 63 | process::exit(0); |
1a4d82fc | 64 | } |