/* */ #include "BtStopDownloadCommand.h" #include "PieceStorage.h" #include "RequestGroup.h" #include "BtRuntime.h" #include "Logger.h" #include "LogFactory.h" #include "wallclock.h" #include "util.h" #include "fmt.h" #include "DownloadEngine.h" namespace aria2 { BtStopDownloadCommand::BtStopDownloadCommand (cuid_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()) { enableExit(); } if(checkPoint_.difference(global::wallclock()) >= timeout_) { A2_LOG_NOTICE(fmt(_("GID#%lld Stop downloading torrent due to" " --bt-stop-timeout option."), requestGroup_->getGID())); requestGroup_->setForceHaltRequested(true); getDownloadEngine()->setRefreshInterval(0); enableExit(); } } void BtStopDownloadCommand::process() { if(requestGroup_->calculateStat().getDownloadSpeed() > 0) { checkPoint_ = global::wallclock(); } } } // namespace aria2