diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-07-17 03:23:56 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-07-17 03:23:56 +0000 |
| commit | d0b727f6dc7131ea5c478bcfdff3b0408f2b26f3 (patch) | |
| tree | f501ae4dfa91fd00a28076c762dc67d4dea6cb17 /src | |
| parent | 036abeee1182ccac0c80351d7d7dd3cbac7ae3ac (diff) | |
2010-07-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractCommand.cc | 16 | ||||
| -rw-r--r-- | src/AbstractCommand.h | 12 | ||||
| -rw-r--r-- | src/CreateRequestCommand.cc | 3 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 17 | ||||
| -rw-r--r-- | src/RequestGroup.h | 9 |
5 files changed, 42 insertions, 15 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index fde9c7e5..29e9beb5 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -79,18 +79,23 @@ AbstractCommand::AbstractCommand(cuid_t cuid, const SharedHandle<FileEntry>& fileEntry, RequestGroup* requestGroup, DownloadEngine* e, - const SocketHandle& s): + const SocketHandle& s, + bool incNumConnection): Command(cuid), checkPoint_(global::wallclock), timeout_(requestGroup->getTimeout()), requestGroup_(requestGroup), req_(req), fileEntry_(fileEntry), e_(e), socket_(s), checkSocketIsReadable_(false), checkSocketIsWritable_(false), - nameResolverCheck_(false) + nameResolverCheck_(false), + incNumConnection_(incNumConnection) { if(!socket_.isNull() && socket_->isOpen()) { setReadCheckSocket(socket_); } - requestGroup_->increaseStreamConnection(); + if(incNumConnection_) { + requestGroup->increaseStreamConnection(); + } + requestGroup_->increaseStreamCommand(); requestGroup_->increaseNumCommand(); } @@ -101,7 +106,10 @@ AbstractCommand::~AbstractCommand() { disableNameResolverCheck(asyncNameResolver_); #endif // ENABLE_ASYNC_DNS requestGroup_->decreaseNumCommand(); - requestGroup_->decreaseStreamConnection(); + requestGroup_->decreaseStreamCommand(); + if(incNumConnection_) { + requestGroup_->decreaseStreamConnection(); + } } bool AbstractCommand::execute() { diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 619e6af7..8dd5a15b 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -75,6 +75,8 @@ private: SharedHandle<SocketCore> writeCheckTarget_; bool nameResolverCheck_; + bool incNumConnection_; + #ifdef ENABLE_ASYNC_DNS void setNameResolverCheck(const SharedHandle<AsyncNameResolver>& resolver); @@ -218,10 +220,12 @@ protected: return requestGroup_->getPieceStorage(); } 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(); bool execute(); diff --git a/src/CreateRequestCommand.cc b/src/CreateRequestCommand.cc index cc62fef4..62783d9b 100644 --- a/src/CreateRequestCommand.cc +++ b/src/CreateRequestCommand.cc @@ -57,7 +57,8 @@ CreateRequestCommand::CreateRequestCommand(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e): AbstractCommand - (cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e) + (cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e, + SharedHandle<SocketCore>(), false) { setStatus(Command::STATUS_ONESHOT_REALTIME); disableReadCheckSocket(); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 148b2e12..da3e677c 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -119,6 +119,7 @@ RequestGroup::RequestGroup(const SharedHandle<Option>& option): option_(new Option(*option.get())), numConcurrentCommand_(option->getAsInt(PREF_SPLIT)), numStreamConnection_(0), + numStreamCommand_(0), numCommand_(0), saveControlFile_(true), progressInfoFile_(new NullProgressInfoFile()), @@ -726,17 +727,17 @@ void RequestGroup::createNextCommand(std::vector<Command*>& commands, { int numCommand; if(getTotalLength() == 0) { - if(numStreamConnection_ > 0) { + if(numStreamCommand_ > 0) { numCommand = 0; } else { numCommand = 1; } } else { - if(numStreamConnection_ >= numConcurrentCommand_) { + if(numStreamCommand_ >= numConcurrentCommand_) { numCommand = 0; } else { numCommand = std::min(downloadContext_->getNumPieces(), - numConcurrentCommand_-numStreamConnection_); + numConcurrentCommand_-numStreamCommand_); } } if(numCommand > 0) { @@ -831,6 +832,16 @@ void RequestGroup::validateTotalLength(uint64_t actualTotalLength) const validateTotalLength(getTotalLength(), actualTotalLength); } +void RequestGroup::increaseStreamCommand() +{ + ++numStreamCommand_; +} + +void RequestGroup::decreaseStreamCommand() +{ + --numStreamCommand_; +} + void RequestGroup::increaseStreamConnection() { ++numStreamConnection_; diff --git a/src/RequestGroup.h b/src/RequestGroup.h index df29fbe3..b1cf8573 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -97,6 +97,8 @@ private: */ unsigned int numStreamConnection_; + unsigned int numStreamCommand_; + unsigned int numCommand_; SharedHandle<SegmentMan> segmentMan_; @@ -278,13 +280,14 @@ public: void setProgressInfoFile(const SharedHandle<BtProgressInfoFile>& progressInfoFile); + void increaseStreamCommand(); + + void decreaseStreamCommand(); + void increaseStreamConnection(); void decreaseStreamConnection(); - // Returns the number of connections used in HTTP(S)/FTP. - unsigned int getNumStreamConnection() { return numStreamConnection_; } - unsigned int getNumConnection() const; void increaseNumCommand(); |
