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"
22 static constexpr bool messageType()
24 return std::is_class<M>::value && std::is_trivial<M>::value;
29 Channel(int sock) : socket_(sock) {}
33 Channel(Channel const&) = delete;
34 Channel& operator=(Channel const&) = delete;
37 Channel(Channel&& that) : socket_(that.socket_)
41 Channel& operator=(Channel&& that)
43 this->socket_ = that.socket_;
49 int send(const void* message, size_t size) const;
50 int send(e_mc_message_type type) const
52 s_mc_message message = { type };
53 return this->send(&message, sizeof(message));
56 typename std::enable_if< messageType<M>(), int >::type
57 send(M const& m) const
59 return this->send(&m, sizeof(M));
63 ssize_t receive(void* message, size_t size, bool block = true) const;
65 typename std::enable_if< messageType<M>(), ssize_t >::type
68 return this->receive(&m, sizeof(M));