diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs index ccaa025..a71d412 100644 --- a/tarpc/src/macros.rs +++ b/tarpc/src/macros.rs @@ -49,15 +49,15 @@ macro_rules! request_variant { // The main macro that creates RPC services. #[macro_export] -macro_rules! rpc { +macro_rules! rpc { ( mod $server:ident { service { - $( + $( $(#[$attr:meta])* rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) -> $out:ty; - )* + )* } } ) => { @@ -66,7 +66,7 @@ macro_rules! rpc { items { } - service { + service { $( $(#[$attr])* rpc $fn_name($($arg: $in_),*) -> $out; @@ -125,7 +125,8 @@ macro_rules! rpc { impl Client { #[doc="Create a new client that connects to the given address."] - pub fn new(addr: A, timeout: ::std::option::Option<::std::time::Duration>) -> $crate::Result + pub fn new(addr: A, timeout: ::std::option::Option<::std::time::Duration>) + -> $crate::Result where A: ::std::net::ToSocketAddrs, { let inner = try!($crate::protocol::Client::new(addr, timeout)); @@ -153,7 +154,10 @@ macro_rules! rpc { } #[doc="Start a running service."] - pub fn serve(addr: A, service: S, read_timeout: ::std::option::Option<::std::time::Duration>) -> $crate::Result<$crate::protocol::ServeHandle> + pub fn serve(addr: A, + service: S, + read_timeout: ::std::option::Option<::std::time::Duration>) + -> $crate::Result<$crate::protocol::ServeHandle> where A: ::std::net::ToSocketAddrs, S: 'static + Service { diff --git a/tarpc/src/protocol.rs b/tarpc/src/protocol.rs index 279bf6e..d498f5f 100644 --- a/tarpc/src/protocol.rs +++ b/tarpc/src/protocol.rs @@ -196,7 +196,7 @@ impl ConnectionHandler { } } -/// Provides methods for blocking until the server completes, +/// Provides methods for blocking until the server completes, pub struct ServeHandle { tx: Sender<()>, join_handle: JoinHandle<()>, @@ -227,11 +227,8 @@ impl ServeHandle { } } -/// Start -pub fn serve_async(addr: A, - f: F, - read_timeout: Option) - -> io::Result +/// Start +pub fn serve_async(addr: A, f: F, read_timeout: Option) -> io::Result where A: ToSocketAddrs, F: 'static + Clone + Send + Serve { @@ -332,10 +329,9 @@ impl Reader { let reply_tx = requests.remove(&id).unwrap(); reply_tx.send(reply).unwrap(); } - // TODO: This shutdown logic is janky.. What's the right way to do this? Err(err) => { warn!("Client: reader thread encountered an unexpected error while parsing; \ - returning now. Error: {:?}", + returning now. Error: {:?}", err); break; } @@ -440,7 +436,11 @@ impl Drop for Client where Request: serde::ser::Serialize { fn drop(&mut self) { - if let Err(e) = self.synced_state.lock().unwrap().stream.shutdown(::std::net::Shutdown::Both) { + if let Err(e) = self.synced_state + .lock() + .unwrap() + .stream + .shutdown(::std::net::Shutdown::Both) { warn!("Client: couldn't shutdown reader thread: {:?}", e); } self.reader_guard.take().unwrap().join().unwrap();