Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server::Handle::shutdown #117

Merged
merged 16 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description = "An RPC framework for Rust with a focus on ease of use."
travis-ci = { repository = "google/tarpc" }

[dependencies]
bincode = "1.0.0-alpha2"
bincode = { git = "https://github.com/tikue/bincode", branch = "faster-byte-buf-deserialization" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this an intentional inclusion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, thanks!

byteorder = "1.0"
cfg-if = "0.1.0"
futures = "0.1.7"
Expand Down
5 changes: 3 additions & 2 deletions benches/latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ impl FutureService for Server {
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(),
let (handle, server) = Server.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
reactor.handle().spawn(server);
let client = FutureClient::connect(addr, client::Options::default().handle(reactor.handle()));
let client = FutureClient::connect(handle.addr(),
client::Options::default().handle(reactor.handle()));
let client = reactor.run(client).unwrap();

bencher.iter(|| reactor.run(client.ack()).unwrap());
Expand Down
6 changes: 3 additions & 3 deletions examples/concurrency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,20 @@ fn main() {
.unwrap_or(4);

let mut reactor = reactor::Core::new().unwrap();
let (addr, server) = Server::new()
let (handle, server) = Server::new()
.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
reactor.handle().spawn(server);
info!("Server listening on {}.", addr);
info!("Server listening on {}.", handle.addr());

let clients = (0..num_clients)
// Spin up a couple threads to drive the clients.
.map(|i| (i, spawn_core()))
.map(|(i, remote)| {
info!("Client {} connecting...", i);
FutureClient::connect(addr, client::Options::default().remote(remote))
FutureClient::connect(handle.addr(), client::Options::default().remote(remote))
.map_err(|e| panic!(e))
});

Expand Down
18 changes: 11 additions & 7 deletions examples/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ impl subscriber::FutureService for Subscriber {
}

impl Subscriber {
fn listen(id: u32, handle: &reactor::Handle, options: server::Options) -> SocketAddr {
let (addr, server) = Subscriber { id: id }
fn listen(id: u32,
handle: &reactor::Handle,
options: server::Options)
-> server::future::Handle {
let (server_handle, server) = Subscriber { id: id }
.listen("localhost:0".first_socket_addr(), handle, options)
.unwrap();
handle.spawn(server);
addr
server_handle
}
}

Expand Down Expand Up @@ -120,7 +123,7 @@ impl publisher::FutureService for Publisher {
fn main() {
let _ = env_logger::init();
let mut reactor = reactor::Core::new().unwrap();
let (publisher_addr, server) = Publisher::new()
let (publisher_handle, server) = Publisher::new()
.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
Expand All @@ -131,10 +134,11 @@ fn main() {
let subscriber2 = Subscriber::listen(1, &reactor.handle(), server::Options::default());

let publisher =
reactor.run(publisher::FutureClient::connect(publisher_addr, client::Options::default()))
reactor.run(publisher::FutureClient::connect(publisher_handle.addr(),
client::Options::default()))
.unwrap();
reactor.run(publisher.subscribe(0, subscriber1)
.and_then(|_| publisher.subscribe(1, subscriber2))
reactor.run(publisher.subscribe(0, subscriber1.addr())
.and_then(|_| publisher.subscribe(1, subscriber2.addr()))
.map_err(|e| panic!(e))
.and_then(|_| {
println!("Broadcasting...");
Expand Down
3 changes: 1 addition & 2 deletions examples/readme_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ impl SyncService for HelloServer {
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut handle = HelloServer.listen("localhost:10000", server::Options::default())
.unwrap();
let handle = HelloServer.listen("localhost:10000", server::Options::default()).unwrap();
tx.send(handle.addr()).unwrap();
handle.run();
});
Expand Down
4 changes: 2 additions & 2 deletions examples/readme_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ impl FutureService for HelloServer {

fn main() {
let mut reactor = reactor::Core::new().unwrap();
let (addr, server) = HelloServer.listen("localhost:10000".first_socket_addr(),
let (handle, server) = HelloServer.listen("localhost:10000".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
reactor.handle().spawn(server);

let options = client::Options::default().handle(reactor.handle());
reactor.run(FutureClient::connect(addr, options)
reactor.run(FutureClient::connect(handle.addr(), options)
.map_err(tarpc::Error::from)
.and_then(|client| client.hello("Mom".to_string()))
.map(|resp| println!("{}", resp)))
Expand Down
3 changes: 1 addition & 2 deletions examples/readme_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ impl SyncService for HelloServer {
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut handle = HelloServer.listen("localhost:0", server::Options::default())
.unwrap();
let handle = HelloServer.listen("localhost:0", server::Options::default()).unwrap();
tx.send(handle.addr()).unwrap();
handle.run();
});
Expand Down
8 changes: 4 additions & 4 deletions examples/server_calling_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ impl DoubleFutureService for DoubleServer {
fn main() {
let _ = env_logger::init();
let mut reactor = reactor::Core::new().unwrap();
let (add_addr, server) = AddServer.listen("localhost:0".first_socket_addr(),
let (add, server) = AddServer.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
reactor.handle().spawn(server);

let options = client::Options::default().handle(reactor.handle());
let add_client = reactor.run(add::FutureClient::connect(add_addr, options)).unwrap();
let add_client = reactor.run(add::FutureClient::connect(add.addr(), options)).unwrap();

let (double_addr, server) = DoubleServer::new(add_client)
let (double, server) = DoubleServer::new(add_client)
.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
reactor.handle().spawn(server);

let double_client =
reactor.run(double::FutureClient::connect(double_addr, client::Options::default()))
reactor.run(double::FutureClient::connect(double.addr(), client::Options::default()))
.unwrap();
reactor.run(futures::stream::futures_unordered((0..5).map(|i| double_client.double(i)))
.map_err(|e| println!("{}", e))
Expand Down
3 changes: 2 additions & 1 deletion examples/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn bench_tarpc(target: u64) {
tx.send(addr).unwrap();
reactor.run(server).unwrap();
});
let mut client = SyncClient::connect(rx.recv().unwrap(), client::Options::default()).unwrap();
let mut client = SyncClient::connect(rx.recv().unwrap().addr(), client::Options::default())
.unwrap();
let start = time::Instant::now();
let mut nread = 0;
while nread < target {
Expand Down
16 changes: 8 additions & 8 deletions examples/two_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,30 @@ fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut reactor = reactor::Core::new().unwrap();
let (addr, server) = Bar.listen("localhost:0".first_socket_addr(),
let (handle, server) = Bar.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
tx.send(addr).unwrap();
tx.send(handle).unwrap();
reactor.run(server).unwrap();
});
let addr = rx.recv().unwrap();
bar::SyncClient::connect(addr, client::Options::default()).unwrap()
let handle = rx.recv().unwrap();
bar::SyncClient::connect(handle.addr(), client::Options::default()).unwrap()
};

let mut baz_client = {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut reactor = reactor::Core::new().unwrap();
let (addr, server) = Baz.listen("localhost:0".first_socket_addr(),
let (handle, server) = Baz.listen("localhost:0".first_socket_addr(),
&reactor.handle(),
server::Options::default())
.unwrap();
tx.send(addr).unwrap();
tx.send(handle).unwrap();
reactor.run(server).unwrap();
});
let addr = rx.recv().unwrap();
baz::SyncClient::connect(addr, client::Options::default()).unwrap()
let handle = rx.recv().unwrap();
baz::SyncClient::connect(handle.addr(), client::Options::default()).unwrap()
};


Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
//! ```
//!
#![deny(missing_docs)]
#![feature(never_type, plugin, struct_field_attributes, fn_traits, unboxed_closures)]
#![feature(fn_traits, move_cell, never_type, plugin, struct_field_attributes, unboxed_closures)]
#![plugin(tarpc_plugins)]

extern crate byteorder;
Expand Down
Loading