From 90abec8a362d6224bfff76d12fc9365fac36ddaa Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Apr 2013 21:46:31 +0900 Subject: Move initialization code in aria2::main to struct Context --- src/DownloadEngine.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/DownloadEngine.cc') diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 05478fe8..0f266b58 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -86,7 +86,7 @@ volatile sig_atomic_t globalHaltRequested = 0; DownloadEngine::DownloadEngine(const SharedHandle& eventPoll) : eventPoll_(eventPoll), haltRequested_(0), - noWait_(false), + noWait_(true), refreshInterval_(DEFAULT_REFRESH_INTERVAL), cookieStorage_(new CookieStorage()), #ifdef ENABLE_BITTORRENT @@ -139,11 +139,15 @@ void executeCommand(std::deque& commands, } } // namespace -void DownloadEngine::run() +int DownloadEngine::run(bool oneshot) { Timer cp; cp.reset(0); while(!commands_.empty() || !routineCommands_.empty()) { + if(!commands_.empty()) { + waitData(); + } + noWait_ = false; global::wallclock().reset(); calculateStatistics(); if(cp.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS >= @@ -156,12 +160,14 @@ void DownloadEngine::run() } executeCommand(routineCommands_, Command::STATUS_ALL); afterEachIteration(); - if(!commands_.empty()) { - waitData(); + if(oneshot) { + return 1; } - noWait_ = false; } - onEndOfRun(); + if(!oneshot) { + onEndOfRun(); + } + return 0; } void DownloadEngine::waitData() -- cgit