Explorar el Código

2009-07-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Keep CreateRequestCommand in queue when no segment is available so
	that they can pick up pieces which slow BitTorrent peers are
	downloading.
	* src/AbstractCommand.cc
	* src/CreateRequestCommand.cc
	* src/CreateRequestCommand.h
Tatsuhiro Tsujikawa hace 16 años
padre
commit
db84b1b652
Se han modificado 4 ficheros con 31 adiciones y 2 borrados
  1. 9 0
      ChangeLog
  2. 1 1
      src/AbstractCommand.cc
  3. 19 1
      src/CreateRequestCommand.cc
  4. 2 0
      src/CreateRequestCommand.h

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2009-07-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Keep CreateRequestCommand in queue when no segment is available so
+	that they can pick up pieces which slow BitTorrent peers are
+	downloading.
+	* src/AbstractCommand.cc
+	* src/CreateRequestCommand.cc
+	* src/CreateRequestCommand.h
+
 2009-07-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	--bt-stop-timeout now only checks download speed.

+ 1 - 1
src/AbstractCommand.cc

@@ -149,7 +149,7 @@ bool AbstractCommand::execute() {
 	  if(_segments.empty()) {
 	    // TODO socket could be pooled here if pipelining is enabled...
 	    logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
-	    return true;
+	    return prepareForRetry(1);
 	  }
 	} else {
 	  size_t maxSegments = req->getMaxPipelinedRequest();

+ 19 - 1
src/CreateRequestCommand.cc

@@ -44,6 +44,8 @@
 #include "SegmentMan.h"
 #include "prefs.h"
 #include "Option.h"
+#include "SleepCommand.h"
+#include "Logger.h"
 
 namespace aria2 {
 
@@ -57,7 +59,7 @@ CreateRequestCommand::CreateRequestCommand(int32_t cuid,
   disableReadCheckSocket();
   disableWriteCheckSocket();
 }
-		  
+
 bool CreateRequestCommand::executeInternal()
 {
   if(_segments.empty()) {
@@ -95,4 +97,20 @@ bool CreateRequestCommand::executeInternal()
   return true;
 }
 
+bool CreateRequestCommand::prepareForRetry(time_t wait)
+{
+  // We assume that this method is called from AbstractCommand when
+  // Segment is not available.  Normally,
+  // AbstractCommand::prepareForRetry() does the job, but it creates
+  // CreateRequestCommand and deletes current one. At the last stage
+  // of the download, commands are idle and prepareForRetry() is
+  // called repeatedly. This means that newly created
+  // CreateRequestCommand is deleted one second later: This is not
+  // efficient. For this reason, reuse current CreateRequestCommand.
+  logger->debug("CUID#%d - Reusing CreateRequestCommand", cuid);
+  SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup, this, wait);
+  e->commands.push_back(scom);
+  return false;
+}
+
 } // namespace aria2

+ 2 - 0
src/CreateRequestCommand.h

@@ -46,6 +46,8 @@ public:
 		       DownloadEngine* e);
 protected:
   virtual bool executeInternal();
+
+  virtual bool prepareForRetry(time_t wait);
 };
 
 } // namespace aria2