Explorar el Código

2008-01-07 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed the bug that SegmentMan::completeSegment() is not called
	even if Segment is complete when --lowest-speed-limit is 
enabled.
	BUG#1864525
	* src/DownloadCommand.{h, cc}
Tatsuhiro Tsujikawa hace 18 años
padre
commit
574e1b3db8
Se han modificado 3 ficheros con 24 adiciones y 10 borrados
  1. 7 0
      ChangeLog
  2. 16 10
      src/DownloadCommand.cc
  3. 1 0
      src/DownloadCommand.h

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-01-07  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed the bug that SegmentMan::completeSegment() is not called
+	even if Segment is complete when --lowest-speed-limit is enabled.
+	BUG#1864525
+	* src/DownloadCommand.{h, cc}
+
 2008-01-06  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed: hash algorithm 'sha1' is always used. 

+ 16 - 10
src/DownloadCommand.cc

@@ -118,16 +118,6 @@ bool DownloadCommand::executeInternal() {
     //segment->writtenLength += infbufSize;
     peerStat->updateDownloadLength(infbufSize);
   }
-  // calculate downloading speed
-  if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) {
-    int32_t nowSpeed = peerStat->calculateDownloadSpeed();
-    if(lowestDownloadSpeedLimit > 0 &&  nowSpeed <= lowestDownloadSpeedLimit) {
-      throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED,
-			  nowSpeed,
-			  lowestDownloadSpeedLimit,
-			  req->getHost().c_str());
-    }
-  }
   if(_requestGroup->getTotalLength() != 0 && bufSize == 0) {
     throw new DlRetryEx(EX_GOT_EOF);
   }
@@ -137,14 +127,30 @@ bool DownloadCommand::executeInternal() {
     if(!transferDecoder.isNull()) transferDecoder->end();
     logger->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, cuid);
     validatePieceHash(segment);
+    checkLowestDownloadSpeed();
     // this unit is going to download another segment.
     return prepareForNextSegment();
   } else {
+    checkLowestDownloadSpeed();
     e->commands.push_back(this);
     return false;
   }
 }
 
+void DownloadCommand::checkLowestDownloadSpeed() const
+{
+  // calculate downloading speed
+  if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) {
+    int32_t nowSpeed = peerStat->calculateDownloadSpeed();
+    if(lowestDownloadSpeedLimit > 0 &&  nowSpeed <= lowestDownloadSpeedLimit) {
+      throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED,
+			  nowSpeed,
+			  lowestDownloadSpeedLimit,
+			  req->getHost().c_str());
+    }
+  }
+}
+
 bool DownloadCommand::prepareForNextSegment() {
   if(_requestGroup->downloadFinished()) {
 #ifdef ENABLE_MESSAGE_DIGEST

+ 1 - 0
src/DownloadCommand.h

@@ -51,6 +51,7 @@ private:
 
   void validatePieceHash(const SegmentHandle& segment);
 
+  void checkLowestDownloadSpeed() const;
 protected:
   TransferEncodingHandle transferDecoder;