Преглед на файлове

2007-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	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}
Tatsuhiro Tsujikawa преди 18 години
родител
ревизия
bcbadb3b6b
променени са 5 файла, в които са добавени 35 реда и са изтрити 3 реда
  1. 7 0
      ChangeLog
  2. 5 0
      src/RequestGroupAware.cc
  3. 2 0
      src/RequestGroupAware.h
  4. 18 3
      src/SleepCommand.cc
  5. 3 0
      src/SleepCommand.h

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2007-11-05  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	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  <tujikawa at rednoah dot com>
 
 	Fixed: the listen port sent to the tracker is wrong. If aria2 fails

+ 5 - 0
src/RequestGroupAware.cc

@@ -45,3 +45,8 @@ RequestGroupAware::~RequestGroupAware()
 {
   _requestGroup->decreaseNumCommand();
 }
+
+RequestGroup* RequestGroupAware::getRequestGroup() const
+{
+  return _requestGroup;
+}

+ 2 - 0
src/RequestGroupAware.h

@@ -46,6 +46,8 @@ public:
   RequestGroupAware(RequestGroup* requestGroup);
 
   ~RequestGroupAware();
+
+  RequestGroup* getRequestGroup() const;
 };
 
 #endif // _D_REQUEST_GROUP_AWARE_H_

+ 18 - 3
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<RequestGroupAware*>(nextCommand);
+  if(requestGroupAware) {
+    if(requestGroupAware->getRequestGroup()->isHaltRequested()) {
+      return true;
+    }
+  }
+  return false;
+}

+ 3 - 0
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();