Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user exception #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/rs/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ macro_rules! service_client {
macro_rules! service_client_methods {
(methods = [$($iname:ident -> $oname:ident = $fname:ident.$mname:ident($($aname:ident: $aty:ty => $aid:expr,)*) -> $rty:ty => $enname:ident = [$($evname:ident($ename:ident: $ety:ty => $eid:expr),)*] ($rrty:ty),)*]) => {
$(pub fn $mname(&mut self, $($aname: $aty,)*) -> $crate::Result<$rrty> {
#[allow(unused_imports)]
use $crate::protocol::Decode;
static MNAME: &'static str = stringify!($mname);

let mut args = $iname::default();
Expand All @@ -182,8 +184,21 @@ macro_rules! service_client_methods {
MNAME, $crate::protocol::MessageType::Call, &mut args, 0));

let mut result = $oname::default();
try!($crate::protocol::helpers::receive(&mut self.protocol, &mut self.transport,
MNAME, &mut result));
let (name, ty, id) = try!(self.protocol.read_message_begin(&mut self.transport));
if ty == $crate::protocol::MessageType::Exception {
// receive exception in ename, but use id to identify which one
// println!("name:{}, ty:{}, id:{}", name, ty, id);
match id + 1 {
$( $eid => { let mut arg: $ety = Default::default();
try!(arg.decode(&mut self.protocol, &mut self.transport));
try!(self.protocol.read_message_end(&mut self.transport));
result.$ename = Some(arg); } ),*
_ => return Err($crate::Error::from($crate::protocol::Error::ProtocolViolation))
}
} else {
try!($crate::protocol::helpers::receive_body(&mut self.protocol, &mut self.transport,
MNAME, &mut result, &name, ty, id));
}

let result = service_client_methods_translate_result!(
result, $enname = [$($evname($ename: $ety => $eid),)*]);
Expand Down
4 changes: 2 additions & 2 deletions lib/rs/src/server/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::thread;

use transport::server::TransportServer;
use transport::Transport;
use protocol::{Protocol, ProtocolFactory};
use protocol::ProtocolFactory;
use processor::Processor;

pub struct ThreadedServer<P, PF, TS> {
Expand Down Expand Up @@ -58,7 +58,7 @@ where P: Processor<PF::Protocol, TS::Transport> + Send + Sync + 'static,

let (supervisor_tx, supervisor_rx) = mpsc::channel();

for _ in (0..threads) {
for _ in 0..threads {
self.spawn_with_supervisor(supervisor_tx.clone());
}

Expand Down