1 /* Copyright (c) 2015-2016. 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. */
7 #ifndef SIMGRID_MC_CHANNEL_HPP
8 #define SIMGRID_MC_CHANNEL_HPP
12 #include <type_traits>
14 #include "src/mc/mc_protocol.h"
19 /** A channel for exchanging messages between model-checker and model-checked
21 * This hides the way the messages are transfered. Currently, they are sent
22 * over a SOCK_DGRAM socket.
27 static constexpr bool messageType()
29 return std::is_class<M>::value && std::is_trivial<M>::value;
34 Channel(int sock) : socket_(sock) {}
38 Channel(Channel const&) = delete;
39 Channel& operator=(Channel const&) = delete;
42 Channel(Channel&& that) : socket_(that.socket_)
46 Channel& operator=(Channel&& that)
48 this->socket_ = that.socket_;
54 int send(const void* message, size_t size) const;
55 int send(e_mc_message_type type) const
57 s_mc_message message = { type };
58 return this->send(&message, sizeof(message));
61 typename std::enable_if< messageType<M>(), int >::type
62 send(M const& m) const
64 return this->send(&m, sizeof(M));
68 ssize_t receive(void* message, size_t size, bool block = true) const;
70 typename std::enable_if< messageType<M>(), ssize_t >::type
73 return this->receive(&m, sizeof(M));