diff --git a/README.md b/README.md index 0dfb6a8..b8b3e75 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ impl SyncService for HelloServer { fn main() { let addr = "localhost:10000"; HelloServer.listen(addr).unwrap(); - let mut client = SyncClient::connect(addr).unwrap(); + let client = SyncClient::connect(addr).unwrap(); println!("{}", client.hello("Mom".to_string()).unwrap()); } ``` diff --git a/examples/readme_errors.rs b/examples/readme_errors.rs index 92f52cc..b8f27ea 100644 --- a/examples/readme_errors.rs +++ b/examples/readme_errors.rs @@ -3,7 +3,7 @@ // Licensed under the MIT License, . // This file may not be copied, modified, or distributed except according to those terms. -#![feature(conservative_impl_trait, plugin, proc_macro)] +#![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] extern crate futures; @@ -50,7 +50,7 @@ impl SyncService for HelloServer { fn main() { let addr = HelloServer.listen("localhost:10000").unwrap(); - let mut client = SyncClient::connect(addr).unwrap(); + let client = SyncClient::connect(addr).unwrap(); println!("{}", client.hello("Mom".to_string()).unwrap()); println!("{}", client.hello("".to_string()).unwrap_err()); } diff --git a/examples/readme_expanded.rs b/examples/readme_expanded.rs index 52c2027..246fae1 100644 --- a/examples/readme_expanded.rs +++ b/examples/readme_expanded.rs @@ -3,7 +3,7 @@ // Licensed under the MIT License, . // This file may not be copied, modified, or distributed except according to those terms. -#![feature(conservative_impl_trait, plugin, proc_macro)] +#![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] extern crate bincode; diff --git a/examples/readme_sync.rs b/examples/readme_sync.rs index 4fbf548..ecfbcdc 100644 --- a/examples/readme_sync.rs +++ b/examples/readme_sync.rs @@ -3,7 +3,7 @@ // Licensed under the MIT License, . // This file may not be copied, modified, or distributed except according to those terms. -// required by `FutureClient` (not used in this example) +// required by `FutureClient` (not used directly in this example) #![feature(conservative_impl_trait, plugin)] #![plugin(tarpc_plugins)] diff --git a/examples/server_calling_server.rs b/examples/server_calling_server.rs index a6c8e2d..efebdf1 100644 --- a/examples/server_calling_server.rs +++ b/examples/server_calling_server.rs @@ -80,7 +80,7 @@ fn main() { let double = DoubleServer::new(add_client); let double_addr = double.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut double_client = double::SyncClient::connect(&double_addr).unwrap(); + let double_client = double::SyncClient::connect(&double_addr).unwrap(); for i in 0..5 { println!("{:?}", double_client.double(i).unwrap()); } diff --git a/examples/throughput.rs b/examples/throughput.rs index 1186677..cf77e17 100644 --- a/examples/throughput.rs +++ b/examples/throughput.rs @@ -53,7 +53,7 @@ const CHUNK_SIZE: u32 = 1 << 19; fn bench_tarpc(target: u64) { let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut client = SyncClient::connect(&addr).unwrap(); + let client = SyncClient::connect(&addr).unwrap(); let start = time::Instant::now(); let mut nread = 0; while nread < target { diff --git a/src/macros.rs b/src/macros.rs index eabef32..97fa505 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -611,7 +611,7 @@ macro_rules! service { #[allow(unused)] #[derive(Clone, Debug)] /// The client stub that makes RPC calls to the server. Exposes a blocking interface. - pub struct SyncClient(FutureClient); + pub struct SyncClient(::std::sync::Arc<::std::sync::Mutex>); impl $crate::sync::Connect for SyncClient { fn connect(addr: A) -> ::std::result::Result @@ -619,7 +619,8 @@ macro_rules! service { { let addr = $crate::util::FirstSocketAddr::try_first_socket_addr(&addr)?; let client = ::connect(&addr); - let client = SyncClient($crate::futures::Future::wait(client)?); + let client = $crate::futures::Future::wait(client)?; + let client = SyncClient(::std::sync::Arc::new(::std::sync::Mutex::new(client))); ::std::result::Result::Ok(client) } } @@ -628,10 +629,10 @@ macro_rules! service { $( #[allow(unused)] $(#[$attr])* - pub fn $fn_name(&mut self, $($arg: $in_),*) + pub fn $fn_name(&self, $($arg: $in_),*) -> ::std::result::Result<$out, $crate::Error<$error>> { - let rpc = (self.0).$fn_name($($arg),*); + let rpc = self.0.lock().unwrap().$fn_name($($arg),*); $crate::futures::Future::wait(rpc) } )* @@ -833,7 +834,7 @@ mod functional_test { fn simple() { let _ = env_logger::init(); let addr = Server.listen("localhost:0".first_socket_addr()).unwrap(); - let mut client = SyncClient::connect(addr).unwrap(); + let client = SyncClient::connect(addr).unwrap(); assert_eq!(3, client.add(1, 2).unwrap()); assert_eq!("Hey, Tim.", client.hey("Tim".to_string()).unwrap()); } @@ -842,7 +843,7 @@ mod functional_test { fn other_service() { let _ = env_logger::init(); let addr = Server.listen("localhost:0".first_socket_addr()).unwrap(); - let mut client = super::other_service::SyncClient::connect(addr).expect("Could not connect!"); + let client = super::other_service::SyncClient::connect(addr).expect("Could not connect!"); match client.foo().err().unwrap() { ::Error::ServerDeserialize(_) => {} // good bad => panic!("Expected Error::ServerDeserialize but got {}", bad),