/* */ #include "BtStopDownloadCommand.h" #include "PieceStorage.h" #include "PeerStorage.h" #include "RequestGroup.h" #include "BtRuntime.h" #include "Peer.h" #include "DownloadContext.h" #include "Logger.h" namespace aria2 { BtStopDownloadCommand::BtStopDownloadCommand (int32_t cuid, RequestGroup* requestGroup, DownloadEngine* e, time_t timeout): TimeBasedCommand(cuid, e, 1), _requestGroup(requestGroup), _timeout(timeout) {} void BtStopDownloadCommand::preProcess() { if(_btRuntime->isHalt() || _pieceStorage->downloadFinished()) { _exit = true; } if(_checkPoint.elapsed(_timeout)) { logger->notice("GID#%d Stop downloading torrent due to" " --bt-stop-timeout option.", _requestGroup->getGID()); _requestGroup->setHaltRequested(true); _exit = true; } } void BtStopDownloadCommand::process() { if(_requestGroup->calculateStat().getDownloadSpeed() == 0) { std::deque > activePeers; _peerStorage->getActivePeers(activePeers); if(countSeeder(activePeers.begin(), activePeers.end()) != 0) { _checkPoint.reset(); } } else { _checkPoint.reset(); } } } // namespace aria2