- gras_dynar_foreach(list->cbs,cpt,cb) {
- if (cb(expeditor,msgtype->ctn_type,payload)) {
- /* cb handled the message */
- return no_error;
+ ctx.expeditor = msg.expe;
+ ctx.ID = msg.ID;
+ ctx.msgtype = msg.type;
+
+ switch (msg.kind) {
+ case e_gras_msg_kind_oneway:
+ case e_gras_msg_kind_rpccall:
+ ran_ok=0;
+ TRY {
+ xbt_dynar_foreach(list->cbs,cpt,cb) {
+ if (!ran_ok) {
+ VERB3("Use the callback #%d (@%p) for incomming msg %s",
+ cpt+1,cb,msg.type->name);
+ if ((*cb)(&ctx,msg.payl)) {
+ /* cb handled the message */
+ free(msg.payl);
+ ran_ok = 1;
+ }
+ }
+ }
+ } CATCH(e) {
+ free(msg.payl);
+ if (msg.type->kind == e_gras_msg_kind_rpccall) {
+ /* The callback raised an exception, propagate it on the network */
+ if (!e.remote) { /* the exception is born on this machine */
+ e.host = (char*)gras_os_myname();
+ xbt_ex_setup_backtrace(&e);
+ }
+ VERB4("Propagate %s exception from '%s' RPC cb back to %s:%d",
+ (e.remote ? "remote" : "local"),
+ msg.type->name,
+ gras_socket_peer_name(msg.expe),
+ gras_socket_peer_port(msg.expe));
+ gras_msg_send_ext(msg.expe, e_gras_msg_kind_rpcerror,
+ msg.ID, msg.type, &e);
+ xbt_ex_free(e);
+ ran_ok=1;
+ } else {
+ RETHROW0("Callback raised an exception: %s");
+ }