#include <errno.h>
#include <string.h>
+#include <stdio.h> // perror
+#include <cstddef> // std::size_t
#include <sys/types.h>
#include <sys/socket.h>
#include <xbt/log.h>
-#include "mc_protocol.h"
-#include "mc_client.h"
+#include "src/mc/mc_protocol.h"
+#include "src/mc/mc_client.h"
extern "C" {
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
-int MC_protocol_send(int socket, void* message, size_t size)
+int MC_protocol_send(int socket, const void* message, std::size_t size)
{
XBT_DEBUG("Protocol [%s] send %s",
MC_mode_name(mc_mode),
return MC_protocol_send(socket, &message, sizeof(message));
}
-int MC_protocol_hello(int socket)
-{
- int e;
- if ((e = MC_protocol_send_simple_message(socket, MC_MESSAGE_HELLO)) != 0) {
- XBT_ERROR("Could not send HELLO message");
- return 1;
- }
-
- s_mc_message_t message;
- message.type = MC_MESSAGE_NONE;
-
- ssize_t s;
- while ((s = MC_receive_message(socket, &message, sizeof(message), 0)) == -1) {
- if (errno == EINTR)
- continue;
- else {
- XBT_ERROR("Could not receive HELLO message");
- return 2;
- }
- }
- if ((size_t) s < sizeof(message) || message.type != MC_MESSAGE_HELLO) {
- 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, int options)
{
int res = recv(socket, message, size, options);
switch(type) {
case MC_MESSAGE_NONE:
return "NONE";
- case MC_MESSAGE_HELLO:
- return "HELLO";
case MC_MESSAGE_CONTINUE:
return "CONTINUE";
case MC_MESSAGE_IGNORE_HEAP:
switch(mode) {
case MC_MODE_NONE:
return "NONE";
- case MC_MODE_STANDALONE:
- return "STANDALONE";
case MC_MODE_CLIENT:
return "CLIENT";
case MC_MODE_SERVER: