瀏覽代碼

2010-07-17 Tatsuhiro Tsujikawa <[email protected]>

	Count the number of command used in HTTP(S)/FTP and the number of
	connections in HTTP(S)/FTP independently. The former is used to
	determin whether additional command is needed.  The latter is used
	to report user to how many connections are used in a download.
	* src/AbstractCommand.cc
	* src/AbstractCommand.h
	* src/CreateRequestCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
Tatsuhiro Tsujikawa 15 年之前
父節點
當前提交
d0b727f6dc
共有 6 個文件被更改,包括 54 次插入15 次删除
  1. 12 0
      ChangeLog
  2. 12 4
      src/AbstractCommand.cc
  3. 8 4
      src/AbstractCommand.h
  4. 2 1
      src/CreateRequestCommand.cc
  5. 14 3
      src/RequestGroup.cc
  6. 6 3
      src/RequestGroup.h

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2010-07-17  Tatsuhiro Tsujikawa  <[email protected]>
+
+	Count the number of command used in HTTP(S)/FTP and the number of
+	connections in HTTP(S)/FTP independently. The former is used to
+	determin whether additional command is needed.  The latter is used
+	to report user to how many connections are used in a download.
+	* src/AbstractCommand.cc
+	* src/AbstractCommand.h
+	* src/CreateRequestCommand.cc
+	* src/RequestGroup.cc
+	* src/RequestGroup.h
+
 2010-07-17  Tatsuhiro Tsujikawa  <[email protected]>
 2010-07-17  Tatsuhiro Tsujikawa  <[email protected]>
 
 
 	Check status values: 200 and 206.
 	Check status values: 200 and 206.

+ 12 - 4
src/AbstractCommand.cc

@@ -79,18 +79,23 @@ AbstractCommand::AbstractCommand(cuid_t cuid,
                                  const SharedHandle<FileEntry>& fileEntry,
                                  const SharedHandle<FileEntry>& fileEntry,
                                  RequestGroup* requestGroup,
                                  RequestGroup* requestGroup,
                                  DownloadEngine* e,
                                  DownloadEngine* e,
-                                 const SocketHandle& s):
+                                 const SocketHandle& s,
+                                 bool incNumConnection):
   Command(cuid), checkPoint_(global::wallclock),
   Command(cuid), checkPoint_(global::wallclock),
   timeout_(requestGroup->getTimeout()),
   timeout_(requestGroup->getTimeout()),
   requestGroup_(requestGroup),
   requestGroup_(requestGroup),
   req_(req), fileEntry_(fileEntry), e_(e), socket_(s),
   req_(req), fileEntry_(fileEntry), e_(e), socket_(s),
   checkSocketIsReadable_(false), checkSocketIsWritable_(false),
   checkSocketIsReadable_(false), checkSocketIsWritable_(false),
-  nameResolverCheck_(false)
+  nameResolverCheck_(false),
+  incNumConnection_(incNumConnection)
 {
 {
   if(!socket_.isNull() && socket_->isOpen()) {
   if(!socket_.isNull() && socket_->isOpen()) {
     setReadCheckSocket(socket_);
     setReadCheckSocket(socket_);
   }
   }
-  requestGroup_->increaseStreamConnection();
+  if(incNumConnection_) {
+    requestGroup->increaseStreamConnection();
+  }
+  requestGroup_->increaseStreamCommand();
   requestGroup_->increaseNumCommand();
   requestGroup_->increaseNumCommand();
 }
 }
 
 
@@ -101,7 +106,10 @@ AbstractCommand::~AbstractCommand() {
   disableNameResolverCheck(asyncNameResolver_);
   disableNameResolverCheck(asyncNameResolver_);
 #endif // ENABLE_ASYNC_DNS
 #endif // ENABLE_ASYNC_DNS
   requestGroup_->decreaseNumCommand();
   requestGroup_->decreaseNumCommand();
-  requestGroup_->decreaseStreamConnection();
+  requestGroup_->decreaseStreamCommand();
+  if(incNumConnection_) {
+    requestGroup_->decreaseStreamConnection();
+  }
 }
 }
 
 
 bool AbstractCommand::execute() {
 bool AbstractCommand::execute() {

+ 8 - 4
src/AbstractCommand.h

@@ -75,6 +75,8 @@ private:
   SharedHandle<SocketCore> writeCheckTarget_;
   SharedHandle<SocketCore> writeCheckTarget_;
   bool nameResolverCheck_;
   bool nameResolverCheck_;
 
 
+  bool incNumConnection_;
+
 #ifdef ENABLE_ASYNC_DNS
 #ifdef ENABLE_ASYNC_DNS
   void setNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver);
   void setNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver);
 
 
@@ -218,10 +220,12 @@ protected:
     return requestGroup_->getPieceStorage();
     return requestGroup_->getPieceStorage();
   }
   }
 public:
 public:
-  AbstractCommand(cuid_t cuid, const SharedHandle<Request>& req,
-                  const SharedHandle<FileEntry>& fileEntry,
-                  RequestGroup* requestGroup, DownloadEngine* e,
-                  const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>());
+  AbstractCommand
+  (cuid_t cuid, const SharedHandle<Request>& req,
+   const SharedHandle<FileEntry>& fileEntry,
+   RequestGroup* requestGroup, DownloadEngine* e,
+   const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>(),
+   bool incNumConnection = true);
 
 
   virtual ~AbstractCommand();
   virtual ~AbstractCommand();
   bool execute();
   bool execute();

+ 2 - 1
src/CreateRequestCommand.cc

@@ -57,7 +57,8 @@ CreateRequestCommand::CreateRequestCommand(cuid_t cuid,
                                            RequestGroup* requestGroup,
                                            RequestGroup* requestGroup,
                                            DownloadEngine* e):
                                            DownloadEngine* e):
   AbstractCommand
   AbstractCommand
-  (cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e)
+  (cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e,
+   SharedHandle<SocketCore>(), false)
 {
 {
   setStatus(Command::STATUS_ONESHOT_REALTIME);
   setStatus(Command::STATUS_ONESHOT_REALTIME);
   disableReadCheckSocket();
   disableReadCheckSocket();

+ 14 - 3
src/RequestGroup.cc

@@ -119,6 +119,7 @@ RequestGroup::RequestGroup(const SharedHandle<Option>& option):
   option_(new Option(*option.get())),
   option_(new Option(*option.get())),
   numConcurrentCommand_(option->getAsInt(PREF_SPLIT)),
   numConcurrentCommand_(option->getAsInt(PREF_SPLIT)),
   numStreamConnection_(0),
   numStreamConnection_(0),
+  numStreamCommand_(0),
   numCommand_(0),
   numCommand_(0),
   saveControlFile_(true),
   saveControlFile_(true),
   progressInfoFile_(new NullProgressInfoFile()),
   progressInfoFile_(new NullProgressInfoFile()),
@@ -726,17 +727,17 @@ void RequestGroup::createNextCommand(std::vector<Command*>& commands,
 {
 {
   int numCommand;
   int numCommand;
   if(getTotalLength() == 0) {
   if(getTotalLength() == 0) {
-    if(numStreamConnection_ > 0) {
+    if(numStreamCommand_ > 0) {
       numCommand = 0;
       numCommand = 0;
     } else {
     } else {
       numCommand = 1;
       numCommand = 1;
     }
     }
   } else {
   } else {
-    if(numStreamConnection_ >= numConcurrentCommand_) {
+    if(numStreamCommand_ >= numConcurrentCommand_) {
       numCommand = 0;
       numCommand = 0;
     } else {
     } else {
       numCommand = std::min(downloadContext_->getNumPieces(),
       numCommand = std::min(downloadContext_->getNumPieces(),
-                            numConcurrentCommand_-numStreamConnection_);
+                            numConcurrentCommand_-numStreamCommand_);
     }
     }
   }
   }
   if(numCommand > 0) {
   if(numCommand > 0) {
@@ -831,6 +832,16 @@ void RequestGroup::validateTotalLength(uint64_t actualTotalLength) const
   validateTotalLength(getTotalLength(), actualTotalLength);
   validateTotalLength(getTotalLength(), actualTotalLength);
 }
 }
 
 
+void RequestGroup::increaseStreamCommand()
+{
+  ++numStreamCommand_;
+}
+
+void RequestGroup::decreaseStreamCommand()
+{
+  --numStreamCommand_;
+}
+
 void RequestGroup::increaseStreamConnection()
 void RequestGroup::increaseStreamConnection()
 {
 {
   ++numStreamConnection_;
   ++numStreamConnection_;

+ 6 - 3
src/RequestGroup.h

@@ -97,6 +97,8 @@ private:
    */
    */
   unsigned int numStreamConnection_;
   unsigned int numStreamConnection_;
 
 
+  unsigned int numStreamCommand_;
+
   unsigned int numCommand_;
   unsigned int numCommand_;
 
 
   SharedHandle<SegmentMan> segmentMan_;
   SharedHandle<SegmentMan> segmentMan_;
@@ -278,13 +280,14 @@ public:
 
 
   void setProgressInfoFile(const SharedHandle<BtProgressInfoFile>& progressInfoFile);
   void setProgressInfoFile(const SharedHandle<BtProgressInfoFile>& progressInfoFile);
 
 
+  void increaseStreamCommand();
+
+  void decreaseStreamCommand();
+
   void increaseStreamConnection();
   void increaseStreamConnection();
 
 
   void decreaseStreamConnection();
   void decreaseStreamConnection();
 
 
-  // Returns the number of connections used in HTTP(S)/FTP.
-  unsigned int getNumStreamConnection() { return numStreamConnection_; }
-
   unsigned int getNumConnection() const;
   unsigned int getNumConnection() const;
 
 
   void increaseNumCommand();
   void increaseNumCommand();