2008-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2008-11-11 16:05:42 +00:00
parent 05a9313e19
commit ec2354f3a1
7 changed files with 40 additions and 23 deletions

View File

@ -1,3 +1,13 @@
2008-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net> 2008-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added the ability to specify output filename and directory in input Added the ability to specify output filename and directory in input

View File

@ -209,7 +209,8 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
e->setNoWait(true); e->setNoWait(true);
e->commands.push_back(command); e->commands.push_back(command);
} else { } else {
SleepCommand* scom = new SleepCommand(cuid, e, command, wait); SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup,
command, wait);
e->commands.push_back(scom); e->commands.push_back(scom);
} }
return true; return true;

View File

@ -258,6 +258,8 @@ bool DownloadCommand::prepareForNextSegment() {
new CheckIntegrityCommand(e->newCUID(), _requestGroup, e, entry); new CheckIntegrityCommand(e->newCUID(), _requestGroup, e, entry);
e->commands.push_back(command); e->commands.push_back(command);
} }
e->setNoWait(true);
e->setRefreshInterval(0);
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
return true; return true;
} else { } else {

View File

@ -414,6 +414,7 @@ void AsyncNameResolverEntry::process(fd_set* rfdsPtr, fd_set* wfdsPtr)
DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()), DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()),
_haltRequested(false), _haltRequested(false),
_noWait(false), _noWait(false),
_refreshInterval(DEFAULT_REFRESH_INTERVAL),
_cookieStorage(new CookieStorage()), _cookieStorage(new CookieStorage()),
_btRegistry(new BtRegistry()), _btRegistry(new BtRegistry()),
_dnsCache(new SimpleDNSCache()) _dnsCache(new SimpleDNSCache())
@ -490,7 +491,8 @@ void DownloadEngine::run() {
Time cp; Time cp;
cp.setTimeInSec(0); cp.setTimeInSec(0);
while(!commands.empty() || !_routineCommands.empty()) { while(!commands.empty() || !_routineCommands.empty()) {
if(cp.elapsed(1)) { if(cp.elapsed(_refreshInterval)) {
_refreshInterval = DEFAULT_REFRESH_INTERVAL;
cp.reset(); cp.reset();
executeCommand(commands, Command::STATUS_ALL); executeCommand(commands, Command::STATUS_ALL);
} else { } else {
@ -1124,4 +1126,9 @@ SharedHandle<AuthConfigFactory> DownloadEngine::getAuthConfigFactory() const
return _authConfigFactory; return _authConfigFactory;
} }
void DownloadEngine::setRefreshInterval(time_t interval)
{
_refreshInterval = interval;
}
} // namespace aria2 } // namespace aria2

View File

@ -296,6 +296,10 @@ private:
bool _noWait; bool _noWait;
static const time_t DEFAULT_REFRESH_INTERVAL = 1;
time_t _refreshInterval;
std::deque<Command*> _routineCommands; std::deque<Command*> _routineCommands;
SharedHandle<CookieStorage> _cookieStorage; SharedHandle<CookieStorage> _cookieStorage;
@ -444,6 +448,8 @@ public:
void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory); void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
SharedHandle<AuthConfigFactory> getAuthConfigFactory() const; SharedHandle<AuthConfigFactory> getAuthConfigFactory() const;
void setRefreshInterval(time_t interval);
}; };
typedef SharedHandle<DownloadEngine> DownloadEngineHandle; typedef SharedHandle<DownloadEngine> DownloadEngineHandle;

View File

@ -39,8 +39,11 @@
namespace aria2 { namespace aria2 {
SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, time_t wait): SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e,
Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) {} RequestGroup* requestGroup,
Command* nextCommand, time_t wait):
Command(cuid), engine(e), _requestGroup(requestGroup),
nextCommand(nextCommand), wait(wait) {}
SleepCommand::~SleepCommand() { SleepCommand::~SleepCommand() {
if(nextCommand) { if(nextCommand) {
@ -49,7 +52,9 @@ SleepCommand::~SleepCommand() {
} }
bool SleepCommand::execute() { 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); engine->commands.push_back(nextCommand);
nextCommand = 0; nextCommand = 0;
return true; return true;
@ -59,18 +64,4 @@ bool SleepCommand::execute() {
} }
} }
bool SleepCommand::isHaltRequested() const
{
if(engine->isHaltRequested()) {
return true;
}
RequestGroupAware* requestGroupAware = dynamic_cast<RequestGroupAware*>(nextCommand);
if(requestGroupAware) {
if(requestGroupAware->getRequestGroup()->isHaltRequested()) {
return true;
}
}
return false;
}
} // namespace aria2 } // namespace aria2

View File

@ -41,18 +41,18 @@
namespace aria2 { namespace aria2 {
class DownloadEngine; class DownloadEngine;
class RequestGroup;
class SleepCommand:public Command { class SleepCommand:public Command {
private: private:
DownloadEngine* engine; DownloadEngine* engine;
RequestGroup* _requestGroup;
Command* nextCommand; Command* nextCommand;
time_t wait; time_t wait;
Time checkPoint; Time checkPoint;
bool isHaltRequested() const;
public: 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(); virtual ~SleepCommand();
bool execute(); bool execute();
}; };