浏览代码

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
Tatsuhiro Tsujikawa 17 年之前
父节点
当前提交
ec2354f3a1
共有 7 个文件被更改,包括 40 次插入23 次删除
  1. 10 0
      ChangeLog
  2. 2 1
      src/AbstractCommand.cc
  3. 2 0
      src/DownloadCommand.cc
  4. 8 1
      src/DownloadEngine.cc
  5. 6 0
      src/DownloadEngine.h
  6. 8 17
      src/SleepCommand.cc
  7. 4 4
      src/SleepCommand.h

+ 10 - 0
ChangeLog

@@ -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>
 
 	Added the ability to specify output filename and directory in input

+ 2 - 1
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;

+ 2 - 0
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 {

+ 8 - 1
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<AuthConfigFactory> DownloadEngine::getAuthConfigFactory() const
   return _authConfigFactory;
 }
 
+void DownloadEngine::setRefreshInterval(time_t interval)
+{
+  _refreshInterval = interval;
+}
+
 } // namespace aria2

+ 6 - 0
src/DownloadEngine.h

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

+ 8 - 17
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<RequestGroupAware*>(nextCommand);
-  if(requestGroupAware) {
-    if(requestGroupAware->getRequestGroup()->isHaltRequested()) {
-      return true;
-    }
-  }
-  return false;
-}
-
 } // namespace aria2

+ 4 - 4
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();
 };