This commit is contained in:
Tim Kuehn
2016-01-14 20:45:09 -08:00
parent b3ed2ef0ba
commit e4faff74be
2 changed files with 19 additions and 15 deletions

View File

@@ -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<A>(addr: A, timeout: ::std::option::Option<::std::time::Duration>) -> $crate::Result<Self>
pub fn new<A>(addr: A, timeout: ::std::option::Option<::std::time::Duration>)
-> $crate::Result<Self>
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<A, S>(addr: A, service: S, read_timeout: ::std::option::Option<::std::time::Duration>) -> $crate::Result<$crate::protocol::ServeHandle>
pub fn serve<A, S>(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
{

View File

@@ -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<A, F>(addr: A,
f: F,
read_timeout: Option<Duration>)
-> io::Result<ServeHandle>
/// Start
pub fn serve_async<A, F>(addr: A, f: F, read_timeout: Option<Duration>) -> io::Result<ServeHandle>
where A: ToSocketAddrs,
F: 'static + Clone + Send + Serve
{
@@ -332,10 +329,9 @@ impl<Reply> Reader<Reply> {
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<Request, Reply> Drop for Client<Request, Reply>
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();