Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function: gras_msg_handleall to deal with all messages arriving within a given...
[simgrid.git] / src / gras / Msg / msg.c
index ab0f1fb..8ed2aef 100644 (file)
@@ -140,7 +140,7 @@ gras_msgtype_declare_ext(const char           *name,
   } CATCH(e) {
     if (e.category != not_found_error)
       RETHROW;
-    xbt_ex_free(&e);
+    xbt_ex_free(e);
   }
 
   if (found) {
@@ -229,7 +229,7 @@ gras_msgtype_t gras_msgtype_by_namev(const char      *name,
   TRY {
     res = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set, namev);
   } CATCH(e) {
-    xbt_ex_free(&e);
+    xbt_ex_free(e);
     THROW1(not_found_error,0,"No registred message of that name: %s",name);
   }
   if (name != namev) 
@@ -312,7 +312,7 @@ gras_msg_wait_ext(double           timeout,
     xbt_dynar_push(pd->msg_queue,&msg);
     
     now=gras_os_time();
-    if (now - start + 0.001 < timeout) {
+    if (now - start + 0.001 > timeout) {
       THROW1(timeout_error,  now-start+0.001-timeout,
             "Timeout while waiting for msg %s",msgt_want->name);
     }
@@ -362,12 +362,39 @@ gras_msg_send(gras_socket_t   sock,
   gras_msg_send_ext(sock, e_gras_msg_kind_oneway,0, msgtype, payload);
 }
 
+/** @brief Handle all messages arriving within the given period
+ *
+ * @param timeOut: How long to wait for incoming messages (in seconds)
+ * @return the error code (or no_error).
+ *
+ * Messages are dealed with just like gras_msg_handle() would do. The
+ * difference is that gras_msg_handle() handles at most one message (or wait up
+ * to timeout second when no message arrives) while this function handles any
+ * amount of messages, and lasts the given period in any case.
+ */
+void 
+gras_msg_handleall(double period) {
+  xbt_ex_t e;
+  double begin=gras_os_time();
+  double now;
+
+  do {
+    now=gras_os_time();
+    TRY{
+      gras_msg_handle(period - now + begin);
+    } CATCH(e) {
+      if (e.category != timeout_error) 
+       RETHROW0("Error while waiting for messages: %s");
+      xbt_ex_free(e);
+    }
+  } while (now - begin < period);
+}
 /** @brief Handle an incomming message or timer (or wait up to \a timeOut seconds)
  *
  * @param timeOut: How long to wait for incoming messages (in seconds)
  * @return the error code (or no_error).
  *
- * Messages are passed to the callbacks.
+ * Messages are passed to the callbacks. See also gras_msg_handleall().
  */
 void
 gras_msg_handle(double timeOut) {
@@ -412,7 +439,7 @@ gras_msg_handle(double timeOut) {
     } CATCH(e) {
       if (e.category != timeout_error)
        RETHROW;
-      xbt_ex_free(&e);
+      xbt_ex_free(e);
       timeouted = 1;
     }
 
@@ -424,8 +451,10 @@ gras_msg_handle(double timeOut) {
               e_gras_msg_kind_names[msg.kind]);
     
       } CATCH(e) {
-       RETHROW1("Error caught while receiving a message on select()ed socket %p: %s",
-                msg.expe);
+       RETHROW4("Error while receiving a message on select()ed socket %p to [%s]%s:%d: %s",
+                msg.expe,
+                gras_socket_peer_proc(msg.expe),gras_socket_peer_name(msg.expe),
+                gras_socket_peer_port(msg.expe));
       }
     }
   }
@@ -505,7 +534,7 @@ gras_msg_handle(double timeOut) {
              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);
+       xbt_ex_free(e);
        ran_ok=1;
       } else {
        RETHROW0("Callback raised an exception: %s");