summaryrefslogtreecommitdiff
path: root/src/RequestGroupMan.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2014-10-14 00:13:29 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2014-10-14 00:13:29 +0900
commitf72a303b8deb702a2ea4f63280302f88741da581 (patch)
tree9df1a81101fe93b1eb9b545559f0148dde504591 /src/RequestGroupMan.cc
parent09d79565376c03b3e735793703c1dc185d413c31 (diff)
Add --bt-detach-seed-only option
This option excludes seed only downloads when counting concurrent active downloads (-j option). This means that if -j3 is given and this option is turned on and 3 downloads are active and one of those enters seed mode, then it is excluded from active download count (thus it becomes 2), and the next download waiting in queue gets started. But be aware that seeding item is still recognized as active download in RPC method.
Diffstat (limited to 'src/RequestGroupMan.cc')
-rw-r--r--src/RequestGroupMan.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc
index 8921bfe1..b33e79e0 100644
--- a/src/RequestGroupMan.cc
+++ b/src/RequestGroupMan.cc
@@ -105,6 +105,7 @@ RequestGroupMan::RequestGroupMan
int maxSimultaneousDownloads,
const Option* option)
: maxSimultaneousDownloads_(maxSimultaneousDownloads),
+ numActive_(0),
option_(option),
serverStatMan_(std::make_shared<ServerStatMan>()),
maxOverallDownloadSpeedLimit_
@@ -140,6 +141,7 @@ bool RequestGroupMan::downloadFinished()
void RequestGroupMan::addRequestGroup
(const std::shared_ptr<RequestGroup>& group)
{
+ ++numActive_;
requestGroups_.push_back(group->getGID(), group);
}
@@ -320,6 +322,11 @@ public:
if(group->getNumCommand() == 0) {
collectStat(group);
const std::shared_ptr<DownloadContext>& dctx = group->getDownloadContext();
+
+ if(!group->isSeedOnlyEnabled()) {
+ e_->getRequestGroupMan()->decreaseNumActive();
+ }
+
// DownloadContext::resetDownloadStopTime() is only called when
// download completed. If
// DownloadContext::getDownloadStopTime().isZero() is true, then
@@ -453,11 +460,11 @@ std::vector<std::unique_ptr<Command>> createInitialCommand
void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
{
removeStoppedGroup(e);
- if(static_cast<size_t>(maxSimultaneousDownloads_) <= requestGroups_.size()) {
+ if(static_cast<size_t>(maxSimultaneousDownloads_) <= numActive_) {
return;
}
int count = 0;
- int num = maxSimultaneousDownloads_-requestGroups_.size();
+ int num = maxSimultaneousDownloads_ - numActive_;
std::vector<std::shared_ptr<RequestGroup> > pending;
while(count < num && (uriListParser_ || !reservedGroups_.empty())) {
@@ -488,6 +495,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
configureRequestGroup(groupToAdd);
groupToAdd->setRequestGroupMan(this);
groupToAdd->setState(RequestGroup::STATE_ACTIVE);
+ ++numActive_;
requestGroups_.push_back(groupToAdd->getGID(), groupToAdd);
try {
auto res = createInitialCommand(groupToAdd, e);
@@ -965,4 +973,10 @@ void RequestGroupMan::initWrDiskCache()
}
}
+void RequestGroupMan::decreaseNumActive()
+{
+ assert(numActive_ > 0);
+ --numActive_;
+}
+
} // namespace aria2