summaryrefslogtreecommitdiff
path: root/src/DownloadEngine.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-25 21:46:31 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-25 21:46:31 +0900
commit90abec8a362d6224bfff76d12fc9365fac36ddaa (patch)
tree115a8248adda60f01004bdae167571c3f95d3806 /src/DownloadEngine.cc
parentbbb978948d87790c6dfb78eaca1d47d45101443d (diff)
Move initialization code in aria2::main to struct Context
Diffstat (limited to 'src/DownloadEngine.cc')
-rw-r--r--src/DownloadEngine.cc18
1 files changed, 12 insertions, 6 deletions
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_(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<Command*>& 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()