diff --git a/ChangeLog b/ChangeLog index c370996a..9668ece0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-12 Tatsuhiro Tsujikawa + + Quickly terminate idle commands when download finished. + * src/AbstractCommand.cc + * src/DownloadCommand.cc + * src/DownloadEngine.cc + * src/DownloadEngine.h + * src/SleepCommand.cc + * src/SleepCommand.h + 2008-11-11 Tatsuhiro Tsujikawa Added the ability to specify output filename and directory in input diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index eff07af3..1e20f649 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -209,7 +209,8 @@ bool AbstractCommand::prepareForRetry(time_t wait) { e->setNoWait(true); e->commands.push_back(command); } else { - SleepCommand* scom = new SleepCommand(cuid, e, command, wait); + SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup, + command, wait); e->commands.push_back(scom); } return true; diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 1e01c560..77a1436a 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -258,6 +258,8 @@ bool DownloadCommand::prepareForNextSegment() { new CheckIntegrityCommand(e->newCUID(), _requestGroup, e, entry); e->commands.push_back(command); } + e->setNoWait(true); + e->setRefreshInterval(0); #endif // ENABLE_MESSAGE_DIGEST return true; } else { diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 2c9ac17b..c2ebfc39 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -414,6 +414,7 @@ void AsyncNameResolverEntry::process(fd_set* rfdsPtr, fd_set* wfdsPtr) DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()), _haltRequested(false), _noWait(false), + _refreshInterval(DEFAULT_REFRESH_INTERVAL), _cookieStorage(new CookieStorage()), _btRegistry(new BtRegistry()), _dnsCache(new SimpleDNSCache()) @@ -490,7 +491,8 @@ void DownloadEngine::run() { Time cp; cp.setTimeInSec(0); while(!commands.empty() || !_routineCommands.empty()) { - if(cp.elapsed(1)) { + if(cp.elapsed(_refreshInterval)) { + _refreshInterval = DEFAULT_REFRESH_INTERVAL; cp.reset(); executeCommand(commands, Command::STATUS_ALL); } else { @@ -1124,4 +1126,9 @@ SharedHandle DownloadEngine::getAuthConfigFactory() const return _authConfigFactory; } +void DownloadEngine::setRefreshInterval(time_t interval) +{ + _refreshInterval = interval; +} + } // namespace aria2 diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 046c39be..81d6c050 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -296,6 +296,10 @@ private: bool _noWait; + static const time_t DEFAULT_REFRESH_INTERVAL = 1; + + time_t _refreshInterval; + std::deque _routineCommands; SharedHandle _cookieStorage; @@ -444,6 +448,8 @@ public: void setAuthConfigFactory(const SharedHandle& factory); SharedHandle getAuthConfigFactory() const; + + void setRefreshInterval(time_t interval); }; typedef SharedHandle DownloadEngineHandle; diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc index 15a4341b..ff8f63cb 100644 --- a/src/SleepCommand.cc +++ b/src/SleepCommand.cc @@ -39,8 +39,11 @@ namespace aria2 { -SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, time_t wait): - Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) {} +SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, + RequestGroup* requestGroup, + Command* nextCommand, time_t wait): + Command(cuid), engine(e), _requestGroup(requestGroup), + nextCommand(nextCommand), wait(wait) {} SleepCommand::~SleepCommand() { if(nextCommand) { @@ -49,7 +52,9 @@ SleepCommand::~SleepCommand() { } bool SleepCommand::execute() { - if(checkPoint.elapsed(wait) || isHaltRequested()) { + if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) { + return true; + } else if(checkPoint.elapsed(wait)) { engine->commands.push_back(nextCommand); nextCommand = 0; return true; @@ -59,18 +64,4 @@ bool SleepCommand::execute() { } } -bool SleepCommand::isHaltRequested() const -{ - if(engine->isHaltRequested()) { - return true; - } - RequestGroupAware* requestGroupAware = dynamic_cast(nextCommand); - if(requestGroupAware) { - if(requestGroupAware->getRequestGroup()->isHaltRequested()) { - return true; - } - } - return false; -} - } // namespace aria2 diff --git a/src/SleepCommand.h b/src/SleepCommand.h index 4da85a88..3e64eebe 100644 --- a/src/SleepCommand.h +++ b/src/SleepCommand.h @@ -41,18 +41,18 @@ namespace aria2 { class DownloadEngine; +class RequestGroup; class SleepCommand:public Command { private: DownloadEngine* engine; + RequestGroup* _requestGroup; Command* nextCommand; time_t wait; Time checkPoint; - - bool isHaltRequested() const; - public: - SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, time_t wait); + SleepCommand(int32_t cuid, DownloadEngine* e, RequestGroup* requestGroup, + Command* nextCommand, time_t wait); virtual ~SleepCommand(); bool execute(); };