Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Don't name unused exceptions.
[simgrid.git] / examples / s4u / app-bittorrent / s4u-tracker.cpp
index 1296679..b7bd4cd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2017. The SimGrid Team.
+/* Copyright (c) 2012-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -17,14 +17,14 @@ Tracker::Tracker(std::vector<std::string> args)
   // Retrieving end time
   try {
     deadline = std::stod(args[1]);
-  } catch (std::invalid_argument& ia) {
+  } catch (const std::invalid_argument&) {
     throw std::invalid_argument(std::string("Invalid deadline:") + args[1].c_str());
   }
   xbt_assert(deadline > 0, "Wrong deadline supplied");
 
-  stream = simgrid::s4u::this_actor::getHost()->extension<HostBittorrent>()->getStream();
+  stream = simgrid::s4u::this_actor::get_host()->extension<HostBittorrent>()->getStream();
 
-  mailbox = simgrid::s4u::Mailbox::byName(TRACKER_MAILBOX);
+  mailbox = simgrid::s4u::Mailbox::by_name(TRACKER_MAILBOX);
 
   XBT_INFO("Tracker launched.");
 }
@@ -32,12 +32,13 @@ Tracker::Tracker(std::vector<std::string> args)
 void Tracker::operator()()
 {
   simgrid::s4u::CommPtr comm = nullptr;
-  void* received;
-  while (simgrid::s4u::Engine::getClock() < deadline) {
+  void* received             = nullptr;
+  while (simgrid::s4u::Engine::get_clock() < deadline) {
     if (comm == nullptr)
       comm = mailbox->get_async(&received);
     if (comm->test()) {
       // Retrieve the data sent by the peer.
+      xbt_assert(received != nullptr);
       TrackerQuery* tq = static_cast<TrackerQuery*>(received);
 
       // Add the peer to our peer list, if not already known.
@@ -55,7 +56,7 @@ void Tracker::operator()()
         do {
           next_peer = known_peers.begin();
           std::advance(next_peer, RngStream_RandInt(stream, 0, nb_known_peers - 1));
-        } while (ta->getPeers()->find(*next_peer) != ta->getPeers()->end());
+        } while (ta->getPeers().find(*next_peer) != ta->getPeers().end());
         ta->addPeer(*next_peer);
         tried++;
       }