X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a3338f2cfef40125d5469a7f6d9030c0e930f2ad..c6d6e5b87aed9c7080c981b11f91f2d0205623c3:/examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp diff --git a/examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp b/examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp index 828fae8d8e..c9a9062541 100644 --- a/examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp +++ b/examples/cpp/dht-kademlia/s4u-dht-kademlia.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2012-2021. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2012-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. */ @@ -11,6 +10,7 @@ #include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(kademlia, "Messages specific for this example"); +namespace sg4 = simgrid::s4u; /** @brief Node function * @param my node ID @@ -40,32 +40,25 @@ static void node(std::vector args) if (join_success) { XBT_VERB("Ok, I'm joining the network with id %u", node.getId()); // We start the main loop - double next_lookup_time = simgrid::s4u::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL; + double next_lookup_time = sg4::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL; XBT_VERB("Main loop start"); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(node.getId())); + sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::to_string(node.getId())); - while (simgrid::s4u::Engine::get_clock() < deadline) { - if (node.receive_comm == nullptr) - node.receive_comm = mailbox->get_async(&node.received_msg); - - if (node.receive_comm->test()) { + while (sg4::Engine::get_clock() < deadline) { + if (kademlia::Message* msg = node.receive(mailbox)) { // There has been a message, we need to handle it ! - if (node.received_msg) { - node.handleFindNode(node.received_msg); - delete node.received_msg; - node.receive_comm = nullptr; - } else - simgrid::s4u::this_actor::sleep_for(1); + node.handleFindNode(msg); + delete msg; } else { /* We search for a pseudo random node */ - if (simgrid::s4u::Engine::get_clock() >= next_lookup_time) { + if (sg4::Engine::get_clock() >= next_lookup_time) { node.randomLookup(); next_lookup_time += RANDOM_LOOKUP_INTERVAL; } else { // Didn't get a message: sleep for a while... - simgrid::s4u::this_actor::sleep_for(1); + sg4::this_actor::sleep_for(1); } } } @@ -79,7 +72,7 @@ static void node(std::vector args) /** @brief Main function */ int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); /* Check the arguments */ xbt_assert(argc > 2, @@ -92,7 +85,7 @@ int main(int argc, char* argv[]) e.run(); - XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock()); + XBT_INFO("Simulated time: %g", sg4::Engine::get_clock()); return 0; }