Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enforce "Rule-of-Three/Five".
[simgrid.git] / examples / s4u / app-bittorrent / s4u-tracker.cpp
index d450951..4e41ae8 100644 (file)
@@ -1,10 +1,11 @@
-/* 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
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "s4u-tracker.hpp"
+#include <algorithm>
 #include <xbt/RngStream.h>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_tracker, "Messages specific for the tracker");
@@ -21,9 +22,9 @@ Tracker::Tracker(std::vector<std::string> args)
   }
   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.");
 }
@@ -31,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.
@@ -48,7 +50,7 @@ void Tracker::operator()()
       TrackerAnswer* ta = new TrackerAnswer(TRACKER_QUERY_INTERVAL);
       std::set<int>::iterator next_peer;
       int nb_known_peers = known_peers.size();
-      int max_tries      = MIN(MAXIMUM_PEERS, nb_known_peers);
+      int max_tries      = std::min(MAXIMUM_PEERS, nb_known_peers);
       int tried          = 0;
       while (tried < max_tries) {
         do {