summaryrefslogtreecommitdiff
path: root/src/AbstractCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-05-15 23:35:06 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-05-15 23:35:06 +0900
commit49b49c351ab0e5d464d158f2d103333371d9c42a (patch)
tree835330b6def8caf42e92d68bd97343f4a7e87a9e /src/AbstractCommand.cc
parent7d144913891c64ef1f01d5279b86066f8125f080 (diff)
Eliminated few seconds delay when downloads stop or pause.
The delay is caused because some Commands are only called in certain interval(called refreshInterval, default, 1000ms). In aria2 download stops when all Commands associated to it are stopped. Since some Commands are called in each 1000ms by default, as mentioned before, we have to wait for them. To fix this issue, we call DownloadEngine::setRefreshInterval(0) when pausing/stopping downloads. DownloadEngine::setRefreshInterval(0) makes refreshInterval 0 in one shot. When all segments are ignored, now DownloadFailureException is thrown. And stop the download immediately. As described earlier, we call DownloadEngine::setRefreshInterval(0) in catch block of DownloadFailureException to eliminate delay.
Diffstat (limited to 'src/AbstractCommand.cc')
-rw-r--r--src/AbstractCommand.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index f9c47358..7d096e19 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -211,7 +211,10 @@ bool AbstractCommand::execute() {
// no URIs available, so don't retry.
if(getSegmentMan()->allSegmentsIgnored()) {
A2_LOG_DEBUG("All segments are ignored.");
- return true;
+ // In this case, the error might be already set in
+ // RequestGroup, so use it here.
+ throw DOWNLOAD_FAILURE_EXCEPTION2
+ ("No URI available.", requestGroup_->getLastErrorCode());
} else {
return prepareForRetry(1);
}
@@ -265,19 +268,19 @@ bool AbstractCommand::execute() {
return false;
}
} catch(DlAbortEx& err) {
- if(!req_) {
- A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, err);
- } else {
+ requestGroup_->setLastErrorCode(err.getErrorCode());
+ if(req_) {
A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
getCuid(),
req_->getUri().c_str()),
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
err));
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
- requestGroup_->setLastErrorCode(err.getErrorCode());
if(err.getErrorCode() == error_code::CANNOT_RESUME) {
requestGroup_->increaseResumeFailureCount();
}
+ } else {
+ A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, err);
}
onAbort();
tryReserved();
@@ -316,12 +319,19 @@ bool AbstractCommand::execute() {
return prepareForRetry(0);
}
} catch(DownloadFailureException& err) {
- A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
requestGroup_->setLastErrorCode(err.getErrorCode());
if(req_) {
+ A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
+ getCuid(),
+ req_->getUri().c_str()),
+ DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
+ err));
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
+ } else {
+ A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
}
requestGroup_->setHaltRequested(true);
+ getDownloadEngine()->setRefreshInterval(0);
return true;
}
}