-
- } else {
- /* select timeouted, and no timer elapsed. Nothing to do */
- THROW1(timeout_error, 0, "No new message or timer (delay was %f)",
- timeOut);
- }
-
- }
-
- /* A message was already there or arrived in the meanwhile. handle it */
- xbt_dynar_foreach(pd->cbl_list,cpt,list) {
- if (list->id == msg.type->code) {
- break;
- } else {
- list=NULL;
- }
- }
- if (!list) {
- INFO3("No callback for message '%s' from %s:%d. Queue it for later gras_msg_wait() use.",
- msg.type->name,
- gras_socket_peer_name(msg.expe),gras_socket_peer_port(msg.expe));
- xbt_dynar_push(pd->msg_waitqueue,&msg);
- return; /* FIXME: maybe we should call ourselves again until the end of the timer or a proper msg is got */
- }
-
- ctx.expeditor = msg.expe;
- ctx.ID = msg.ID;
- ctx.msgtype = msg.type;
- ctx.answer_due = (msg.kind == e_gras_msg_kind_rpccall);
-
- 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) {
- DEBUG4("Use the callback #%d (@%p) for incomming msg %s (payload_size=%d)",
- cpt+1,cb,msg.type->name,msg.payl_size);
- if (!(*cb)(&ctx,msg.payl)) {
- /* cb handled the message */
- free(msg.payl);
- ran_ok = 1;
- }
+
+ if (timeouted) {
+ if (timerexpected) {
+
+ /* A timer elapsed before the arrival of any message even if we select()ed a bit */
+ untiltimer = gras_msg_timer_handle();
+ if (untiltimer == 0.0) {
+ /* we served a timer, we're done */
+ return;
+ } else {
+ xbt_assert1(untiltimer>0, "Negative timer (%f). I'm 'puzzeled'", untiltimer);
+ WARN1("No timer elapsed, in contrary to expectations (next in %f sec)",
+ untiltimer);
+ THROW1(timeout_error,0,
+ "No timer elapsed, in contrary to expectations (next in %f sec)",
+ untiltimer);
+ }
+
+ } else {
+ /* select timeouted, and no timer elapsed. Nothing to do */
+ THROW1(timeout_error, 0, "No new message or timer (delay was %f)",
+ timeOut);
+ }
+
+ }
+
+ /* A message was already there or arrived in the meanwhile. handle it */
+ xbt_dynar_foreach(pd->cbl_list,cpt,list) {
+ if (list->id == msg.type->code) {
+ break;
+ } else {
+ list=NULL;
+ }
+ }
+ if (!list) {
+ INFO3("No callback for message '%s' from %s:%d. Queue it for later gras_msg_wait() use.",
+ msg.type->name,
+ gras_socket_peer_name(msg.expe),gras_socket_peer_port(msg.expe));
+ xbt_dynar_push(pd->msg_waitqueue,&msg);
+ return; /* FIXME: maybe we should call ourselves again until the end of the timer or a proper msg is got */
+ }
+
+ ctx.expeditor = msg.expe;
+ ctx.ID = msg.ID;
+ ctx.msgtype = msg.type;
+ ctx.answer_due = (msg.kind == e_gras_msg_kind_rpccall);
+
+ 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) {
+ DEBUG4("Use the callback #%d (@%p) for incomming msg %s (payload_size=%d)",
+ cpt+1,cb,msg.type->name,msg.payl_size);
+ 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) {
+ char *old_file=e.file;
+ /* The callback raised an exception, propagate it on the network */
+ if (!e.remote) {
+ /* Make sure we reduce the file name to its basename to avoid issues in tests */
+ char *new_file=strrchr(e.file,'/');
+ if (new_file)
+ e.file = new_file;
+ /* the exception is born on this machine */
+ e.host = (char*)gras_os_myname();
+ xbt_ex_setup_backtrace(&e);
+ }
+ VERB5("Propagate %s exception ('%s') from '%s' RPC cb back to %s:%d",
+ (e.remote ? "remote" : "local"),
+ e.msg,
+ 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);
+ e.file=old_file;
+ xbt_ex_free(e);
+ ctx.answer_due = 0;
+ ran_ok=1;
+ } else {
+ RETHROW0("Callback raised an exception: %s");
+ }
+ }
+
+ xbt_assert1(! ctx.answer_due,
+ "Bug in user code: RPC callback to message '%s' didn't call gras_msg_rpcreturn",msg.type->name);
+ if (ctx.answer_due)
+ CRITICAL1("BUGS BOTH IN USER CODE (RPC callback to message '%s' didn't call gras_msg_rpcreturn) "
+ "AND IN SIMGRID (process wasn't killed by an assert)",msg.type->name);
+ if (!ran_ok)
+ THROW1(mismatch_error,0,
+ "Message '%s' refused by all registered callbacks (maybe your callback misses a 'return 0' at the end)", msg.type->name);
+ /* FIXME: gras_datadesc_free not implemented => leaking the payload */
+ break;
+
+
+ case e_gras_msg_kind_rpcanswer:
+ INFO3("Unexpected RPC answer discarded (type: %s; from:%s:%d)", msg.type->name,
+ gras_socket_peer_name(msg.expe),gras_socket_peer_port(msg.expe));
+ WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+ return;
+
+ case e_gras_msg_kind_rpcerror:
+ INFO3("Unexpected RPC error discarded (type: %s; from:%s:%d)", msg.type->name,
+ gras_socket_peer_name(msg.expe),gras_socket_peer_port(msg.expe));
+ WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+ return;
+
+ default:
+ THROW1(unknown_error,0,
+ "Cannot handle messages of kind %d yet",msg.type->kind);