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"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
22 int MC_protocol_send(int socket, void* message, size_t size)
24 XBT_DEBUG("Protocol [%s] send %s",
25 MC_mode_name(mc_mode),
26 MC_message_type_name(*(e_mc_message_type*) message));
28 while (send(socket, message, size, 0) == -1) {
37 int MC_protocol_send_simple_message(int socket, e_mc_message_type type)
39 s_mc_message_t message;
41 return MC_protocol_send(socket, &message, sizeof(message));
44 int MC_protocol_hello(int socket)
47 if ((e = MC_protocol_send_simple_message(socket, MC_MESSAGE_HELLO)) != 0) {
48 XBT_ERROR("Could not send HELLO message");
52 s_mc_message_t message;
53 message.type = MC_MESSAGE_NONE;
56 while ((s = MC_receive_message(socket, &message, sizeof(message), 0)) == -1) {
60 XBT_ERROR("Could not receive HELLO message");
64 if ((size_t) s < sizeof(message) || message.type != MC_MESSAGE_HELLO) {
65 XBT_ERROR("Did not receive suitable HELLO message. Who are you?");
72 ssize_t MC_receive_message(int socket, void* message, size_t size, int options)
74 int res = recv(socket, message, size, options);
76 XBT_DEBUG("Protocol [%s] received %s",
77 MC_mode_name(mc_mode),
78 MC_message_type_name(*(e_mc_message_type*) message));
83 const char* MC_message_type_name(e_mc_message_type type)
88 case MC_MESSAGE_HELLO:
90 case MC_MESSAGE_CONTINUE:
92 case MC_MESSAGE_IGNORE_HEAP:
94 case MC_MESSAGE_UNIGNORE_HEAP:
95 return "UNIGNORE_HEAP";
96 case MC_MESSAGE_IGNORE_MEMORY:
97 return "IGNORE_MEMORY";
98 case MC_MESSAGE_STACK_REGION:
99 return "STACK_REGION";
100 case MC_MESSAGE_REGISTER_SYMBOL:
101 return "REGISTER_SYMBOL";
102 case MC_MESSAGE_DEADLOCK_CHECK:
103 return "DEADLOCK_CHECK";
104 case MC_MESSAGE_DEADLOCK_CHECK_REPLY:
105 return "DEADLOCK_CHECK_REPLY";
106 case MC_MESSAGE_WAITING:
108 case MC_MESSAGE_SIMCALL_HANDLE:
109 return "SIMCALL_HANDLE";
110 case MC_MESSAGE_ASSERTION_FAILED:
111 return "ASSERTION_FAILED";
117 const char* MC_mode_name(e_mc_mode_t mode)