forked from mirrors/gecko-dev
--HG-- rename : third_party/rust/crossbeam-deque/.cargo-checksum.json => third_party/rust/crossbeam-deque-0.2.0/.cargo-checksum.json rename : third_party/rust/crossbeam-deque/.travis.yml => third_party/rust/crossbeam-deque-0.2.0/.travis.yml rename : third_party/rust/crossbeam-deque/CHANGELOG.md => third_party/rust/crossbeam-deque-0.2.0/CHANGELOG.md rename : third_party/rust/crossbeam-deque/Cargo.toml => third_party/rust/crossbeam-deque-0.2.0/Cargo.toml rename : third_party/rust/bitflags-0.7.0/LICENSE-APACHE => third_party/rust/crossbeam-deque-0.2.0/LICENSE-APACHE rename : third_party/rust/crossbeam-deque/README.md => third_party/rust/crossbeam-deque-0.2.0/README.md rename : third_party/rust/crossbeam-deque/src/lib.rs => third_party/rust/crossbeam-deque-0.2.0/src/lib.rs rename : third_party/rust/crossbeam-epoch/.cargo-checksum.json => third_party/rust/crossbeam-epoch-0.3.1/.cargo-checksum.json rename : third_party/rust/crossbeam-epoch/.travis.yml => third_party/rust/crossbeam-epoch-0.3.1/.travis.yml rename : third_party/rust/crossbeam-epoch/CHANGELOG.md => third_party/rust/crossbeam-epoch-0.3.1/CHANGELOG.md rename : third_party/rust/crossbeam-epoch/Cargo.toml => third_party/rust/crossbeam-epoch-0.3.1/Cargo.toml rename : third_party/rust/tokio-io/LICENSE-APACHE => third_party/rust/crossbeam-epoch-0.3.1/LICENSE-APACHE rename : third_party/rust/crossbeam-epoch/README.md => third_party/rust/crossbeam-epoch-0.3.1/README.md rename : third_party/rust/crossbeam-epoch/examples/sanitize.rs => third_party/rust/crossbeam-epoch-0.3.1/examples/sanitize.rs rename : third_party/rust/crossbeam-epoch/src/atomic.rs => third_party/rust/crossbeam-epoch-0.3.1/src/atomic.rs rename : third_party/rust/crossbeam-epoch/src/collector.rs => third_party/rust/crossbeam-epoch-0.3.1/src/collector.rs rename : third_party/rust/crossbeam-epoch/src/default.rs => third_party/rust/crossbeam-epoch-0.3.1/src/default.rs rename : third_party/rust/crossbeam-epoch/src/deferred.rs => third_party/rust/crossbeam-epoch-0.3.1/src/deferred.rs rename : third_party/rust/crossbeam-epoch/src/epoch.rs => third_party/rust/crossbeam-epoch-0.3.1/src/epoch.rs rename : third_party/rust/crossbeam-epoch/src/garbage.rs => third_party/rust/crossbeam-epoch-0.3.1/src/garbage.rs rename : third_party/rust/crossbeam-epoch/src/guard.rs => third_party/rust/crossbeam-epoch-0.3.1/src/guard.rs rename : third_party/rust/crossbeam-epoch/src/internal.rs => third_party/rust/crossbeam-epoch-0.3.1/src/internal.rs rename : third_party/rust/crossbeam-epoch/src/lib.rs => third_party/rust/crossbeam-epoch-0.3.1/src/lib.rs rename : third_party/rust/crossbeam-epoch/src/sync/list.rs => third_party/rust/crossbeam-epoch-0.3.1/src/sync/list.rs rename : third_party/rust/crossbeam-epoch/src/sync/queue.rs => third_party/rust/crossbeam-epoch-0.3.1/src/sync/queue.rs rename : third_party/rust/crossbeam-utils/.cargo-checksum.json => third_party/rust/crossbeam-utils-0.2.2/.cargo-checksum.json rename : third_party/rust/crossbeam-utils/CHANGELOG.md => third_party/rust/crossbeam-utils-0.2.2/CHANGELOG.md rename : third_party/rust/crossbeam-utils/Cargo.toml => third_party/rust/crossbeam-utils-0.2.2/Cargo.toml rename : third_party/rust/bitflags-0.7.0/LICENSE-APACHE => third_party/rust/crossbeam-utils-0.2.2/LICENSE-APACHE rename : third_party/rust/crossbeam-utils/src/atomic_option.rs => third_party/rust/crossbeam-utils-0.2.2/src/atomic_option.rs rename : third_party/rust/crossbeam-utils/src/lib.rs => third_party/rust/crossbeam-utils-0.2.2/src/lib.rs rename : third_party/rust/crossbeam-utils/src/scoped.rs => third_party/rust/crossbeam-utils-0.2.2/src/scoped.rs rename : third_party/rust/bitflags-0.7.0/LICENSE-APACHE => third_party/rust/indexmap/LICENSE-APACHE rename : third_party/rust/lazycell/.cargo-checksum.json => third_party/rust/lazycell-0.4.0/.cargo-checksum.json rename : third_party/rust/lazycell/CHANGELOG.md => third_party/rust/lazycell-0.4.0/CHANGELOG.md rename : third_party/rust/lazycell/Cargo.toml => third_party/rust/lazycell-0.4.0/Cargo.toml rename : third_party/rust/bitflags-0.7.0/LICENSE-APACHE => third_party/rust/lazycell-0.4.0/LICENSE-APACHE rename : third_party/rust/lazycell/LICENSE-MIT => third_party/rust/lazycell-0.4.0/LICENSE-MIT rename : third_party/rust/lazycell/README.md => third_party/rust/lazycell-0.4.0/README.md rename : third_party/rust/lazycell/src/lib.rs => third_party/rust/lazycell-0.4.0/src/lib.rs rename : third_party/rust/bitflags-0.7.0/LICENSE-APACHE => third_party/rust/rand-0.3.22/LICENSE-APACHE rename : third_party/rust/bitflags-0.7.0/LICENSE-MIT => third_party/rust/rand-0.3.22/LICENSE-MIT rename : third_party/rust/rand/appveyor.yml => third_party/rust/rand-0.3.22/appveyor.yml rename : third_party/rust/slab/.cargo-checksum.json => third_party/rust/slab-0.3.0/.cargo-checksum.json rename : third_party/rust/slab/Cargo.toml => third_party/rust/slab-0.3.0/Cargo.toml rename : third_party/rust/slab/README.md => third_party/rust/slab-0.3.0/README.md rename : third_party/rust/slab/src/lib.rs => third_party/rust/slab-0.3.0/src/lib.rs rename : third_party/rust/tokio-io/src/read_to_end.rs => third_party/rust/tokio-io/src/io/read_to_end.rs rename : third_party/rust/tokio-io/src/read_until.rs => third_party/rust/tokio-io/src/io/read_until.rs
132 lines
3.2 KiB
Rust
132 lines
3.2 KiB
Rust
extern crate env_logger;
|
|
extern crate tokio_io;
|
|
extern crate tokio_tcp;
|
|
extern crate mio;
|
|
extern crate futures;
|
|
|
|
use std::{net, thread};
|
|
use std::sync::mpsc::channel;
|
|
|
|
use futures::{Future, Stream};
|
|
use tokio_tcp::{TcpListener, TcpStream};
|
|
|
|
|
|
macro_rules! t {
|
|
($e:expr) => (match $e {
|
|
Ok(e) => e,
|
|
Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn connect() {
|
|
drop(env_logger::init());
|
|
let srv = t!(net::TcpListener::bind("127.0.0.1:0"));
|
|
let addr = t!(srv.local_addr());
|
|
let t = thread::spawn(move || {
|
|
t!(srv.accept()).0
|
|
});
|
|
|
|
let stream = TcpStream::connect(&addr);
|
|
let mine = t!(stream.wait());
|
|
let theirs = t.join().unwrap();
|
|
|
|
assert_eq!(t!(mine.local_addr()), t!(theirs.peer_addr()));
|
|
assert_eq!(t!(theirs.local_addr()), t!(mine.peer_addr()));
|
|
}
|
|
|
|
#[test]
|
|
fn accept() {
|
|
drop(env_logger::init());
|
|
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse())));
|
|
let addr = t!(srv.local_addr());
|
|
|
|
let (tx, rx) = channel();
|
|
let client = srv.incoming().map(move |t| {
|
|
tx.send(()).unwrap();
|
|
t
|
|
}).into_future().map_err(|e| e.0);
|
|
assert!(rx.try_recv().is_err());
|
|
let t = thread::spawn(move || {
|
|
net::TcpStream::connect(&addr).unwrap()
|
|
});
|
|
|
|
let (mine, _remaining) = t!(client.wait());
|
|
let mine = mine.unwrap();
|
|
let theirs = t.join().unwrap();
|
|
|
|
assert_eq!(t!(mine.local_addr()), t!(theirs.peer_addr()));
|
|
assert_eq!(t!(theirs.local_addr()), t!(mine.peer_addr()));
|
|
}
|
|
|
|
#[test]
|
|
fn accept2() {
|
|
drop(env_logger::init());
|
|
let srv = t!(TcpListener::bind(&t!("127.0.0.1:0".parse())));
|
|
let addr = t!(srv.local_addr());
|
|
|
|
let t = thread::spawn(move || {
|
|
net::TcpStream::connect(&addr).unwrap()
|
|
});
|
|
|
|
let (tx, rx) = channel();
|
|
let client = srv.incoming().map(move |t| {
|
|
tx.send(()).unwrap();
|
|
t
|
|
}).into_future().map_err(|e| e.0);
|
|
assert!(rx.try_recv().is_err());
|
|
|
|
let (mine, _remaining) = t!(client.wait());
|
|
mine.unwrap();
|
|
t.join().unwrap();
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
mod unix {
|
|
use tokio_tcp::TcpStream;
|
|
|
|
use env_logger;
|
|
use futures::{Future, future};
|
|
use mio::unix::UnixReady;
|
|
use tokio_io::AsyncRead;
|
|
|
|
use std::io::Write;
|
|
use std::{net, thread};
|
|
use std::time::Duration;
|
|
|
|
#[test]
|
|
fn poll_hup() {
|
|
drop(env_logger::init());
|
|
|
|
let srv = t!(net::TcpListener::bind("127.0.0.1:0"));
|
|
let addr = t!(srv.local_addr());
|
|
let t = thread::spawn(move || {
|
|
let mut client = t!(srv.accept()).0;
|
|
client.write(b"hello world").unwrap();
|
|
thread::sleep(Duration::from_millis(200));
|
|
});
|
|
|
|
let mut stream = t!(TcpStream::connect(&addr).wait());
|
|
|
|
// Poll for HUP before reading.
|
|
future::poll_fn(|| {
|
|
stream.poll_read_ready(UnixReady::hup().into())
|
|
}).wait().unwrap();
|
|
|
|
// Same for write half
|
|
future::poll_fn(|| {
|
|
stream.poll_write_ready()
|
|
}).wait().unwrap();
|
|
|
|
let mut buf = vec![0; 11];
|
|
|
|
// Read the data
|
|
future::poll_fn(|| {
|
|
stream.poll_read(&mut buf)
|
|
}).wait().unwrap();
|
|
|
|
assert_eq!(b"hello world", &buf[..]);
|
|
|
|
t.join().unwrap();
|
|
}
|
|
}
|