diff --git a/ChangeLog b/ChangeLog index 51fd7a6d..6878b1bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-11-05 Tatsuhiro Tsujikawa + + Now SleepCommand dispatches nextCommand when halt is requested. + It avoids a possible long wait after hitting CTRL-C. + * src/SleepCommand.{h, cc} + * src/RequestGroupAware.{h, cc} + 2007-11-04 Tatsuhiro Tsujikawa Fixed: the listen port sent to the tracker is wrong. If aria2 fails diff --git a/src/RequestGroupAware.cc b/src/RequestGroupAware.cc index c76f9ba8..940adf0e 100644 --- a/src/RequestGroupAware.cc +++ b/src/RequestGroupAware.cc @@ -45,3 +45,8 @@ RequestGroupAware::~RequestGroupAware() { _requestGroup->decreaseNumCommand(); } + +RequestGroup* RequestGroupAware::getRequestGroup() const +{ + return _requestGroup; +} diff --git a/src/RequestGroupAware.h b/src/RequestGroupAware.h index 1f5e6283..580a4fc9 100644 --- a/src/RequestGroupAware.h +++ b/src/RequestGroupAware.h @@ -46,6 +46,8 @@ public: RequestGroupAware(RequestGroup* requestGroup); ~RequestGroupAware(); + + RequestGroup* getRequestGroup() const; }; #endif // _D_REQUEST_GROUP_AWARE_H_ diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc index aa13c07f..0cf82b54 100644 --- a/src/SleepCommand.cc +++ b/src/SleepCommand.cc @@ -34,20 +34,22 @@ /* copyright --> */ #include "SleepCommand.h" #include "Util.h" +#include "RequestGroupAware.h" +#include "RequestGroup.h" SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait): Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) {} SleepCommand::~SleepCommand() { - if(nextCommand != NULL) { + if(nextCommand) { delete(nextCommand); } } bool SleepCommand::execute() { - if(checkPoint.elapsed(wait)) { + if(checkPoint.elapsed(wait) || isHaltRequested()) { engine->commands.push_back(nextCommand); - nextCommand = NULL; + nextCommand = 0; return true; } else { engine->commands.push_back(this); @@ -55,3 +57,16 @@ 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; +} diff --git a/src/SleepCommand.h b/src/SleepCommand.h index f4f1ee20..b2edff94 100644 --- a/src/SleepCommand.h +++ b/src/SleepCommand.h @@ -45,6 +45,9 @@ private: Command* nextCommand; int32_t wait; Time checkPoint; + + bool isHaltRequested() const; + public: SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait); virtual ~SleepCommand();