diff --git a/tarpc/src/lib.rs b/tarpc/src/lib.rs
index efb2684..5fce4e8 100644
--- a/tarpc/src/lib.rs
+++ b/tarpc/src/lib.rs
@@ -60,4 +60,5 @@ pub mod protocol;
/// Provides the macro used for constructing rpc services and client stubs.
pub mod macros;
-pub use protocol::{Config, Error, Result, ServeHandle};
+pub use protocol::{Config, Dialer, Error, Listener, Result, ServeHandle, Stream, TcpDialer,
+ TcpDialerExt, TcpTransport, Transport};
diff --git a/tarpc/src/macros.rs b/tarpc/src/macros.rs
index 02fac66..f068736 100644
--- a/tarpc/src/macros.rs
+++ b/tarpc/src/macros.rs
@@ -315,17 +315,18 @@ macro_rules! service_inner {
)*
#[doc="Spawn a running service."]
- fn spawn(self, addr: A) -> $crate::Result<$crate::protocol::ServeHandle>
+ fn spawn(self, addr: A)
+ -> $crate::Result<$crate::protocol::ServeHandle<$crate::TcpDialer<::std::net::SocketAddr>>>
where A: ::std::net::ToSocketAddrs,
Self: 'static,
{
- self.spawn_with_config(addr, $crate::Config::default())
+ self.spawn_with_config($crate::TcpTransport(addr), $crate::Config::default())
}
#[doc="Spawn a running service."]
- fn spawn_with_config(self, addr: A, config: $crate::Config)
- -> $crate::Result<$crate::protocol::ServeHandle>
- where A: ::std::net::ToSocketAddrs,
+ fn spawn_with_config(self, addr: T, config: $crate::Config)
+ -> $crate::Result<$crate::protocol::ServeHandle<::Dialer>>
+ where T: $crate::Transport,
Self: 'static,
{
let server = ::std::sync::Arc::new(__Server(self));
@@ -385,25 +386,27 @@ macro_rules! service_inner {
#[allow(unused)]
#[doc="The client stub that makes RPC calls to the server."]
- pub struct Client($crate::protocol::Client<__Request, __Reply>);
+ pub struct Client($crate::protocol::Client<__Request, __Reply, S>);
- impl Client {
- #[allow(unused)]
- #[doc="Create a new client with default configuration that connects to the given \
- address."]
+ impl Client<::std::net::TcpStream> {
pub fn new(addr: A) -> $crate::Result
where A: ::std::net::ToSocketAddrs,
{
- Self::with_config(addr, $crate::Config::default())
+ Self::with_config($crate::TcpDialer(addr), $crate::Config::default())
}
+ }
+ impl Client {
+ #[allow(unused)]
+ #[doc="Create a new client with default configuration that connects to the given \
+ address."]
#[allow(unused)]
#[doc="Create a new client with the specified configuration that connects to the \
given address."]
- pub fn with_config(addr: A, config: $crate::Config) -> $crate::Result
- where A: ::std::net::ToSocketAddrs,
+ pub fn with_config(dialer: D, config: $crate::Config) -> $crate::Result
+ where D: $crate::Dialer,
{
- let inner = try!($crate::protocol::Client::with_config(addr, config));
+ let inner = try!($crate::protocol::Client::with_config(dialer, config));
::std::result::Result::Ok(Client(inner))
}
@@ -424,25 +427,26 @@ macro_rules! service_inner {
#[allow(unused)]
#[doc="The client stub that makes asynchronous RPC calls to the server."]
- pub struct AsyncClient($crate::protocol::Client<__Request, __Reply>);
+ pub struct AsyncClient($crate::protocol::Client<__Request, __Reply, S>);
- impl AsyncClient {
+ impl AsyncClient<::std::net::TcpStream> {
#[allow(unused)]
#[doc="Create a new asynchronous client with default configuration that connects to \
the given address."]
- pub fn new(addr: A) -> $crate::Result
+ pub fn new(addr: A) -> $crate::Result>
where A: ::std::net::ToSocketAddrs,
{
- Self::with_config(addr, $crate::Config::default())
+ Self::with_config($crate::TcpDialer(addr), $crate::Config::default())
}
+ }
+ impl AsyncClient {
#[allow(unused)]
#[doc="Create a new asynchronous client that connects to the given address."]
- pub fn with_config(addr: A, config: $crate::Config)
- -> $crate::Result
- where A: ::std::net::ToSocketAddrs,
+ pub fn with_config(dialer: D, config: $crate::Config) -> $crate::Result
+ where D: $crate::Dialer
{
- let inner = try!($crate::protocol::Client::with_config(addr, config));
+ let inner = try!($crate::protocol::Client::with_config(dialer, config));
::std::result::Result::Ok(AsyncClient(inner))
}
diff --git a/tarpc/src/protocol/client.rs b/tarpc/src/protocol/client.rs
index edb0d36..38701cb 100644
--- a/tarpc/src/protocol/client.rs
+++ b/tarpc/src/protocol/client.rs
@@ -13,33 +13,41 @@ use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Receiver, Sender, channel};
use std::thread;
-use super::{Config, Deserialize, Error, Packet, Result, Serialize};
+use super::{Config, Deserialize, Dialer, Error, Packet, Result, Serialize, Stream, TcpDialer};
/// A client stub that connects to a server to run rpcs.
-pub struct Client
+pub struct Client
where Request: serde::ser::Serialize
{
// The guard is in an option so it can be joined in the drop fn
reader_guard: Arc