mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-02-23 15:49:54 +01:00
Change module structure. (#122)
* Change `client::{future, sync}, server::{future, sync}` to `future::{client, server}, sync::{client, server}`
This reflects the most common usage pattern and allows for some types to not need to be fully qualified when used together (e.g. the previously-named `client::future::Options` and `server::future::Options` can now be `client::Options` and `server::Options`).
* sync::client: create a RequestHandler struct to encapsulate logic of processing client requests.
The largest benefit is that unit testing becomes easier, e.g. testing that the request processing stops when all request senders are dropped.
* Rename Serialize error variants to make sense.
* Rename tarpc_service_ConnectFuture__ => Connect (because it's public)
* Use tokio proto's ClientProxy.
Rather than reimplement the same logic. Curiously, this commit
isn't a net loss in LOC. Oh well.
* Factor out os-specific functionality in listener() into their own fns
* Remove service-fn dep
This commit is contained in:
@@ -25,8 +25,8 @@ use std::{cmp, thread};
|
||||
use std::sync::{Arc, mpsc};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::future::ClientExt;
|
||||
use tarpc::future::{client, server};
|
||||
use tarpc::future::client::ClientExt;
|
||||
use tarpc::util::{FirstSocketAddr, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ use std::rc::Rc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use subscriber::FutureServiceExt as SubscriberExt;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::future::ClientExt;
|
||||
use tarpc::future::{client, server};
|
||||
use tarpc::future::client::ClientExt;
|
||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
@@ -61,7 +61,7 @@ impl Subscriber {
|
||||
fn listen(id: u32,
|
||||
handle: &reactor::Handle,
|
||||
options: server::Options)
|
||||
-> server::future::Handle {
|
||||
-> server::Handle {
|
||||
let (server_handle, server) = Subscriber { id: id }
|
||||
.listen("localhost:0".first_socket_addr(), handle, options)
|
||||
.unwrap();
|
||||
|
||||
@@ -17,8 +17,8 @@ use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::sync::ClientExt;
|
||||
use tarpc::sync::{client, server};
|
||||
use tarpc::sync::client::ClientExt;
|
||||
|
||||
service! {
|
||||
rpc hello(name: String) -> String | NoNameGiven;
|
||||
|
||||
@@ -12,8 +12,8 @@ extern crate tarpc;
|
||||
extern crate tokio_core;
|
||||
|
||||
use futures::Future;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::future::ClientExt;
|
||||
use tarpc::future::{client, server};
|
||||
use tarpc::future::client::ClientExt;
|
||||
use tarpc::util::{FirstSocketAddr, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ extern crate tokio_core;
|
||||
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::sync::ClientExt;
|
||||
use tarpc::sync::{client, server};
|
||||
use tarpc::sync::client::ClientExt;
|
||||
use tarpc::util::Never;
|
||||
|
||||
service! {
|
||||
|
||||
@@ -15,8 +15,8 @@ extern crate tokio_core;
|
||||
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
|
||||
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
|
||||
use futures::{BoxFuture, Future, Stream};
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::future::ClientExt as Fc;
|
||||
use tarpc::future::{client, server};
|
||||
use tarpc::future::client::ClientExt as Fc;
|
||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ use add::{SyncService as AddSyncService, SyncServiceExt as AddExt};
|
||||
use double::{SyncService as DoubleSyncService, SyncServiceExt as DoubleExt};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::sync::ClientExt as Fc;
|
||||
use tarpc::sync::{client, server};
|
||||
use tarpc::sync::client::ClientExt as Fc;
|
||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||
|
||||
pub mod add {
|
||||
@@ -69,7 +69,8 @@ fn main() {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
thread::spawn(move || {
|
||||
let handle = AddServer.listen("localhost:0".first_socket_addr(),
|
||||
server::Options::default()).unwrap();
|
||||
server::Options::default())
|
||||
.unwrap();
|
||||
tx.send(handle.addr()).unwrap();
|
||||
handle.run();
|
||||
});
|
||||
@@ -80,7 +81,8 @@ fn main() {
|
||||
thread::spawn(move || {
|
||||
let add_client = add::SyncClient::connect(add, client::Options::default()).unwrap();
|
||||
let handle = DoubleServer::new(add_client)
|
||||
.listen("localhost:0".first_socket_addr(), server::Options::default())
|
||||
.listen("localhost:0".first_socket_addr(),
|
||||
server::Options::default())
|
||||
.unwrap();
|
||||
tx.send(handle.addr()).unwrap();
|
||||
handle.run();
|
||||
|
||||
@@ -21,8 +21,8 @@ use std::sync::Arc;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::sync::ClientExt;
|
||||
use tarpc::future::server;
|
||||
use tarpc::sync::client::{self, ClientExt};
|
||||
use tarpc::util::{FirstSocketAddr, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
|
||||
@@ -19,8 +19,9 @@ use bar::FutureServiceExt as BarExt;
|
||||
use baz::FutureServiceExt as BazExt;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use tarpc::{client, server};
|
||||
use tarpc::client::sync::ClientExt;
|
||||
use tarpc::future::server;
|
||||
use tarpc::sync::client;
|
||||
use tarpc::sync::client::ClientExt;
|
||||
use tarpc::util::{FirstSocketAddr, Never};
|
||||
use tokio_core::reactor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user