mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-24 11:40:22 +01:00
* Return a concrete type from `server::listen`. * Change `FutureServiceExt::listen` to return `(SocketAddr, Listen)`, where `Listen` is a struct created by the `service!` macro that `impls Future<Item=(), Error=()>` and represents server execution. * Disable `conservative_impl_trait` as it's no longer used. * Update `FutureServiceExt` doc comment. * Update `SyncServiceExt` doc comment. Also annotate `server::Handle` with `#[must_use]`. * `cargo fmt`
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
// Copyright 2016 Google Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
|
// This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
#![feature(plugin, test)]
|
|
#![plugin(tarpc_plugins)]
|
|
|
|
#[macro_use]
|
|
extern crate tarpc;
|
|
#[cfg(test)]
|
|
extern crate test;
|
|
extern crate env_logger;
|
|
extern crate futures;
|
|
extern crate tokio_core;
|
|
|
|
use tarpc::{client, server};
|
|
use tarpc::client::future::ClientExt;
|
|
use tarpc::util::{FirstSocketAddr, Never};
|
|
#[cfg(test)]
|
|
use test::Bencher;
|
|
use tokio_core::reactor;
|
|
|
|
service! {
|
|
rpc ack();
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
struct Server;
|
|
|
|
impl FutureService for Server {
|
|
type AckFut = futures::Finished<(), Never>;
|
|
fn ack(&self) -> Self::AckFut {
|
|
futures::finished(())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[bench]
|
|
fn latency(bencher: &mut Bencher) {
|
|
let _ = env_logger::init();
|
|
let mut reactor = reactor::Core::new().unwrap();
|
|
let (addr, server) = Server.listen("localhost:0".first_socket_addr(),
|
|
&reactor.handle(),
|
|
server::Options::default())
|
|
.unwrap();
|
|
reactor.handle().spawn(server);
|
|
let client = reactor.run(FutureClient::connect(addr, client::Options::default())).unwrap();
|
|
|
|
bencher.iter(|| reactor.run(client.ack()).unwrap());
|
|
}
|