11 Commits

Author SHA1 Message Date
Tim Kuehn
3cf8e440f7 Bump minor version. 2016-08-07 13:02:04 -07:00
Tim Kuehn
2e02f33fc4 Merge branch 'master' of github.com:google/tarpc 2016-07-28 20:49:12 -07:00
Tim Kuehn
d8472dcd1c Update README to reflect latest version. 2016-07-28 20:48:07 -07:00
Tim
2c5846621f Update dependency versions (#43)
* Update dependency versions

* Bump minor version.
2016-07-28 20:46:30 -07:00
Tim Kuehn
6a6157948a Bump minor version. 2016-07-28 20:37:51 -07:00
Tim Kuehn
1c18a3c4fe Update dependency versions 2016-07-28 20:25:46 -07:00
shaladdle
e8ec295e85 Merge pull request #35 from tikue/missing-debug
Add missing Debug impls.
2016-04-24 21:19:42 -07:00
Tim Kuehn
44eec09418 Add missing Debug impls. 2016-04-24 21:06:42 -07:00
shaladdle
fe116a1b6b Merge pull request #34 from tikue/macro-cleanup
Minor macro implementation cleanup.
2016-04-24 20:36:08 -07:00
Tim Kuehn
ec4fa8636b Minor macro implementation cleanup.
* Fold service into service_inner.
* Rename service_inner => service.
2016-04-24 20:02:46 -07:00
shaladdle
2d58340d16 Merge pull request #33 from tikue/bump-version
Bump version to v0.5.0
2016-04-24 19:37:04 -07:00
11 changed files with 56 additions and 69 deletions

View File

@@ -23,7 +23,7 @@ function then returns the value produced by that other server.
Add to your `Cargo.toml` dependencies: Add to your `Cargo.toml` dependencies:
```toml ```toml
tarpc = "0.5.0" tarpc = "0.6"
``` ```
## Example ## Example

View File

@@ -1,4 +1,11 @@
## 0.6 (20216-08-07)
### Breaking Changes
* Updated serde to 0.8. Requires dependents to update as well.
## 0.5 (2016-04-24) ## 0.5 (2016-04-24)
### Breaking Changes
0.5 adds support for arbitrary transports via the 0.5 adds support for arbitrary transports via the
[`Transport`](tarpc/src/transport/mod.rs#L7) trait. [`Transport`](tarpc/src/transport/mod.rs#L7) trait.
Out of the box tarpc provides implementations for: Out of the box tarpc provides implementations for:
@@ -6,6 +13,9 @@ Out of the box tarpc provides implementations for:
* Tcp, for types `impl`ing `ToSocketAddrs`. * Tcp, for types `impl`ing `ToSocketAddrs`.
* Unix sockets via the `UnixTransport` type. * Unix sockets via the `UnixTransport` type.
This was a breaking change: `handler.local_addr()` was renamed
`handler.dialer()`.
## 0.4 (2016-04-02) ## 0.4 (2016-04-02)
### Breaking Changes ### Breaking Changes

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "tarpc" name = "tarpc"
version = "0.5.0" version = "0.6.0"
authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"] authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"]
license = "MIT" license = "MIT"
documentation = "https://google.github.io/tarpc" documentation = "https://google.github.io/tarpc"
@@ -11,13 +11,13 @@ readme = "../README.md"
description = "An RPC framework for Rust with a focus on ease of use." description = "An RPC framework for Rust with a focus on ease of use."
[dependencies] [dependencies]
bincode = "0.5" bincode = "0.6"
log = "0.3" log = "0.3"
scoped-pool = "0.1" scoped-pool = "1.0"
serde = "0.7" serde = "0.8"
unix_socket = "0.5" unix_socket = "0.5"
[dev-dependencies] [dev-dependencies]
lazy_static = "0.1" lazy_static = "0.2"
env_logger = "0.3" env_logger = "0.3"
tempdir = "0.3" tempdir = "0.3"

View File

@@ -250,18 +250,20 @@ macro_rules! impl_deserialize {
/// * `__Reply` -- an implementation detail /// * `__Reply` -- an implementation detail
#[macro_export] #[macro_export]
macro_rules! service { macro_rules! service {
// Entry point
( (
$( $tokens:tt )* $(
$(#[$attr:meta])*
rpc $fn_name:ident( $( $arg:ident : $in_:ty ),* ) $(-> $out:ty)*;
)*
) => { ) => {
service_inner! {{ service! {{
$( $tokens )* $(
$(#[$attr])*
rpc $fn_name( $( $arg : $in_ ),* ) $(-> $out)*;
)*
}} }}
} };
}
#[doc(hidden)]
#[macro_export]
macro_rules! service_inner {
// Pattern for when the next rpc has an implicit unit return type // Pattern for when the next rpc has an implicit unit return type
( (
{ {
@@ -272,7 +274,7 @@ macro_rules! service_inner {
} }
$( $expanded:tt )* $( $expanded:tt )*
) => { ) => {
service_inner! { service! {
{ $( $unexpanded )* } { $( $unexpanded )* }
$( $expanded )* $( $expanded )*
@@ -291,7 +293,7 @@ macro_rules! service_inner {
} }
$( $expanded:tt )* $( $expanded:tt )*
) => { ) => {
service_inner! { service! {
{ $( $unexpanded )* } { $( $unexpanded )* }
$( $expanded )* $( $expanded )*
@@ -300,7 +302,7 @@ macro_rules! service_inner {
rpc $fn_name( $( $arg : $in_ ),* ) -> $out; rpc $fn_name( $( $arg : $in_ ),* ) -> $out;
} }
}; };
// Pattern when all return types have been expanded // Pattern for when all return types have been expanded
( (
{ } // none left to expand { } // none left to expand
$( $(
@@ -498,7 +500,8 @@ macro_rules! service_inner {
} }
} }
#[allow(dead_code)] // because we're just testing that the macro expansion compiles #[allow(dead_code)]
// because we're just testing that the macro expansion compiles
#[cfg(test)] #[cfg(test)]
mod syntax_test { mod syntax_test {
// Tests a service definition with a fn that takes no args // Tests a service definition with a fn that takes no args
@@ -592,7 +595,7 @@ mod functional_test {
fn async_try_clone_unix() { fn async_try_clone_unix() {
let temp_dir = tempdir::TempDir::new("tarpc").unwrap(); let temp_dir = tempdir::TempDir::new("tarpc").unwrap();
let temp_file = temp_dir.path() let temp_file = temp_dir.path()
.join("async_try_clone_unix.tmp"); .join("async_try_clone_unix.tmp");
let handle = Server.spawn(UnixTransport(temp_file)).unwrap(); let handle = Server.spawn(UnixTransport(temp_file)).unwrap();
let client1 = AsyncClient::new(handle.dialer()).unwrap(); let client1 = AsyncClient::new(handle.dialer()).unwrap();
let client2 = client1.try_clone().unwrap(); let client2 = client1.try_clone().unwrap();

View File

@@ -5,7 +5,7 @@
use serde; use serde;
use std::fmt; use std::fmt;
use std::io::{self, BufReader, BufWriter, Read}; use std::io::{self, BufReader, BufWriter};
use std::collections::HashMap; use std::collections::HashMap;
use std::mem; use std::mem;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@@ -119,9 +119,9 @@ impl<Request, Reply, S> Drop for Client<Request, Reply, S>
// finish. // finish.
debug!("Joining writer and reader."); debug!("Joining writer and reader.");
reader_guard.take() reader_guard.take()
.expect(pos!()) .expect(pos!())
.join() .join()
.expect(pos!()); .expect(pos!());
debug!("Successfully joined writer and reader."); debug!("Successfully joined writer and reader.");
} }
} }

View File

@@ -185,8 +185,8 @@ mod test {
let _ = env_logger::init(); let _ = env_logger::init();
let server = Arc::new(Server::new()); let server = Arc::new(Server::new());
let serve_handle = server.spawn_with_config("localhost:0", let serve_handle = server.spawn_with_config("localhost:0",
Config { timeout: Some(Duration::new(0, 10)) }) Config { timeout: Some(Duration::new(0, 10)) })
.unwrap(); .unwrap();
let client: Client<(), u64, _> = Client::new(serve_handle.dialer()).unwrap(); let client: Client<(), u64, _> = Client::new(serve_handle.dialer()).unwrap();
let thread = thread::spawn(move || serve_handle.shutdown()); let thread = thread::spawn(move || serve_handle.shutdown());
info!("force_shutdown:: rpc1: {:?}", client.rpc(())); info!("force_shutdown:: rpc1: {:?}", client.rpc(()));
@@ -197,9 +197,9 @@ mod test {
fn client_failed_rpc() { fn client_failed_rpc() {
let _ = env_logger::init(); let _ = env_logger::init();
let server = Arc::new(Server::new()); let server = Arc::new(Server::new());
let serve_handle = server.spawn_with_config("localhost:0", let serve_handle =
Config { timeout: test_timeout() }) server.spawn_with_config("localhost:0", Config { timeout: test_timeout() })
.unwrap(); .unwrap();
let client: Arc<Client<(), u64, _>> = Arc::new(Client::new(serve_handle.dialer()).unwrap()); let client: Arc<Client<(), u64, _>> = Arc::new(Client::new(serve_handle.dialer()).unwrap());
client.rpc(()).unwrap(); client.rpc(()).unwrap();
serve_handle.shutdown(); serve_handle.shutdown();

View File

@@ -1,4 +1,4 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer, de, ser}; use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
use std::marker::PhantomData; use std::marker::PhantomData;
/// Packet shared between client and server. /// Packet shared between client and server.
@@ -19,40 +19,10 @@ impl<T: Serialize> Serialize for Packet<T> {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer where S: Serializer
{ {
serializer.serialize_struct(PACKET, let mut state = try!(serializer.serialize_struct(PACKET, 2));
MapVisitor { try!(serializer.serialize_struct_elt(&mut state, RPC_ID, &self.rpc_id));
value: self, try!(serializer.serialize_struct_elt(&mut state, MESSAGE, &self.message));
state: 0, serializer.serialize_struct_end(state)
})
}
}
struct MapVisitor<'a, T: 'a> {
value: &'a Packet<T>,
state: u8,
}
impl<'a, T: Serialize> ser::MapVisitor for MapVisitor<'a, T> {
#[inline]
fn visit<S>(&mut self, serializer: &mut S) -> Result<Option<()>, S::Error>
where S: Serializer
{
match self.state {
0 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt(RPC_ID, &self.value.rpc_id))))
}
1 => {
self.state += 1;
Ok(Some(try!(serializer.serialize_struct_elt(MESSAGE, &self.value.message))))
}
_ => Ok(None),
}
}
#[inline]
fn len(&self) -> Option<usize> {
Some(2)
} }
} }

View File

@@ -41,7 +41,7 @@ impl<'a, S, St> ConnectionHandler<'a, S, St>
scope.execute(move || Self::write(rx, write_stream)); scope.execute(move || Self::write(rx, write_stream));
loop { loop {
match read_stream.deserialize() { match read_stream.deserialize() {
Ok(Packet { rpc_id, message, }) => { Ok(Packet { rpc_id, message }) => {
let tx = tx.clone(); let tx = tx.clone();
scope.execute(move || { scope.execute(move || {
let reply = server.serve(message); let reply = server.serve(message);
@@ -81,7 +81,8 @@ impl<'a, S, St> ConnectionHandler<'a, S, St>
fn timed_out(error_kind: io::ErrorKind) -> bool { fn timed_out(error_kind: io::ErrorKind) -> bool {
match error_kind { match error_kind {
io::ErrorKind::TimedOut | io::ErrorKind::WouldBlock => true, io::ErrorKind::TimedOut |
io::ErrorKind::WouldBlock => true,
_ => false, _ => false,
} }
} }
@@ -264,7 +265,6 @@ pub trait Serve: Send + Sync + Sized {
dialer: dialer, dialer: dialer,
}) })
} }
} }
impl<P, S> Serve for P impl<P, S> Serve for P

View File

@@ -3,6 +3,7 @@ use std::net::{SocketAddr, TcpListener, TcpStream, ToSocketAddrs};
use std::time::Duration; use std::time::Duration;
/// A transport for TCP. /// A transport for TCP.
#[derive(Debug)]
pub struct TcpTransport<A: ToSocketAddrs>(pub A); pub struct TcpTransport<A: ToSocketAddrs>(pub A);
impl<A: ToSocketAddrs> super::Transport for TcpTransport<A> { impl<A: ToSocketAddrs> super::Transport for TcpTransport<A> {
@@ -54,6 +55,7 @@ impl super::Stream for TcpStream {
} }
/// Connects to a socket address. /// Connects to a socket address.
#[derive(Debug)]
pub struct TcpDialer<A = SocketAddr>(pub A) where A: ToSocketAddrs; pub struct TcpDialer<A = SocketAddr>(pub A) where A: ToSocketAddrs;
impl<A> super::Dialer for TcpDialer<A> impl<A> super::Dialer for TcpDialer<A>

View File

@@ -4,6 +4,7 @@ use std::time::Duration;
use unix_socket::{UnixListener, UnixStream}; use unix_socket::{UnixListener, UnixStream};
/// A transport for unix sockets. /// A transport for unix sockets.
#[derive(Debug)]
pub struct UnixTransport<P>(pub P) where P: AsRef<Path>; pub struct UnixTransport<P>(pub P) where P: AsRef<Path>;
impl<P> super::Transport for UnixTransport<P> impl<P> super::Transport for UnixTransport<P>
@@ -17,6 +18,7 @@ impl<P> super::Transport for UnixTransport<P>
} }
/// Connects to a unix socket address. /// Connects to a unix socket address.
#[derive(Debug)]
pub struct UnixDialer<P>(pub P) where P: AsRef<Path>; pub struct UnixDialer<P>(pub P) where P: AsRef<Path>;
impl<P> super::Dialer for UnixDialer<P> impl<P> super::Dialer for UnixDialer<P>

View File

@@ -5,5 +5,5 @@ authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.k
[dev-dependencies] [dev-dependencies]
tarpc = { path = "../tarpc" } tarpc = { path = "../tarpc" }
lazy_static = "^0.1.15" lazy_static = "0.2"
env_logger = "^0.3.2" env_logger = "0.3"