From 7bbd9cec3bd234f4406092a3471460dc65e0c647 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 17 May 2008 05:12:14 +0000 Subject: [PATCH] 2008-05-16 Tatsuhiro Tsujikawa Call subtractPieceStats from ~PeerInteractionCommand only when the peer has at least one completed piece. * src/Peer.cc * src/Peer.h * src/PeerInteractionCommand.cc * src/PeerSessionResource.cc * src/PeerSessionResource.h --- ChangeLog | 10 ++++++++++ src/Peer.cc | 6 ++++++ src/Peer.h | 2 ++ src/PeerInteractionCommand.cc | 6 ++++-- src/PeerSessionResource.cc | 5 +++++ src/PeerSessionResource.h | 2 ++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a38e4d65..618d8280 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-05-16 Tatsuhiro Tsujikawa + + Call subtractPieceStats from ~PeerInteractionCommand only when the + peer has at least one completed piece. + * src/Peer.cc + * src/Peer.h + * src/PeerInteractionCommand.cc + * src/PeerSessionResource.cc + * src/PeerSessionResource.h + 2008-05-16 Tatsuhiro Tsujikawa Removed unnecessary sorting diff --git a/src/Peer.cc b/src/Peer.cc index 6449c4bd..42fe65dd 100644 --- a/src/Peer.cc +++ b/src/Peer.cc @@ -454,4 +454,10 @@ const Time& Peer::getLastAmUnchoking() const return _res->getLastAmUnchoking(); } +uint64_t Peer::getCompletedLength() const +{ + assert(_res); + return _res->getCompletedLength(); +} + } // namespace aria2 diff --git a/src/Peer.h b/src/Peer.h index 89d61849..c7dbb054 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -235,6 +235,8 @@ public: const Time& getLastDownloadUpdate() const; const Time& getLastAmUnchoking() const; + + uint64_t getCompletedLength() const; }; typedef SharedHandle PeerHandle; diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index edb6bbf2..e0e58939 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -170,8 +170,10 @@ PeerInteractionCommand::PeerInteractionCommand(int32_t cuid, } PeerInteractionCommand::~PeerInteractionCommand() { - pieceStorage->subtractPieceStats(peer->getBitfield(), - peer->getBitfieldLength()); + if(peer->getCompletedLength() > 0) { + pieceStorage->subtractPieceStats(peer->getBitfield(), + peer->getBitfieldLength()); + } peer->releaseSessionResource(); PEER_OBJECT_CLUSTER(btContext)->unregisterHandle(peer->getID()); diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc index 1a111a2b..71c0dcd3 100644 --- a/src/PeerSessionResource.cc +++ b/src/PeerSessionResource.cc @@ -337,4 +337,9 @@ const Time& PeerSessionResource::getLastAmUnchoking() const return _lastAmUnchoking; } +uint64_t PeerSessionResource::getCompletedLength() const +{ + return _bitfieldMan->getCompletedLength(); +} + } // namespace aria2 diff --git a/src/PeerSessionResource.h b/src/PeerSessionResource.h index 4388004c..783e86bb 100644 --- a/src/PeerSessionResource.h +++ b/src/PeerSessionResource.h @@ -185,6 +185,8 @@ public: const Time& getLastDownloadUpdate() const; const Time& getLastAmUnchoking() const; + + uint64_t getCompletedLength() const; }; } // namespace aria2