1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include <sys/types.h>
11 #include <sys/socket.h>
15 #include "mc_protocol.h"
16 #include "mc_client.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
20 int MC_protocol_send(int socket, void* message, size_t size)
22 XBT_DEBUG("Protocol [%s] send %s",
23 MC_mode_name(mc_mode),
24 MC_message_type_name(*(e_mc_message_type*) message));
26 while (send(socket, message, size, 0) == -1) {
35 int MC_protocol_send_simple_message(int socket, int type)
37 s_mc_message_t message;
39 return MC_protocol_send(socket, &message, sizeof(message));
42 int MC_protocol_hello(int socket)
45 if ((e = MC_protocol_send_simple_message(socket, MC_MESSAGE_HELLO)) != 0) {
46 XBT_ERROR("Could not send HELLO message");
50 s_mc_message_t message;
51 message.type = MC_MESSAGE_NONE;
54 while ((s = MC_receive_message(socket, &message, sizeof(message), 0)) == -1) {
58 XBT_ERROR("Could not receive HELLO message");
62 if (s < sizeof(message) || message.type != MC_MESSAGE_HELLO) {
63 XBT_ERROR("Did not receive suitable HELLO message. Who are you?");
70 ssize_t MC_receive_message(int socket, void* message, size_t size, int options)
72 int res = recv(socket, message, size, options);
74 XBT_DEBUG("Protocol [%s] received %s",
75 MC_mode_name(mc_mode),
76 MC_message_type_name(*(e_mc_message_type*) message));
81 const char* MC_message_type_name(e_mc_message_type type)
86 case MC_MESSAGE_HELLO:
88 case MC_MESSAGE_CONTINUE:
90 case MC_MESSAGE_IGNORE_HEAP:
92 case MC_MESSAGE_UNIGNORE_HEAP:
93 return "UNIGNORE_HEAP";
94 case MC_MESSAGE_IGNORE_MEMORY:
95 return "IGNORE_MEMORY";
96 case MC_MESSAGE_STACK_REGION:
97 return "STACK_REGION";
98 case MC_MESSAGE_REGISTER_SYMBOL:
99 return "REGISTER_SYMBOL";
100 case MC_MESSAGE_DEADLOCK_CHECK:
101 return "DEADLOCK_CHECK";
102 case MC_MESSAGE_DEADLOCK_CHECK_REPLY:
103 return "DEADLOCK_CHECK_REPLY";
104 case MC_MESSAGE_WAITING:
106 case MC_MESSAGE_SIMCALL_HANDLE:
107 return "SIMCALL_HANDLE";
108 case MC_MESSAGE_ASSERTION_FAILED:
109 return "ASSERTION_FAILED";
115 const char* MC_mode_name(e_mc_mode_t mode)
120 case MC_MODE_STANDALONE: