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)]
23 use std::io::net::tcp::{TcpListener, TcpStream};
24 use std::io::{Acceptor, Listener};
25 use std::task::TaskBuilder;
28 fn start(argc: int, argv: **u8) -> int {
29 green::start(argc, argv, rustuv::event_loop, main)
33 // This test has a chance to time out, try to not let it time out
36 timer::sleep(30 * 1000);
37 println!("timed out!");
38 unsafe { libc::exit(1) }
41 let (tx, rx) = channel();
43 let mut listener = TcpListener::bind("127.0.0.1", 0).unwrap();
44 tx.send(listener.socket_name().unwrap());
45 let mut acceptor = listener.listen();
47 let mut stream = match acceptor.accept() {
50 debug!("accept failed: {:?}", error);
60 let (tx, rx) = channel();
61 for _ in range(0, 1000) {
63 TaskBuilder::new().stack_size(64 * 1024).spawn(proc() {
64 let host = addr.ip.to_str();
66 match TcpStream::connect(host.as_slice(), port) {
68 let mut stream = stream;
73 Err(e) => debug!("{:?}", e)
79 // Wait for all clients to exit, but don't wait for the server to exit. The
80 // server just runs infinitely.
82 for _ in range(0, 1000) {
85 unsafe { libc::exit(0) }