X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b9f8f01f1e31a9cec9df207ad241e9c732790cc1..47130afb26809fc8c0e3a77cd168874a23abb62d:/src/mc/remote/Channel.hpp diff --git a/src/mc/remote/Channel.hpp b/src/mc/remote/Channel.hpp index 029ef68691..06d22b1d89 100644 --- a/src/mc/remote/Channel.hpp +++ b/src/mc/remote/Channel.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -10,8 +10,7 @@ #include -namespace simgrid { -namespace mc { +namespace simgrid::mc { /** A channel for exchanging messages between model-checker and model-checked app * @@ -20,13 +19,13 @@ namespace mc { */ class Channel { int socket_ = -1; - template static constexpr bool messageType() - { - return std::is_class::value && std::is_trivial::value; - } + template static constexpr bool messageType() { return std::is_class_v && std::is_trivial_v; } + std::vector buffer_; public: + Channel() = default; explicit Channel(int sock) : socket_(sock) {} + Channel(int sock, Channel const& other); ~Channel(); // No copy: @@ -41,21 +40,24 @@ public: return this->send(&message, sizeof(message)); } /** @brief Send a message; returns 0 on success or errno on failure */ - template typename std::enable_if(), int>::type send(M const& m) const + template typename std::enable_if_t(), int> send(M const& m) const { return this->send(&m, sizeof(M)); } // Receive - ssize_t receive(void* message, size_t size, bool block = true) const; - template typename std::enable_if(), ssize_t>::type receive(M& m) const + ssize_t receive(void* message, size_t size, int flags = 0); + template typename std::enable_if_t(), ssize_t> receive(M& m) { - return this->receive(&m, sizeof(M)); + return this->receive(&m, sizeof(M), 0); } + void reinject(const char* data, size_t size); + bool has_pending_data() const { return not buffer_.empty(); } + // Socket handling int get_socket() const { return socket_; } + void reset_socket(int socket) { socket_ = socket; } }; -} // namespace mc -} // namespace simgrid +} // namespace simgrid::mc #endif