Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remote support for MC_deadlock_check() using MC_MESSAGE_DEADLOCK_CHECK IPC message
[simgrid.git] / src / mc / mc_protocol.c
index 3396a38..0034148 100644 (file)
 #include <xbt/log.h>
 
 #include "mc_protocol.h"
 #include <xbt/log.h>
 
 #include "mc_protocol.h"
+#include "mc_client.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
 
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
 
-int MC_protocol_send_simple_message(int socket, int type)
+int MC_protocol_send(int socket, void* message, size_t size)
 {
 {
-  s_mc_message_t message;
-  message.type = type;
-
-  while (send(socket, &message, sizeof(message), 0) == -1) {
+  while (send(socket, message, size, 0) == -1) {
     if (errno == EINTR)
       continue;
     else
     if (errno == EINTR)
       continue;
     else
@@ -30,6 +28,13 @@ int MC_protocol_send_simple_message(int socket, int type)
   return 0;
 }
 
   return 0;
 }
 
+int MC_protocol_send_simple_message(int socket, int type)
+{
+  s_mc_message_t message;
+  message.type = type;
+  return MC_protocol_send(socket, &message, sizeof(message));
+}
+
 int MC_protocol_hello(int socket)
 {
   int e;
 int MC_protocol_hello(int socket)
 {
   int e;
@@ -41,7 +46,8 @@ int MC_protocol_hello(int socket)
   s_mc_message_t message;
   message.type = MC_MESSAGE_NONE;
 
   s_mc_message_t message;
   message.type = MC_MESSAGE_NONE;
 
-  while (recv(socket, &message, sizeof(message), 0) == -1) {
+  size_t s;
+  while ((s = recv(socket, &message, sizeof(message), 0)) == -1) {
     if (errno == EINTR)
       continue;
     else {
     if (errno == EINTR)
       continue;
     else {
@@ -49,10 +55,15 @@ int MC_protocol_hello(int socket)
       return 2;
     }
   }
       return 2;
     }
   }
-  if (message.type != MC_MESSAGE_HELLO) {
+  if (s < sizeof(message) || message.type != MC_MESSAGE_HELLO) {
     XBT_ERROR("Did not receive suitable HELLO message. Who are you?");
     return 3;
   }
 
   return 0;
 }
     XBT_ERROR("Did not receive suitable HELLO message. Who are you?");
     return 3;
   }
 
   return 0;
 }
+
+ssize_t MC_receive_message(int socket, void* message, size_t size)
+{
+  return recv(socket, message, size, 0);
+}