{
if (mc_mode == MC_MODE_SERVER) {
int res;
- if ((res = MC_protocol_send_simple_message(mc_model_checker->process().socket,
- MC_MESSAGE_DEADLOCK_CHECK)))
+ if ((res = mc_model_checker->process().send_message(MC_MESSAGE_DEADLOCK_CHECK)))
xbt_die("Could not check deadlock state");
s_mc_int_message_t message;
- ssize_t s = MC_receive_message(mc_model_checker->process().socket, &message, sizeof(message), 0);
+ ssize_t s = mc_model_checker->process().receive_message(message);
if (s == -1)
xbt_die("Could not receive message");
else if (s != sizeof(message) || message.type != MC_MESSAGE_DEADLOCK_CHECK_REPLY) {
Process* process = this;
process->process_flags = MC_PROCESS_NO_FLAG;
- process->socket = sockfd;
+ process->socket_ = sockfd;
process->pid_ = pid;
if (pid==getpid())
process->process_flags |= MC_PROCESS_SELF_FLAG;
{
Process* process = this;
+ if (this->socket_ >= 0 && close(this->socket_) < 0)
+ xbt_die("Could not close communication socket");
+
process->process_flags = MC_PROCESS_NO_FLAG;
process->pid_ = 0;
#ifndef MC_PROCESS_H
#define MC_PROCESS_H
-#include <stdbool.h>
+#include <type_traits>
+
#include <sys/types.h>
#include <vector>
return status_;
}
+ template<class M>
+ typename std::enable_if< std::is_class<M>::value && std::is_trivial<M>::value, int >::type
+ send_message(M const& m)
+ {
+ return MC_protocol_send(this->socket_, &m, sizeof(M));
+ }
+
+ int send_message(e_mc_message_type message_id)
+ {
+ return MC_protocol_send_simple_message(this->socket_, message_id);
+ }
+
+ template<class M>
+ typename std::enable_if< std::is_class<M>::value && std::is_trivial<M>::value, ssize_t >::type
+ receive_message(M& m)
+ {
+ return MC_receive_message(this->socket_, &m, sizeof(M), 0);
+ }
+
private:
void init_memory_map_info();
void refresh_heap();
private:
mc_process_flags_t process_flags;
pid_t pid_;
-public: // to be private
- int socket;
-private:
+ int socket_;
int status_;
bool running_;
std::vector<VmMap> memory_map_;
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, size_t size)
{
XBT_DEBUG("Protocol [%s] send %s",
MC_mode_name(mc_mode),
void* data;
} s_mc_register_symbol_message_t, * mc_register_symbol_message_t;
-XBT_INTERNAL int MC_protocol_send(int socket, void* message, size_t size);
+XBT_INTERNAL int MC_protocol_send(int socket, const void* message, size_t size);
XBT_INTERNAL int MC_protocol_send_simple_message(int socket, e_mc_message_type type);
XBT_INTERNAL int MC_protocol_hello(int socket);
XBT_INTERNAL ssize_t MC_receive_message(int socket, void* message, size_t size, int options);
void s_mc_server::resume(mc_process_t process)
{
- int socket = process->socket;
- int res = MC_protocol_send_simple_message(socket, MC_MESSAGE_CONTINUE);
+ int res = process->send_message(MC_MESSAGE_CONTINUE);
if (res)
throw std::system_error(res, std::system_category());
process->cache_flags = (mc_process_cache_flags_t) 0;
m.type = MC_MESSAGE_SIMCALL_HANDLE;
m.pid = pid;
m.value = value;
- MC_protocol_send(mc_model_checker->process().socket, &m, sizeof(m));
+ mc_model_checker->process().send_message(m);
process->cache_flags = (mc_process_cache_flags_t) 0;
while (mc_model_checker->process().running()) {
if (!mc_server->handle_events())