summaryrefslogtreecommitdiff
path: root/src/FileAllocationCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
commit048a2cf59737f761876e81a77e8d064c45c752d7 (patch)
tree65c9d5498aafe6a8c8e640ddfcc43c7013504d0d /src/FileAllocationCommand.cc
parente26bbbb9eee140ba24402fe872a752b42f0077de (diff)
2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented BitTorrent/http/ftp integrated download. I've rewritten lots of files and now some headers have forward class declarations to reduce compile time. The implementation is extremely alpha stage, I recommend to use this for testing purpose only.
Diffstat (limited to 'src/FileAllocationCommand.cc')
-rw-r--r--src/FileAllocationCommand.cc51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc
index 554086d8..01a24d65 100644
--- a/src/FileAllocationCommand.cc
+++ b/src/FileAllocationCommand.cc
@@ -33,45 +33,48 @@
*/
/* copyright --> */
#include "FileAllocationCommand.h"
-#include "InitiateConnectionCommandFactory.h"
+#include "FileAllocationMan.h"
+#include "FileAllocationEntry.h"
#include "message.h"
#include "DownloadCommand.h"
#include "prefs.h"
#include "Util.h"
+FileAllocationCommand::FileAllocationCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const FileAllocationEntryHandle& fileAllocationEntry):
+ RealtimeCommand(cuid, requestGroup, e),
+ _fileAllocationEntry(fileAllocationEntry) {}
+
+FileAllocationCommand::~FileAllocationCommand() {}
+
bool FileAllocationCommand::executeInternal()
{
- _fileAllocationEntry->allocateChunk();
-
- if(_fileAllocationEntry->finished()) {
- logger->debug(MSG_ALLOCATION_COMPLETED,
- _timer.difference(),
- Util::llitos(_requestGroup->getTotalLength(), true).c_str());
-
- _e->_fileAllocationMan->markCurrentFileAllocationEntryDone();
-
- if(_timer.difference() <= _e->option->getAsInt(PREF_DIRECT_DOWNLOAD_TIMEOUT) &&
- _fileAllocationEntry->getNextDownloadCommand()) {
- _e->commands.push_back(_fileAllocationEntry->popNextDownloadCommand());
- } else {
- Commands commands = _requestGroup->createNextCommandWithAdj(_e, -1);
- Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, _fileAllocationEntry->getCurrentRequest(), _requestGroup, _e);
+ if(_e->isHaltRequested()) {
+ return true;
+ }
+ try {
+ _fileAllocationEntry->allocateChunk();
+ if(_fileAllocationEntry->finished()) {
+ logger->debug(MSG_ALLOCATION_COMPLETED,
+ _timer.difference(),
+ Util::llitos(_requestGroup->getTotalLength(), true).c_str());
+ _e->_fileAllocationMan->markCurrentFileAllocationEntryDone();
+
+ _e->addCommand(_fileAllocationEntry->prepareForNextAction(_e));
- commands.push_front(command);
-
- _e->addCommand(commands);
+ return true;
+ } else {
+ _e->commands.push_back(this);
+ return false;
}
- return true;
- } else {
- _e->commands.push_back(this);
- return false;
+ } catch(Exception* e) {
+ _e->_fileAllocationMan->markCurrentFileAllocationEntryDone();
+ throw;
}
}
bool FileAllocationCommand::handleException(Exception* e)
{
logger->error(MSG_FILE_ALLOCATION_FAILURE, e, cuid);
- delete e;
logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid, _requestGroup->getFilePath().c_str());
return true;
}