mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-02-23 15:49:54 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92f157206d | ||
|
|
b093db63a3 | ||
|
|
8c3e3df47f | ||
|
|
6907c6e0a3 | ||
|
|
4b5273127d | ||
|
|
4b763e9f52 | ||
|
|
848eb00bea | ||
|
|
44ec68c002 | ||
|
|
b2282f9d7a | ||
|
|
326f0270b9 | ||
|
|
fd47a6c038 | ||
|
|
77cfffaaed | ||
|
|
118893678b | ||
|
|
ae3985de46 | ||
|
|
49f36e0b2b | ||
|
|
4a7082b27c | ||
|
|
3aa53a06fb | ||
|
|
a0afbefef4 | ||
|
|
5b554f7062 | ||
|
|
0411a90be9 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,3 +3,5 @@ Cargo.lock
|
|||||||
.cargo
|
.cargo
|
||||||
*.swp
|
*.swp
|
||||||
*.bk
|
*.bk
|
||||||
|
tarpc.iml
|
||||||
|
.idea
|
||||||
|
|||||||
17
Cargo.toml
17
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tarpc"
|
name = "tarpc"
|
||||||
version = "0.9.0"
|
version = "0.12.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://docs.rs/tarpc"
|
documentation = "https://docs.rs/tarpc"
|
||||||
@@ -15,37 +15,38 @@ description = "An RPC framework for Rust with a focus on ease of use."
|
|||||||
travis-ci = { repository = "google/tarpc" }
|
travis-ci = { repository = "google/tarpc" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode = "0.8"
|
bincode = "1.0"
|
||||||
byteorder = "1.0"
|
byteorder = "1.0"
|
||||||
bytes = "0.4"
|
bytes = "0.4"
|
||||||
cfg-if = "0.1.0"
|
cfg-if = "0.1.0"
|
||||||
futures = "0.1.11"
|
futures = "0.1.11"
|
||||||
lazy_static = "0.2"
|
lazy_static = "1.0"
|
||||||
log = "0.3"
|
log = "0.4"
|
||||||
net2 = "0.2"
|
net2 = "0.2"
|
||||||
num_cpus = "1.0"
|
num_cpus = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
tarpc-plugins = { path = "src/plugins", version = "0.2.0" }
|
tarpc-plugins = { path = "src/plugins", version = "0.4.0" }
|
||||||
thread-pool = "0.1.1"
|
thread-pool = "0.1.1"
|
||||||
|
tokio-codec = "0.1"
|
||||||
tokio-core = "0.1.6"
|
tokio-core = "0.1.6"
|
||||||
tokio-io = "0.1"
|
tokio-io = "0.1"
|
||||||
tokio-proto = "0.1.1"
|
tokio-proto = "0.1.1"
|
||||||
tokio-service = "0.1"
|
tokio-service = "0.1"
|
||||||
|
|
||||||
# Optional dependencies
|
# Optional dependencies
|
||||||
native-tls = { version = "0.1.1", optional = true }
|
native-tls = { version = "0.1", optional = true }
|
||||||
tokio-tls = { version = "0.1", optional = true }
|
tokio-tls = { version = "0.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
env_logger = "0.4"
|
env_logger = "0.5"
|
||||||
futures-cpupool = "0.1"
|
futures-cpupool = "0.1"
|
||||||
clap = "2.0"
|
clap = "2.0"
|
||||||
serde_bytes = "0.10"
|
serde_bytes = "0.10"
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dev-dependencies]
|
[target.'cfg(target_os = "macos")'.dev-dependencies]
|
||||||
security-framework = "0.1"
|
security-framework = "0.2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -11,7 +11,7 @@ tarpc is an RPC framework for rust with a focus on ease of use. Defining a
|
|||||||
service can be done in just a few lines of code, and most of the boilerplate of
|
service can be done in just a few lines of code, and most of the boilerplate of
|
||||||
writing a server is taken care of for you.
|
writing a server is taken care of for you.
|
||||||
|
|
||||||
[Documentation](https://docs.rs/tarpc)
|
[Documentation](https://docs.rs/crate/tarpc/)
|
||||||
|
|
||||||
## What is an RPC framework?
|
## What is an RPC framework?
|
||||||
"RPC" stands for "Remote Procedure Call," a function call where the work of
|
"RPC" stands for "Remote Procedure Call," a function call where the work of
|
||||||
@@ -37,8 +37,8 @@ arguments to tarpc fns.
|
|||||||
Add to your `Cargo.toml` dependencies:
|
Add to your `Cargo.toml` dependencies:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
tarpc = "0.9.0"
|
tarpc = "0.12.0"
|
||||||
tarpc-plugins = "0.2.0"
|
tarpc-plugins = "0.4.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example: Sync
|
## Example: Sync
|
||||||
@@ -47,7 +47,7 @@ tarpc has two APIs: `sync` for blocking code and `future` for asynchronous
|
|||||||
code. Here's how to use the sync api.
|
code. Here's how to use the sync api.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -100,7 +100,7 @@ races! See the `tarpc_examples` package for more examples.
|
|||||||
Here's the same service, implemented using futures.
|
Here's the same service, implemented using futures.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
@@ -171,7 +171,7 @@ However, if you are working with both stream types, ensure that you use the TLS
|
|||||||
servers and TCP clients with TCP servers.
|
servers and TCP clients with TCP servers.
|
||||||
|
|
||||||
```rust,no_run
|
```rust,no_run
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
|
|||||||
10
RELEASES.md
10
RELEASES.md
@@ -1,3 +1,13 @@
|
|||||||
|
## 0.10.0 (2018-04-08)
|
||||||
|
|
||||||
|
## Breaking Changes
|
||||||
|
Fixed rustc breakage in tarpc-plugins. These changes require a recent version of rustc.
|
||||||
|
|
||||||
|
## 0.10.0 (2018-03-26)
|
||||||
|
|
||||||
|
## Breaking Changes
|
||||||
|
Updates bincode to version 1.0.
|
||||||
|
|
||||||
## 0.9.0 (2017-09-17)
|
## 0.9.0 (2017-09-17)
|
||||||
|
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, test, use_extern_macros)]
|
#![feature(plugin, test, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -38,7 +38,7 @@ impl FutureService for Server {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[bench]
|
#[bench]
|
||||||
fn latency(bencher: &mut Bencher) {
|
fn latency(bencher: &mut Bencher) {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let mut reactor = reactor::Core::new().unwrap();
|
let mut reactor = reactor::Core::new().unwrap();
|
||||||
let (handle, server) = Server
|
let (handle, server) = Server
|
||||||
.listen(
|
.listen(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(inclusive_range_syntax, conservative_impl_trait, plugin, never_type, use_extern_macros)]
|
#![feature(plugin, never_type, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
@@ -147,7 +147,7 @@ fn run_once(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let matches = App::new("Tarpc Concurrency")
|
let matches = App::new("Tarpc Concurrency")
|
||||||
.about(
|
.about(
|
||||||
"Demonstrates making concurrent requests to a tarpc service.",
|
"Demonstrates making concurrent requests to a tarpc service.",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
@@ -100,7 +100,7 @@ impl publisher::FutureService for Publisher {
|
|||||||
type SubscribeFut = Box<Future<Item = (), Error = Message>>;
|
type SubscribeFut = Box<Future<Item = (), Error = Message>>;
|
||||||
|
|
||||||
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
|
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
|
||||||
let clients = self.clients.clone();
|
let clients = Rc::clone(&self.clients);
|
||||||
Box::new(
|
Box::new(
|
||||||
subscriber::FutureClient::connect(address, client::Options::default())
|
subscriber::FutureClient::connect(address, client::Options::default())
|
||||||
.map(move |subscriber| {
|
.map(move |subscriber| {
|
||||||
@@ -117,12 +117,12 @@ impl publisher::FutureService for Publisher {
|
|||||||
fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut {
|
fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut {
|
||||||
println!("Unsubscribing {}", id);
|
println!("Unsubscribing {}", id);
|
||||||
self.clients.borrow_mut().remove(&id).unwrap();
|
self.clients.borrow_mut().remove(&id).unwrap();
|
||||||
futures::finished(()).boxed()
|
Box::new(futures::finished(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let mut reactor = reactor::Core::new().unwrap();
|
let mut reactor = reactor::Core::new().unwrap();
|
||||||
let (publisher_handle, server) = Publisher::new()
|
let (publisher_handle, server) = Publisher::new()
|
||||||
.listen(
|
.listen(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
// required by `FutureClient` (not used directly in this example)
|
// required by `FutureClient` (not used directly in this example)
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
@@ -14,7 +14,7 @@ extern crate tokio_core;
|
|||||||
|
|
||||||
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
|
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
|
||||||
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
|
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
|
||||||
use futures::{BoxFuture, Future, Stream};
|
use futures::{Future, Stream};
|
||||||
use tarpc::future::{client, server};
|
use tarpc::future::{client, server};
|
||||||
use tarpc::future::client::ClientExt as Fc;
|
use tarpc::future::client::ClientExt as Fc;
|
||||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||||
@@ -59,18 +59,17 @@ impl DoubleServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DoubleFutureService for DoubleServer {
|
impl DoubleFutureService for DoubleServer {
|
||||||
type DoubleFut = BoxFuture<i32, Message>;
|
type DoubleFut = Box<Future<Item=i32, Error=Message>>;
|
||||||
|
|
||||||
fn double(&self, x: i32) -> Self::DoubleFut {
|
fn double(&self, x: i32) -> Self::DoubleFut {
|
||||||
self.client
|
Box::new(self.client
|
||||||
.add(x, x)
|
.add(x, x)
|
||||||
.map_err(|e| e.to_string().into())
|
.map_err(|e| e.to_string().into()))
|
||||||
.boxed()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let mut reactor = reactor::Core::new().unwrap();
|
let mut reactor = reactor::Core::new().unwrap();
|
||||||
let (add, server) = AddServer
|
let (add, server) = AddServer
|
||||||
.listen(
|
.listen(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
@@ -61,7 +61,7 @@ impl DoubleSyncService for DoubleServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let handle = AddServer
|
let handle = AddServer
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -112,7 +112,7 @@ fn bench_tcp(target: u64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let _ = *BUF; // To non-lazily initialize it.
|
let _ = *BUF; // To non-lazily initialize it.
|
||||||
bench_tcp(256 << 20);
|
bench_tcp(256 << 20);
|
||||||
bench_tarpc(256 << 20);
|
bench_tarpc(256 << 20);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
#![feature(plugin, use_extern_macros)]
|
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
#![plugin(tarpc_plugins)]
|
#![plugin(tarpc_plugins)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -56,7 +56,7 @@ impl baz::FutureService for Baz {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let bar_client = {
|
let bar_client = {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
ideal_width = 100
|
|
||||||
reorder_imports = true
|
reorder_imports = true
|
||||||
|
|||||||
@@ -90,17 +90,18 @@ enum Reactor {
|
|||||||
|
|
||||||
impl fmt::Debug for Reactor {
|
impl fmt::Debug for Reactor {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
const HANDLE: &'static &'static str = &"Reactor::Handle";
|
const HANDLE: &str = "Reactor::Handle";
|
||||||
const HANDLE_INNER: &'static &'static str = &"Handle { .. }";
|
const HANDLE_INNER: &str = "Handle { .. }";
|
||||||
const REMOTE: &'static &'static str = &"Reactor::Remote";
|
const REMOTE: &str = "Reactor::Remote";
|
||||||
const REMOTE_INNER: &'static &'static str = &"Remote { .. }";
|
const REMOTE_INNER: &str = "Remote { .. }";
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Reactor::Handle(_) => f.debug_tuple(HANDLE).field(HANDLE_INNER).finish(),
|
Reactor::Handle(_) => f.debug_tuple(HANDLE).field(&HANDLE_INNER).finish(),
|
||||||
Reactor::Remote(_) => f.debug_tuple(REMOTE).field(REMOTE_INNER).finish(),
|
Reactor::Remote(_) => f.debug_tuple(REMOTE).field(&REMOTE_INNER).finish(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct Client<Req, Resp, E>
|
pub struct Client<Req, Resp, E>
|
||||||
where
|
where
|
||||||
@@ -159,7 +160,7 @@ where
|
|||||||
Resp: DeserializeOwned + Send + 'static,
|
Resp: DeserializeOwned + Send + 'static,
|
||||||
E: DeserializeOwned + Send + 'static,
|
E: DeserializeOwned + Send + 'static,
|
||||||
{
|
{
|
||||||
let inner = Proto::new(max_payload_size).bind_client(&handle, tcp);
|
let inner = Proto::new(max_payload_size).bind_client(handle, tcp);
|
||||||
Client { inner }
|
Client { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ impl Tracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment(&self) {
|
pub fn increment(&self) {
|
||||||
let _ = self.tx.send(Action::Increment);
|
let _ = self.tx.unbounded_send(Action::Increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrement(&self) {
|
pub fn decrement(&self) {
|
||||||
debug!("Closing connection");
|
debug!("Closing connection");
|
||||||
let _ = self.tx.send(Action::Decrement);
|
let _ = self.tx.unbounded_send(Action::Decrement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ impl fmt::Debug for Acceptor {
|
|||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::Acceptor::*;
|
use self::Acceptor::*;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
const TLS: &'static &'static str = &"TlsAcceptor { .. }";
|
const TLS: &str = "TlsAcceptor { .. }";
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Tcp => fmt.debug_tuple("Acceptor::Tcp").finish(),
|
Tcp => fmt.debug_tuple("Acceptor::Tcp").finish(),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
Tls(_) => fmt.debug_tuple("Acceptlr::Tls").field(TLS).finish(),
|
Tls(_) => fmt.debug_tuple("Acceptor::Tls").field(&TLS).finish(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,18 +223,18 @@ impl Options {
|
|||||||
impl fmt::Debug for Options {
|
impl fmt::Debug for Options {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
const SOME: &'static &'static str = &"Some(_)";
|
const SOME: &str = "Some(_)";
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
const NONE: &'static &'static str = &"None";
|
const NONE: &str = "None";
|
||||||
|
|
||||||
let mut debug_struct = fmt.debug_struct("Options");
|
let mut debug_struct = fmt.debug_struct("Options");
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
debug_struct.field(
|
debug_struct.field(
|
||||||
"tls_acceptor",
|
"tls_acceptor",
|
||||||
if self.tls_acceptor.is_some() {
|
if self.tls_acceptor.is_some() {
|
||||||
SOME
|
&SOME
|
||||||
} else {
|
} else {
|
||||||
NONE
|
&NONE
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
debug_struct.finish()
|
debug_struct.finish()
|
||||||
@@ -352,9 +352,8 @@ where
|
|||||||
St: fmt::Debug,
|
St: fmt::Debug,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
const HANDLE: &'static &'static str = &"Handle { .. }";
|
|
||||||
f.debug_struct("BindStream")
|
f.debug_struct("BindStream")
|
||||||
.field("handle", HANDLE)
|
.field("handle", &self.handle)
|
||||||
.field("new_service", &self.new_service)
|
.field("new_service", &self.new_service)
|
||||||
.field("stream", &self.stream)
|
.field("stream", &self.stream)
|
||||||
.finish()
|
.finish()
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ impl Shutdown {
|
|||||||
/// The returned future resolves when the server is completely shut down.
|
/// The returned future resolves when the server is completely shut down.
|
||||||
pub fn shutdown(&self) -> ShutdownFuture {
|
pub fn shutdown(&self) -> ShutdownFuture {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
let inner = if let Err(_) = self.tx.send(tx) {
|
let inner = if self.tx.unbounded_send(tx).is_err() {
|
||||||
trace!("Server already initiated shutdown.");
|
trace!("Server already initiated shutdown.");
|
||||||
futures::Either::A(futures::ok(()))
|
futures::Either::A(futures::ok(()))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
//! Example usage:
|
//! Example usage:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! #![feature(plugin, use_extern_macros)]
|
//! #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
//! #![plugin(tarpc_plugins)]
|
//! #![plugin(tarpc_plugins)]
|
||||||
//!
|
//!
|
||||||
//! #[macro_use]
|
//! #[macro_use]
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
//! Example usage with TLS:
|
//! Example usage with TLS:
|
||||||
//!
|
//!
|
||||||
//! ```no-run
|
//! ```no-run
|
||||||
//! #![feature(plugin, use_extern_macros)]
|
//! #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
//! #![plugin(tarpc_plugins)]
|
//! #![plugin(tarpc_plugins)]
|
||||||
//!
|
//!
|
||||||
//! #[macro_use]
|
//! #[macro_use]
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
|
|
||||||
#![deny(missing_docs, missing_debug_implementations)]
|
#![deny(missing_docs, missing_debug_implementations)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![cfg_attr(test, feature(plugin, use_extern_macros))]
|
#![cfg_attr(test, feature(plugin, use_extern_macros, proc_macro_path_invoc))]
|
||||||
#![cfg_attr(test, plugin(tarpc_plugins))]
|
#![cfg_attr(test, plugin(tarpc_plugins))]
|
||||||
|
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
@@ -130,6 +130,7 @@ extern crate log;
|
|||||||
extern crate net2;
|
extern crate net2;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
extern crate thread_pool;
|
extern crate thread_pool;
|
||||||
|
extern crate tokio_codec;
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ macro_rules! as_item {
|
|||||||
/// Rpc methods are specified, mirroring trait syntax:
|
/// Rpc methods are specified, mirroring trait syntax:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(plugin, use_extern_macros)]
|
/// # #![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
|
||||||
/// # #![plugin(tarpc_plugins)]
|
/// # #![plugin(tarpc_plugins)]
|
||||||
/// # #[macro_use] extern crate tarpc;
|
/// # #[macro_use] extern crate tarpc;
|
||||||
/// # fn main() {}
|
/// # fn main() {}
|
||||||
@@ -593,7 +593,7 @@ mod functional_test {
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "tls")] {
|
if #[cfg(feature = "tls")] {
|
||||||
const DOMAIN: &'static str = "foobar.com";
|
const DOMAIN: &str = "foobar.com";
|
||||||
|
|
||||||
use tls::client::Context;
|
use tls::client::Context;
|
||||||
use native_tls::{Pkcs12, TlsAcceptor, TlsConnector};
|
use native_tls::{Pkcs12, TlsAcceptor, TlsConnector};
|
||||||
@@ -634,7 +634,7 @@ mod functional_test {
|
|||||||
let buf = include_bytes!("../test/root-ca.der");
|
let buf = include_bytes!("../test/root-ca.der");
|
||||||
let cert = unwrap!(Certificate::from_der(buf));
|
let cert = unwrap!(Certificate::from_der(buf));
|
||||||
let mut connector = unwrap!(TlsConnector::builder());
|
let mut connector = unwrap!(TlsConnector::builder());
|
||||||
connector.add_root_certificate(cert);
|
connector.add_root_certificate(cert).unwrap();
|
||||||
|
|
||||||
Context {
|
Context {
|
||||||
domain: DOMAIN.into(),
|
domain: DOMAIN.into(),
|
||||||
@@ -657,7 +657,6 @@ mod functional_test {
|
|||||||
fn get_tls_client_context() -> Context {
|
fn get_tls_client_context() -> Context {
|
||||||
let mut connector = unwrap!(TlsConnector::builder());
|
let mut connector = unwrap!(TlsConnector::builder());
|
||||||
unwrap!(connector.builder_mut()
|
unwrap!(connector.builder_mut()
|
||||||
.builder_mut()
|
|
||||||
.set_ca_file("test/root-ca.pem"));
|
.set_ca_file("test/root-ca.pem"));
|
||||||
Context {
|
Context {
|
||||||
domain: DOMAIN.into(),
|
domain: DOMAIN.into(),
|
||||||
@@ -850,7 +849,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, client, _) =
|
let (_, client, _) =
|
||||||
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
||||||
assert_eq!(3, client.add(1, 2).unwrap());
|
assert_eq!(3, client.add(1, 2).unwrap());
|
||||||
@@ -861,7 +860,7 @@ mod functional_test {
|
|||||||
fn shutdown() {
|
fn shutdown() {
|
||||||
use futures::{Async, Future};
|
use futures::{Async, Future};
|
||||||
|
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (addr, client, shutdown) =
|
let (addr, client, shutdown) =
|
||||||
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
||||||
assert_eq!(3, unwrap!(client.add(1, 2)));
|
assert_eq!(3, unwrap!(client.add(1, 2)));
|
||||||
@@ -897,7 +896,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_shutdown() {
|
fn no_shutdown() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (addr, client, shutdown) =
|
let (addr, client, shutdown) =
|
||||||
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
unwrap!(start_server_with_sync_client::<SyncClient, Server>(Server));
|
||||||
assert_eq!(3, client.add(1, 2).unwrap());
|
assert_eq!(3, client.add(1, 2).unwrap());
|
||||||
@@ -913,7 +912,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn other_service() {
|
fn other_service() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, client, _) = unwrap!(start_server_with_sync_client::<
|
let (_, client, _) = unwrap!(start_server_with_sync_client::<
|
||||||
super::other_service::SyncClient,
|
super::other_service::SyncClient,
|
||||||
Server,
|
Server,
|
||||||
@@ -989,7 +988,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, mut reactor, client) = unwrap!(
|
let (_, mut reactor, client) = unwrap!(
|
||||||
start_server_with_async_client::<FutureClient, Server>(Server)
|
start_server_with_async_client::<FutureClient, Server>(Server)
|
||||||
);
|
);
|
||||||
@@ -1005,7 +1004,7 @@ mod functional_test {
|
|||||||
use futures::Future;
|
use futures::Future;
|
||||||
use tokio_core::reactor;
|
use tokio_core::reactor;
|
||||||
|
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (handle, mut reactor, server) = unwrap!(return_server::<Server>(Server));
|
let (handle, mut reactor, server) = unwrap!(return_server::<Server>(Server));
|
||||||
|
|
||||||
let (tx, rx) = ::std::sync::mpsc::channel();
|
let (tx, rx) = ::std::sync::mpsc::channel();
|
||||||
@@ -1027,7 +1026,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concurrent() {
|
fn concurrent() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, mut reactor, client) = unwrap!(
|
let (_, mut reactor, client) = unwrap!(
|
||||||
start_server_with_async_client::<FutureClient, Server>(Server)
|
start_server_with_async_client::<FutureClient, Server>(Server)
|
||||||
);
|
);
|
||||||
@@ -1041,7 +1040,7 @@ mod functional_test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn other_service() {
|
fn other_service() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, mut reactor, client) = unwrap!(start_server_with_async_client::<
|
let (_, mut reactor, client) = unwrap!(start_server_with_async_client::<
|
||||||
super::other_service::FutureClient,
|
super::other_service::FutureClient,
|
||||||
Server,
|
Server,
|
||||||
@@ -1058,7 +1057,7 @@ mod functional_test {
|
|||||||
use future::server;
|
use future::server;
|
||||||
use super::FutureServiceExt;
|
use super::FutureServiceExt;
|
||||||
|
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let reactor = reactor::Core::new().unwrap();
|
let reactor = reactor::Core::new().unwrap();
|
||||||
let handle = Server
|
let handle = Server
|
||||||
.listen(
|
.listen(
|
||||||
@@ -1080,7 +1079,7 @@ mod functional_test {
|
|||||||
use util::FirstSocketAddr;
|
use util::FirstSocketAddr;
|
||||||
use super::{FutureClient, FutureServiceExt};
|
use super::{FutureClient, FutureServiceExt};
|
||||||
|
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let mut reactor = reactor::Core::new().unwrap();
|
let mut reactor = reactor::Core::new().unwrap();
|
||||||
let (handle, server) = Server
|
let (handle, server) = Server
|
||||||
.listen(
|
.listen(
|
||||||
@@ -1115,7 +1114,7 @@ mod functional_test {
|
|||||||
use future::client::ClientExt;
|
use future::client::ClientExt;
|
||||||
use super::FutureServiceExt;
|
use super::FutureServiceExt;
|
||||||
|
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
let (_, mut reactor, client) = unwrap!(
|
let (_, mut reactor, client) = unwrap!(
|
||||||
start_server_with_async_client::<FutureClient, Server>(Server)
|
start_server_with_async_client::<FutureClient, Server>(Server)
|
||||||
);
|
);
|
||||||
@@ -1167,7 +1166,7 @@ mod functional_test {
|
|||||||
fn error() {
|
fn error() {
|
||||||
use std::error::Error as E;
|
use std::error::Error as E;
|
||||||
use self::error_service::*;
|
use self::error_service::*;
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
let (_, mut reactor, client) =
|
let (_, mut reactor, client) =
|
||||||
start_err_server_with_async_client::<FutureClient, ErrorServer>(ErrorServer).unwrap();
|
start_err_server_with_async_client::<FutureClient, ErrorServer>(ErrorServer).unwrap();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tarpc-plugins"
|
name = "tarpc-plugins"
|
||||||
version = "0.2.0"
|
version = "0.4.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://docs.rs/tarpc"
|
documentation = "https://docs.rs/tarpc"
|
||||||
@@ -15,7 +15,7 @@ description = "Plugins for tarpc, an RPC framework for Rust with a focus on ease
|
|||||||
travis-ci = { repository = "google/tarpc" }
|
travis-ci = { repository = "google/tarpc" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
itertools = "0.6"
|
itertools = "0.7"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
plugin = true
|
plugin = true
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use itertools::Itertools;
|
|||||||
use rustc_plugin::Registry;
|
use rustc_plugin::Registry;
|
||||||
use syntax::ast::{self, Ident, TraitRef, Ty, TyKind};
|
use syntax::ast::{self, Ident, TraitRef, Ty, TyKind};
|
||||||
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
|
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
|
||||||
use syntax::ext::quote::rt::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::parse::{self, token, str_lit, PResult};
|
use syntax::parse::{self, token, str_lit, PResult};
|
||||||
use syntax::parse::parser::{Parser, PathStyle};
|
use syntax::parse::parser::{Parser, PathStyle};
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
@@ -126,7 +126,7 @@ fn ty_snake_to_camel(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacRe
|
|||||||
convert(&mut path.segments
|
convert(&mut path.segments
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.identifier);
|
.ident);
|
||||||
MacEager::ty(P(Ty {
|
MacEager::ty(P(Ty {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: TyKind::Path(None, path),
|
node: TyKind::Path(None, path),
|
||||||
@@ -160,10 +160,8 @@ fn convert(ident: &mut Ident) -> String {
|
|||||||
while let Some(c) = chars.next() {
|
while let Some(c) = chars.next() {
|
||||||
if c != '_' {
|
if c != '_' {
|
||||||
camel_ty.push(c);
|
camel_ty.push(c);
|
||||||
} else {
|
} else if let Some(c) = chars.next() {
|
||||||
if let Some(c) = chars.next() {
|
camel_ty.extend(c.to_uppercase());
|
||||||
camel_ty.extend(c.to_uppercase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
// Licensed under the MIT License, <LICENSE or http://opensource.org/licenses/MIT>.
|
||||||
// This file may not be copied, modified, or distributed except according to those terms.
|
// This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
use bincode::{self, Infinite};
|
use bincode;
|
||||||
use byteorder::{BigEndian, ReadBytesExt};
|
use byteorder::{BigEndian, ByteOrder};
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use bytes::buf::BufMut;
|
use bytes::buf::BufMut;
|
||||||
use serde;
|
use serde;
|
||||||
use std::io::{self, Cursor};
|
use std::io;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_io::codec::{Encoder, Decoder, Framed};
|
use tokio_codec::{Encoder, Decoder, Framed};
|
||||||
use tokio_proto::multiplex::{ClientProto, ServerProto};
|
use tokio_proto::multiplex::{ClientProto, ServerProto};
|
||||||
use tokio_proto::streaming::multiplex::RequestId;
|
use tokio_proto::streaming::multiplex::RequestId;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ enum CodecState {
|
|||||||
impl<Encode, Decode> Codec<Encode, Decode> {
|
impl<Encode, Decode> Codec<Encode, Decode> {
|
||||||
fn new(max_payload_size: u64) -> Self {
|
fn new(max_payload_size: u64) -> Self {
|
||||||
Codec {
|
Codec {
|
||||||
max_payload_size: max_payload_size,
|
max_payload_size,
|
||||||
state: CodecState::Id,
|
state: CodecState::Id,
|
||||||
_phantom_data: PhantomData,
|
_phantom_data: PhantomData,
|
||||||
}
|
}
|
||||||
@@ -66,16 +66,18 @@ where
|
|||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn encode(&mut self, (id, message): Self::Item, buf: &mut BytesMut) -> io::Result<()> {
|
fn encode(&mut self, (id, message): Self::Item, buf: &mut BytesMut) -> io::Result<()> {
|
||||||
let payload_size = bincode::serialized_size(&message);
|
let payload_size = bincode::serialized_size(&message).map_err(|serialize_err| {
|
||||||
|
io::Error::new(io::ErrorKind::Other, serialize_err)
|
||||||
|
})?;
|
||||||
if payload_size > self.max_payload_size {
|
if payload_size > self.max_payload_size {
|
||||||
return Err(too_big(payload_size, self.max_payload_size));
|
return Err(too_big(payload_size, self.max_payload_size));
|
||||||
}
|
}
|
||||||
let message_size = 2 * mem::size_of::<u64>() + payload_size as usize;
|
let message_size = 2 * mem::size_of::<u64>() + payload_size as usize;
|
||||||
buf.reserve(message_size);
|
buf.reserve(message_size);
|
||||||
buf.put_u64::<BigEndian>(id);
|
buf.put_u64_be(id);
|
||||||
trace!("Encoded request id = {} as {:?}", id, buf);
|
trace!("Encoded request id = {} as {:?}", id, buf);
|
||||||
buf.put_u64::<BigEndian>(payload_size);
|
buf.put_u64_be(payload_size);
|
||||||
bincode::serialize_into(&mut buf.writer(), &message, Infinite)
|
bincode::serialize_into(&mut buf.writer(), &message)
|
||||||
.map_err(|serialize_err| {
|
.map_err(|serialize_err| {
|
||||||
io::Error::new(io::ErrorKind::Other, serialize_err)
|
io::Error::new(io::ErrorKind::Other, serialize_err)
|
||||||
})?;
|
})?;
|
||||||
@@ -103,9 +105,9 @@ where
|
|||||||
}
|
}
|
||||||
Id => {
|
Id => {
|
||||||
let mut id_buf = buf.split_to(mem::size_of::<u64>());
|
let mut id_buf = buf.split_to(mem::size_of::<u64>());
|
||||||
let id = Cursor::new(&mut id_buf).read_u64::<BigEndian>()?;
|
let id = BigEndian::read_u64(&*id_buf);
|
||||||
trace!("--> Parsed id = {} from {:?}", id, id_buf);
|
trace!("--> Parsed id = {} from {:?}", id, id_buf);
|
||||||
self.state = Len { id: id };
|
self.state = Len { id };
|
||||||
}
|
}
|
||||||
Len { .. } if buf.len() < mem::size_of::<u64>() => {
|
Len { .. } if buf.len() < mem::size_of::<u64>() => {
|
||||||
trace!(
|
trace!(
|
||||||
@@ -116,7 +118,7 @@ where
|
|||||||
}
|
}
|
||||||
Len { id } => {
|
Len { id } => {
|
||||||
let len_buf = buf.split_to(mem::size_of::<u64>());
|
let len_buf = buf.split_to(mem::size_of::<u64>());
|
||||||
let len = Cursor::new(len_buf).read_u64::<BigEndian>()?;
|
let len = BigEndian::read_u64(&*len_buf);
|
||||||
trace!(
|
trace!(
|
||||||
"--> Parsed payload length = {}, remaining buffer length = {}",
|
"--> Parsed payload length = {}, remaining buffer length = {}",
|
||||||
len,
|
len,
|
||||||
@@ -125,7 +127,7 @@ where
|
|||||||
if len > self.max_payload_size {
|
if len > self.max_payload_size {
|
||||||
return Err(too_big(len, self.max_payload_size));
|
return Err(too_big(len, self.max_payload_size));
|
||||||
}
|
}
|
||||||
self.state = Payload { id: id, len: len };
|
self.state = Payload { id, len };
|
||||||
}
|
}
|
||||||
Payload { len, .. } if buf.len() < len as usize => {
|
Payload { len, .. } if buf.len() < len as usize => {
|
||||||
trace!(
|
trace!(
|
||||||
@@ -137,7 +139,7 @@ where
|
|||||||
}
|
}
|
||||||
Payload { id, len } => {
|
Payload { id, len } => {
|
||||||
let payload = buf.split_to(len as usize);
|
let payload = buf.split_to(len as usize);
|
||||||
let result = bincode::deserialize_from(&mut Cursor::new(payload), Infinite);
|
let result = bincode::deserialize(&payload);
|
||||||
// Reset the state machine because, either way, we're done processing this
|
// Reset the state machine because, either way, we're done processing this
|
||||||
// message.
|
// message.
|
||||||
self.state = Id;
|
self.state = Id;
|
||||||
@@ -178,7 +180,7 @@ where
|
|||||||
type BindTransport = Result<Self::Transport, io::Error>;
|
type BindTransport = Result<Self::Transport, io::Error>;
|
||||||
|
|
||||||
fn bind_transport(&self, io: T) -> Self::BindTransport {
|
fn bind_transport(&self, io: T) -> Self::BindTransport {
|
||||||
Ok(io.framed(Codec::new(self.max_payload_size)))
|
Ok(Framed::new(io, Codec::new(self.max_payload_size)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +196,7 @@ where
|
|||||||
type BindTransport = Result<Self::Transport, io::Error>;
|
type BindTransport = Result<Self::Transport, io::Error>;
|
||||||
|
|
||||||
fn bind_transport(&self, io: T) -> Self::BindTransport {
|
fn bind_transport(&self, io: T) -> Self::BindTransport {
|
||||||
Ok(io.framed(Codec::new(self.max_payload_size)))
|
Ok(Framed::new(io, Codec::new(self.max_payload_size)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ impl<Req, Resp, E> Clone for Client<Req, Resp, E> {
|
|||||||
|
|
||||||
impl<Req, Resp, E> fmt::Debug for Client<Req, Resp, E> {
|
impl<Req, Resp, E> fmt::Debug for Client<Req, Resp, E> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
const PROXY: &'static &'static str = &"ClientProxy { .. }";
|
const PROXY: &str = "ClientProxy { .. }";
|
||||||
f.debug_struct("Client").field("proxy", PROXY).finish()
|
f.debug_struct("Client").field("proxy", &PROXY).finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +93,11 @@ impl Options {
|
|||||||
impl fmt::Debug for Options {
|
impl fmt::Debug for Options {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
const SOME: &'static &'static str = &"Some(_)";
|
const SOME: &str = "Some(_)";
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
const NONE: &'static &'static str = &"None";
|
const NONE: &str = "None";
|
||||||
let mut f = f.debug_struct("Options");
|
let mut f = f.debug_struct("Options");
|
||||||
#[cfg(feature = "tls")] f.field("tls_ctx", if self.tls_ctx.is_some() { SOME } else { NONE });
|
#[cfg(feature = "tls")] f.field("tls_ctx", if self.tls_ctx.is_some() { &SOME } else { &NONE });
|
||||||
f.finish()
|
f.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,13 +89,12 @@ impl Handle {
|
|||||||
|
|
||||||
impl fmt::Debug for Handle {
|
impl fmt::Debug for Handle {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
const CORE: &'static &'static str = &"Core { .. }";
|
const SERVER: &str = "Box<Future<Item = (), Error = ()>>";
|
||||||
const SERVER: &'static &'static str = &"Box<Future<Item = (), Error = ()>>";
|
|
||||||
|
|
||||||
f.debug_struct("Handle")
|
f.debug_struct("Handle")
|
||||||
.field("reactor", CORE)
|
.field("reactor", &self.reactor)
|
||||||
.field("handle", &self.handle)
|
.field("handle", &self.handle)
|
||||||
.field("server", SERVER)
|
.field("server", &SERVER)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ pub mod client {
|
|||||||
|
|
||||||
impl fmt::Debug for Context {
|
impl fmt::Debug for Context {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
const TLS_CONNECTOR: &'static &'static str = &"TlsConnector { .. }";
|
const TLS_CONNECTOR: &str = "TlsConnector { .. }";
|
||||||
f.debug_struct("Context")
|
f.debug_struct("Context")
|
||||||
.field("domain", &self.domain)
|
.field("domain", &self.domain)
|
||||||
.field("tls_connector", TLS_CONNECTOR)
|
.field("tls_connector", &TLS_CONNECTOR)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user