X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4ffc087f0ea28fee6fb1d70b37995e64dd2d3575..82bc0605a155764eb531f71670b028fcf1717412:/examples/s4u/app-bittorrent/s4u_peer.cpp diff --git a/examples/s4u/app-bittorrent/s4u_peer.cpp b/examples/s4u/app-bittorrent/s4u_peer.cpp index 79157bc9a5..a9c38f868f 100644 --- a/examples/s4u/app-bittorrent/s4u_peer.cpp +++ b/examples/s4u/app-bittorrent/s4u_peer.cpp @@ -18,7 +18,6 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_peer, "Messages specific for the peers"); #define FILE_PIECES 10UL #define PIECES_BLOCKS 5UL #define BLOCK_SIZE 16384 -static const unsigned long int FILE_SIZE = FILE_PIECES * PIECES_BLOCKS * BLOCK_SIZE; /** Number of blocks asked by each request */ #define BLOCKS_REQUESTED 2 @@ -547,8 +546,13 @@ void Peer::updateChokedPeers() round_ = (round_ + 1) % 3; Connection* chosen_peer = nullptr; // select first active peer and remove it from the set - Connection* choked_peer = *(active_peers.begin()); - active_peers.erase(choked_peer); + Connection* choked_peer; + if (active_peers.empty()) { + choked_peer = nullptr; + } else { + choked_peer = *active_peers.begin(); + active_peers.erase(choked_peer); + } /**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/ if (hasFinished()) {