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
80 lines
2.5 KiB
Rust
80 lines
2.5 KiB
Rust
use std::mem;
|
|
use mio::net::{AddressFamily, Inet, Inet6, SockAddr, InetAddr, IPv4Addr, SocketType, Dgram, Stream};
|
|
use std::io::net::ip::IpAddr;
|
|
use native::NativeTaskBuilder;
|
|
use std::task::TaskBuilder;
|
|
use mio::os::{from_sockaddr};
|
|
use time::Instant;
|
|
use std::vec::*;
|
|
use std::io::timer;
|
|
|
|
mod nix {
|
|
pub use nix::c_int;
|
|
pub use nix::fcntl::{Fd, O_NONBLOCK, O_CLOEXEC};
|
|
pub use nix::errno::{EWOULDBLOCK, EINPROGRESS};
|
|
pub use nix::sys::socket::*;
|
|
pub use nix::unistd::*;
|
|
pub use nix::sys::epoll::*;
|
|
}
|
|
|
|
fn timed(label: &str, f: ||) {
|
|
let start = Instant::now();
|
|
f();
|
|
let elapsed = start.elapsed();
|
|
println!(" {}: {}", label, elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1_000_000_000.0);
|
|
}
|
|
|
|
fn init(saddr: &str) -> (nix::Fd, nix::Fd) {
|
|
let optval = 1i;
|
|
let addr = SockAddr::parse(saddr.as_slice()).expect("could not parse InetAddr");
|
|
let srvfd = nix::socket(nix::AF_INET, nix::SOCK_STREAM, nix::SOCK_CLOEXEC).unwrap();
|
|
nix::setsockopt(srvfd, nix::SOL_SOCKET, nix::SO_REUSEADDR, &optval).unwrap();
|
|
nix::bind(srvfd, &from_sockaddr(&addr)).unwrap();
|
|
nix::listen(srvfd, 256u).unwrap();
|
|
|
|
let fd = nix::socket(nix::AF_INET, nix::SOCK_STREAM, nix::SOCK_CLOEXEC | nix::SOCK_NONBLOCK).unwrap();
|
|
let res = nix::connect(fd, &from_sockaddr(&addr));
|
|
let start = Instant::now();
|
|
println!("connecting : {}", res);
|
|
|
|
let clifd = nix::accept4(srvfd, nix::SOCK_CLOEXEC | nix::SOCK_NONBLOCK).unwrap();
|
|
let elapsed = start.elapsed();
|
|
println!("accepted : {} - {}", clifd, elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1_000_000_000.0);
|
|
|
|
(clifd, srvfd)
|
|
}
|
|
|
|
#[test]
|
|
fn read_bench() {
|
|
let (clifd, srvfd) = init("10.10.1.5:11111");
|
|
let mut buf = Vec::with_capacity(1600);
|
|
unsafe { buf.set_len(1600); }
|
|
timed("read", || {
|
|
let mut i = 0u;
|
|
while i < 10000000 {
|
|
let res = nix::read(clifd, buf.as_mut_slice());
|
|
assert_eq!(res.unwrap_err().kind, nix::EWOULDBLOCK);
|
|
i = i + 1;
|
|
}
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn epollctl_bench() {
|
|
let (clifd, srvfd) = init("10.10.1.5:22222");
|
|
|
|
let epfd = nix::epoll_create().unwrap();
|
|
let info = nix::EpollEvent { events: nix::EPOLLIN | nix::EPOLLONESHOT | nix::EPOLLET,
|
|
data: 0u64 };
|
|
|
|
nix::epoll_ctl(epfd, nix::EpollCtlAdd, clifd, &info);
|
|
|
|
timed("epoll_ctl", || {
|
|
let mut i = 0u;
|
|
while i < 10000000 {
|
|
nix::epoll_ctl(epfd, nix::EpollCtlMod, clifd, &info);
|
|
i = i + 1;
|
|
}
|
|
});
|
|
|
|
}
|