WIP multiplex Parse/Serialize/FramedIo impls

This commit is contained in:
Tim Kuehn
2016-09-15 02:38:07 -07:00
parent 8c0181633d
commit 20d1a019ae
16 changed files with 525 additions and 603 deletions

View File

@@ -59,7 +59,7 @@ fn run_once(clients: &[FutureClient], concurrency: u32, print: bool) {
.take(concurrency as usize)
.map(|client| {
let start = SystemTime::now();
let future = client.read(&CHUNK_SIZE).map(move |_| start.elapsed().unwrap());
let future = client.read(CHUNK_SIZE).map(move |_| start.elapsed().unwrap());
thread::yield_now();
future
})

View File

@@ -65,7 +65,7 @@ impl Subscriber {
.listen("localhost:0")
.wait()
.unwrap();
publisher.subscribe(&id, &subscriber.local_addr()).unwrap();
publisher.subscribe(id, *subscriber.local_addr()).unwrap();
subscriber
}
}
@@ -90,7 +90,7 @@ impl publisher::FutureService for Publisher {
.unwrap()
.values()
// Ignore failing subscribers.
.map(move |client| client.receive(&message).then(|_| Ok(())))
.map(move |client| client.receive(message.clone()).then(|_| Ok(())))
.collect::<Vec<_>>())
.map(|_| ())
.boxed()
@@ -127,8 +127,8 @@ fn main() {
let _subscriber2 = Subscriber::new(1, publisher.clone());
println!("Broadcasting...");
publisher.broadcast(&"hello to all".to_string()).unwrap();
publisher.unsubscribe(&1).unwrap();
publisher.broadcast(&"hello again".to_string()).unwrap();
publisher.broadcast("hello to all".to_string()).unwrap();
publisher.unsubscribe(1).unwrap();
publisher.broadcast("hello again".to_string()).unwrap();
thread::sleep(Duration::from_millis(300));
}

View File

@@ -30,5 +30,5 @@ fn main() {
let addr = "localhost:10000";
let _server = HelloServer.listen(addr);
let client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello(&"Mom".to_string()).unwrap());
println!("{}", client.hello("Mom".to_string()).unwrap());
}

View File

@@ -52,6 +52,6 @@ fn main() {
let addr = "localhost:10000";
let _server = HelloServer.listen(addr);
let client = SyncClient::connect(addr).unwrap();
println!("{}", client.hello(&"Mom".to_string()).unwrap());
println!("{}", client.hello(&"".to_string()).unwrap_err());
println!("{}", client.hello("Mom".to_string()).unwrap());
println!("{}", client.hello("".to_string()).unwrap_err());
}

View File

@@ -54,7 +54,7 @@ impl DoubleFutureService for DoubleServer {
fn double(&self, x: i32) -> Self::DoubleFut {
self.client
.add(&x, &x)
.add(x, x)
.map_err(|e| e.to_string().into())
.boxed()
}
@@ -68,6 +68,6 @@ fn main() {
let double_client = double::SyncClient::connect(double.local_addr()).unwrap();
for i in 0..5 {
println!("{:?}", double_client.double(&i).unwrap());
println!("{:?}", double_client.double(i).unwrap());
}
}

View File

@@ -63,14 +63,14 @@ fn main() {
let bar_client = bar::SyncClient::connect(bar.local_addr()).unwrap();
let baz_client = baz::SyncClient::connect(baz.local_addr()).unwrap();
info!("Result: {:?}", bar_client.bar(&17));
info!("Result: {:?}", bar_client.bar(17));
let total = 20;
for i in 1..(total + 1) {
if i % 2 == 0 {
info!("Result 1: {:?}", bar_client.bar(&i));
info!("Result 1: {:?}", bar_client.bar(i));
} else {
info!("Result 2: {:?}", baz_client.baz(&i.to_string()));
info!("Result 2: {:?}", baz_client.baz(i.to_string()));
}
}