Fixed invalid connection count

pull/1/head
Tatsuhiro Tsujikawa 2007-07-05 15:14:00 +00:00
parent 800bc3a6c3
commit e52e0fa01f
9 changed files with 54 additions and 23 deletions

View File

@ -61,8 +61,7 @@ bool CheckIntegrityCommand::executeInternal()
return true; return true;
} }
if(_requestGroup->needsFileAllocation()) { if(_requestGroup->needsFileAllocation()) {
FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, _entry->getCurrentRequest(), _requestGroup, _requestGroup->getExistingFileLength()); FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, _entry->getCurrentRequest(), _requestGroup, _entry->popNextDownloadCommand(), _requestGroup->getExistingFileLength());
entry->setNextDownloadCommand(_entry->popNextDownloadCommand());
_e->_fileAllocationMan->pushFileAllocationEntry(entry); _e->_fileAllocationMan->pushFileAllocationEntry(entry);
} else { } else {
if(_timer.difference() <= _e->option->getAsInt(PREF_DIRECT_DOWNLOAD_TIMEOUT) && if(_timer.difference() <= _e->option->getAsInt(PREF_DIRECT_DOWNLOAD_TIMEOUT) &&

View File

@ -44,8 +44,9 @@ private:
public: public:
CheckIntegrityEntry(int cuid, CheckIntegrityEntry(int cuid,
const RequestHandle& currentRequest, const RequestHandle& currentRequest,
RequestGroup* requestGroup): RequestGroup* requestGroup,
RequestGroupEntry(cuid, currentRequest, requestGroup), DownloadCommand* nextDownloadCommand = 0):
RequestGroupEntry(cuid, currentRequest, requestGroup, nextDownloadCommand),
_validator(0) _validator(0)
{} {}

View File

@ -44,8 +44,9 @@ public:
FileAllocationEntry(int cuid, FileAllocationEntry(int cuid,
const RequestHandle& currentRequest, const RequestHandle& currentRequest,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadCommand* nextDownloadCommand = 0,
int64_t offset = 0): int64_t offset = 0):
RequestGroupEntry(cuid, currentRequest, requestGroup), RequestGroupEntry(cuid, currentRequest, requestGroup, nextDownloadCommand),
_offset(offset) _offset(offset)
{} {}

View File

@ -227,16 +227,14 @@ void RequestGroup::prepareForNextAction(int cuid, const RequestHandle& req, Down
// purge SegmentEntries // purge SegmentEntries
_segmentMan->purgeSegmentEntry(); _segmentMan->purgeSegmentEntry();
CheckIntegrityEntryHandle entry = new CheckIntegrityEntry(cuid, req, this); CheckIntegrityEntryHandle entry = new CheckIntegrityEntry(cuid, req, this, downloadCommand);
entry->setNextDownloadCommand(downloadCommand);
entry->initValidator(); entry->initValidator();
CheckIntegrityCommand* command = new CheckIntegrityCommand(cuid, this, e, entry); CheckIntegrityCommand* command = new CheckIntegrityCommand(cuid, this, e, entry);
e->commands.push_back(command); e->commands.push_back(command);
} else } else
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
if(needsFileAllocation()) { if(needsFileAllocation()) {
FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, req, this, existingFile.size()); FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, req, this, downloadCommand, existingFile.size());
entry->setNextDownloadCommand(downloadCommand);
e->_fileAllocationMan->pushFileAllocationEntry(entry); e->_fileAllocationMan->pushFileAllocationEntry(entry);
} else { } else {
if(downloadCommand) { if(downloadCommand) {

View File

@ -37,6 +37,8 @@
RequestGroupEntry::~RequestGroupEntry() RequestGroupEntry::~RequestGroupEntry()
{ {
if(_shouldAddNumConnection) {
--_requestGroup->numConnection; --_requestGroup->numConnection;
}
delete _nextDownloadCommand; delete _nextDownloadCommand;
} }

View File

@ -47,17 +47,24 @@ protected:
RequestHandle _currentRequest; RequestHandle _currentRequest;
RequestGroup* _requestGroup; RequestGroup* _requestGroup;
DownloadCommand* _nextDownloadCommand; DownloadCommand* _nextDownloadCommand;
bool _shouldAddNumConnection;
public: public:
RequestGroupEntry(int cuid, RequestGroupEntry(int cuid,
const RequestHandle& currentRequest, const RequestHandle& currentRequest,
RequestGroup* requestGroup): RequestGroup* requestGroup,
DownloadCommand* nextDownloadCommand = 0):
_cuid(cuid), _cuid(cuid),
_currentRequest(currentRequest), _currentRequest(currentRequest),
_requestGroup(requestGroup), _requestGroup(requestGroup),
_nextDownloadCommand(0) _nextDownloadCommand(nextDownloadCommand)
{ {
if(nextDownloadCommand) {
_shouldAddNumConnection = false;
} else {
_shouldAddNumConnection = true;
++_requestGroup->numConnection; ++_requestGroup->numConnection;
} }
}
virtual ~RequestGroupEntry(); virtual ~RequestGroupEntry();
@ -80,12 +87,12 @@ public:
{ {
return _requestGroup; return _requestGroup;
} }
/*
void setNextDownloadCommand(DownloadCommand* command) void setNextDownloadCommand(DownloadCommand* command)
{ {
_nextDownloadCommand = command; _nextDownloadCommand = command;
} }
*/
DownloadCommand* getNextDownloadCommand() const DownloadCommand* getNextDownloadCommand() const
{ {
return _nextDownloadCommand; return _nextDownloadCommand;

View File

@ -37,13 +37,13 @@
bool UriFileListParser::hasNext() const bool UriFileListParser::hasNext() const
{ {
return _ifs; return *_ifs;
} }
Strings UriFileListParser::next() Strings UriFileListParser::next()
{ {
string line; string line;
while(getline(_ifs, line)) { while(getline(*_ifs, line)) {
if(Util::trim(line) != "") { if(Util::trim(line) != "") {
Strings uris; Strings uris;
Util::slice(uris, line, '\t', true); Util::slice(uris, line, '\t', true);

View File

@ -41,9 +41,22 @@
class UriFileListParser { class UriFileListParser {
private: private:
string _filename; string _filename;
ifstream _ifs; istream* _ifs;
bool _deleteOnExit;
public: public:
UriFileListParser(const string& filename):_filename(filename), _ifs(filename.c_str()) {} UriFileListParser(const string& filename):_filename(filename), _ifs(new ifstream(filename.c_str())), _deleteOnExit(true) {}
UriFileListParser():_ifs(0) {}
UriFileListParser(istream& ifs):_filename("-"), _ifs(&ifs), _deleteOnExit(false)
{}
~UriFileListParser()
{
if(_deleteOnExit) {
delete _ifs;
}
}
bool hasNext() const; bool hasNext() const;

View File

@ -52,6 +52,7 @@
#include "UriFileListParser.h" #include "UriFileListParser.h"
#include "CookieBoxFactory.h" #include "CookieBoxFactory.h"
#include "a2algo.h" #include "a2algo.h"
#include "message.h"
#include <deque> #include <deque>
#include <algorithm> #include <algorithm>
#include <time.h> #include <time.h>
@ -211,7 +212,8 @@ void showUsage() {
cout << _(" -n, --no-netrc Disables netrc support.") << endl; cout << _(" -n, --no-netrc Disables netrc support.") << endl;
cout << _(" -i, --input-file=FILE Downloads URIs found in FILE. You can specify\n" cout << _(" -i, --input-file=FILE Downloads URIs found in FILE. You can specify\n"
" multiple URIs for a single entity: deliminate\n" " multiple URIs for a single entity: deliminate\n"
" URIs by Tab in a single line.") << endl; " URIs by Tab in a single line.\n"
" Reads input from stdin when '-' is specified.") << endl;
cout << _(" -j, --max-concurrent-downloads=N Set maximum number of concurrent downloads.\n" cout << _(" -j, --max-concurrent-downloads=N Set maximum number of concurrent downloads.\n"
" It should be used with -i option.\n" " It should be used with -i option.\n"
" Default: 5") << endl; " Default: 5") << endl;
@ -753,10 +755,18 @@ int main(int argc, char* argv[]) {
else else
#endif // ENABLE_METALINK #endif // ENABLE_METALINK
if(op->defined(PREF_INPUT_FILE)) { if(op->defined(PREF_INPUT_FILE)) {
UriFileListParser flparser(op->get(PREF_INPUT_FILE)); SharedHandle<UriFileListParser> flparser(0);
if(op->get(PREF_INPUT_FILE) == "-") {
flparser = new UriFileListParser(cin);
} else {
if(!File(op->get(PREF_INPUT_FILE)).isFile()) {
throw new FatalException(EX_FILE_OPEN, op->get(PREF_INPUT_FILE).c_str(), "No such file");
}
flparser = new UriFileListParser(op->get(PREF_INPUT_FILE));
}
RequestGroups groups; RequestGroups groups;
while(flparser.hasNext()) { while(flparser->hasNext()) {
Strings uris = flparser.next(); Strings uris = flparser->next();
if(!uris.empty()) { if(!uris.empty()) {
Strings xuris; Strings xuris;
ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT), ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT),