Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[examples/s4u-dht-chord] Handle TimeoutException which may be thrown by Comm::test.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 5 Feb 2020 20:23:13 +0000 (21:23 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 5 Feb 2020 23:00:13 +0000 (00:00 +0100)
examples/s4u/dht-chord/s4u-dht-chord-node.cpp

index 93af036..1af602a 100644 (file)
@@ -498,7 +498,15 @@ void Node::operator()()
   while (now < std::min(start_time_ + deadline_, MAX_SIMULATION_TIME)) {
     if (comm_receive == nullptr)
       comm_receive = mailbox_->get_async(&data);
-    if (comm_receive->test()) {
+    bool comm_completed = true;
+    try {
+      if (not comm_receive->test())
+        comm_completed = false;
+    } catch (const simgrid::TimeoutException&) {
+      XBT_DEBUG("Caught a timeout, go ahead.");
+    }
+
+    if (comm_completed) {
       if (data != nullptr) {
         ChordMessage* message = static_cast<ChordMessage*>(data);
         handleMessage(message);
@@ -528,10 +536,14 @@ void Node::operator()()
     now = simgrid::s4u::Engine::get_clock();
   }
   if (comm_receive != nullptr) {
-    if (comm_receive->test())
-      delete static_cast<ChordMessage*>(data);
-    else
-      comm_receive->cancel();
+    try {
+      if (comm_receive->test())
+        delete static_cast<ChordMessage*>(data);
+      else
+        comm_receive->cancel();
+    } catch (const simgrid::TimeoutException&) {
+      XBT_DEBUG("Caught a timeout for last message, nevermind.");
+    }
   }
   // leave the ring
   leave();