/* */ #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" #include "DownloadContext.h" namespace aria2 { BtStopDownloadCommand::BtStopDownloadCommand(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e, std::chrono::seconds timeout) : TimeBasedCommand(cuid, e, 1_s), requestGroup_(requestGroup), timeout_(std::move(timeout)) { } void BtStopDownloadCommand::preProcess() { if (btRuntime_->isHalt() || pieceStorage_->downloadFinished()) { enableExit(); } if (checkPoint_.difference(global::wallclock()) >= timeout_) { A2_LOG_NOTICE(fmt(_("GID#%s Stop downloading torrent due to" " --bt-stop-timeout option."), GroupId::toHex(requestGroup_->getGID()).c_str())); requestGroup_->setForceHaltRequested(true); getDownloadEngine()->setRefreshInterval(std::chrono::milliseconds(0)); enableExit(); } } void BtStopDownloadCommand::process() { NetStat& stat = requestGroup_->getDownloadContext()->getNetStat(); if (stat.calculateDownloadSpeed() > 0) { checkPoint_ = global::wallclock(); } } } // namespace aria2