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.
pull/1/head
Tatsuhiro Tsujikawa 2011-05-15 23:35:06 +09:00
parent 7d14491389
commit 49b49c351a
8 changed files with 32 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -41,6 +41,7 @@
#include "wallclock.h"
#include "util.h"
#include "fmt.h"
#include "DownloadEngine.h"
namespace aria2 {
@ -64,6 +65,7 @@ void BtStopDownloadCommand::preProcess()
" --bt-stop-timeout option.",
util::itos(requestGroup_->getGID()).c_str()));
requestGroup_->setForceHaltRequested(true);
getDownloadEngine()->setRefreshInterval(0);
enableExit();
}
}

View File

@ -94,7 +94,10 @@ bool CreateRequestCommand::executeInternal()
if(getSegmentMan()) {
getSegmentMan()->ignoreSegmentFor(getFileEntry());
}
throw DL_ABORT_EX("No URI available.");
// In this case, the error might be already set in RequestGroup,
// so use it here.
throw DL_ABORT_EX2("No URI available.",
getRequestGroup()->getLastErrorCode());
} else if(getRequest()->getWakeTime() > global::wallclock) {
A2_LOG_DEBUG("This request object is still sleeping.");
getFileEntry()->poolRequest(getRequest());

View File

@ -385,6 +385,7 @@ void PeerInteractionCommand::onFailure(const Exception& err)
{
requestGroup_->setLastErrorCode(err.getErrorCode());
requestGroup_->setHaltRequested(true);
getDownloadEngine()->setRefreshInterval(0);
}
bool PeerInteractionCommand::exitBeforeExecute()

View File

@ -486,6 +486,11 @@ public:
lastErrorCode_ = code;
}
error_code::Value getLastErrorCode() const
{
return lastErrorCode_;
}
void saveControlFile() const;
void removeControlFile() const;

View File

@ -536,6 +536,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
}
if(count > 0) {
e->setNoWait(true);
e->setRefreshInterval(0);
A2_LOG_DEBUG(fmt("%d RequestGroup(s) added.", count));
}
}

View File

@ -395,6 +395,7 @@ SharedHandle<ValueBase> removeDownload
} else {
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
}
e->setRefreshInterval(0);
}
return createGIDResponse(gid);
}
@ -452,6 +453,7 @@ SharedHandle<ValueBase> pauseDownload
group = e->getRequestGroupMan()->findReservedGroup(gid);
}
if(group && pauseRequestGroup(group, reserved, forcePause)) {
e->setRefreshInterval(0);
return createGIDResponse(gid);
} else {
throw DL_ABORT_EX

View File

@ -89,6 +89,7 @@ bool TrackerWatcherCommand::execute() {
return true;
} else {
trackerRequestGroup_->setForceHaltRequested(true);
e_->setRefreshInterval(0);
e_->addCommand(this);
return false;
}