Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Have the application execute its transition before returning SIMCALL_EXECUTE_ANSWER
[simgrid.git] / src / mc / remote / AppSide.cpp
index 3517fe193f24bbf0809b94626b1a70763542d720..e56a85476db8ffc012f16b825a05250169865e11 100644 (file)
@@ -99,29 +99,30 @@ void AppSide::handle_simcall_execute(const s_mc_message_simcall_execute_t* messa
   kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(message->aid_);
   xbt_assert(actor != nullptr, "Invalid pid %ld", message->aid_);
 
+  // The client may send some messages to the server while processing the transition
+  actor->simcall_handle(message->times_considered_);
+  // Say the server that the transition is over and that it should proceed
+  xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send MESSAGE_WAITING to model-checker");
+
   // Finish the RPC from the server: return a serialized observer, to build a Transition on Checker side
   s_mc_message_simcall_execute_answer_t answer;
   memset(&answer, 0, sizeof(answer));
   answer.type = MessageType::SIMCALL_EXECUTE_ANSWER;
+  std::stringstream stream;
   if (actor->simcall_.observer_ != nullptr) {
-    std::stringstream stream;
-    actor->simcall_.observer_->serialize(answer.simcall, stream);
-    xbt_assert(stream.str().size() < sizeof(answer.buffer),
-               "The serialized simcall is too large for the buffer. Please fix the code.");
-    strncpy(answer.buffer, stream.str().c_str(), SIMCALL_SERIALIZATION_BUFFER_SIZE);
+    actor->simcall_.observer_->serialize(stream);
   } else {
-    answer.simcall = mc::Transition::Type::UNKNOWN;
+    stream << (short)mc::Transition::Type::UNKNOWN;
   }
+  std::string str = stream.str();
+  xbt_assert(str.size() + 1 <= answer.buffer.size(),
+             "The serialized simcall is too large for the buffer. Please fix the code.");
+  strncpy(answer.buffer.data(), str.c_str(), answer.buffer.size() - 1);
+  answer.buffer.back() = '\0';
 
-  XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> %s '%s'", actor->get_cname(), mc::Transition::to_c_str(answer.simcall),
-            answer.buffer);
+  XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> '%s'", actor->get_cname(), str.c_str());
   xbt_assert(channel_.send(answer) == 0, "Could not send response");
 
-  // The client may send some messages to the server while processing the transition
-  actor->simcall_handle(message->times_considered_);
-
-  // Say the server that the transition is over and that it should proceed
-  xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send MESSAGE_WAITING to model-checker");
 }
 
 void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const