mirror of https://github.com/aria2/aria2
2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Throw exception if binding listening port is failed. Removed RequestGroupMan::getInitialCommand(). Use fillRequestGroupFromReserver() instead. Delete commands for RequestGroup which has errors when it is being added. * src/BtSetup.cc * src/DownloadEngine.cc * src/DownloadEngine.h * src/DownloadEngineFactory.cc * src/MultiUrlRequestInfo.cc * src/RequestGroupMan.cc * src/RequestGroupMan.h * test/RequestGroupManTest.ccpull/1/head
parent
a71b642db1
commit
07dc5bdfee
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Throw exception if binding listening port is failed. Removed
|
||||||
|
RequestGroupMan::getInitialCommand(). Use
|
||||||
|
fillRequestGroupFromReserver() instead. Delete commands for
|
||||||
|
RequestGroup which has errors when it is being added.
|
||||||
|
* src/BtSetup.cc
|
||||||
|
* src/DownloadEngine.cc
|
||||||
|
* src/DownloadEngine.h
|
||||||
|
* src/DownloadEngineFactory.cc
|
||||||
|
* src/MultiUrlRequestInfo.cc
|
||||||
|
* src/RequestGroupMan.cc
|
||||||
|
* src/RequestGroupMan.h
|
||||||
|
* test/RequestGroupManTest.cc
|
||||||
|
|
||||||
2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-10-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Fixed the bug that when downloading more than one torrent,
|
Fixed the bug that when downloading more than one torrent,
|
||||||
|
|
|
@ -153,10 +153,11 @@ void BtSetup::setup(std::deque<Command*>& commands,
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
if(listenCommand->bindPort(port, seq)) {
|
if(listenCommand->bindPort(port, seq)) {
|
||||||
btRuntime->setListenPort(port);
|
btRuntime->setListenPort(port);
|
||||||
commands.push_back(listenCommand);
|
// Add command to DownloadEngine directly.
|
||||||
|
e->commands.push_back(listenCommand);
|
||||||
} else {
|
} else {
|
||||||
_logger->error(_("Errors occurred while binding port.\n"));
|
|
||||||
delete listenCommand;
|
delete listenCommand;
|
||||||
|
throw DL_ABORT_EX(_("Errors occurred while binding port.\n"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PeerListenCommand* listenCommand = PeerListenCommand::getInstance(e);
|
PeerListenCommand* listenCommand = PeerListenCommand::getInstance(e);
|
||||||
|
|
|
@ -229,13 +229,6 @@ void DownloadEngine::requestHalt()
|
||||||
_requestGroupMan->halt();
|
_requestGroupMan->halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadEngine::fillCommand()
|
|
||||||
{
|
|
||||||
std::deque<Command*> commands;
|
|
||||||
_requestGroupMan->getInitialCommands(commands, this);
|
|
||||||
addCommand(commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadEngine::setStatCalc(const StatCalcHandle& statCalc)
|
void DownloadEngine::setStatCalc(const StatCalcHandle& statCalc)
|
||||||
{
|
{
|
||||||
_statCalc = statCalc;
|
_statCalc = statCalc;
|
||||||
|
|
|
@ -184,8 +184,6 @@ public:
|
||||||
|
|
||||||
void addCommand(const std::deque<Command*>& commands);
|
void addCommand(const std::deque<Command*>& commands);
|
||||||
|
|
||||||
void fillCommand();
|
|
||||||
|
|
||||||
void setStatCalc(const SharedHandle<StatCalc>& statCalc);
|
void setStatCalc(const SharedHandle<StatCalc>& statCalc);
|
||||||
|
|
||||||
bool isHaltRequested() const
|
bool isHaltRequested() const
|
||||||
|
|
|
@ -74,24 +74,11 @@ DownloadEngineFactory::DownloadEngineFactory():
|
||||||
_logger(LogFactory::getInstance()) {}
|
_logger(LogFactory::getInstance()) {}
|
||||||
|
|
||||||
DownloadEngineHandle
|
DownloadEngineHandle
|
||||||
DownloadEngineFactory::newDownloadEngine(Option* op,
|
DownloadEngineFactory::newDownloadEngine
|
||||||
const RequestGroups& requestGroups)
|
(Option* op, const RequestGroups& requestGroups)
|
||||||
{
|
{
|
||||||
RequestGroups workingSet;
|
const size_t MAX_CONCURRENT_DOWNLOADS =
|
||||||
RequestGroups reservedSet;
|
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS);
|
||||||
const size_t MAX_CONCURRENT_DOWNLOADS = op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS);
|
|
||||||
if(MAX_CONCURRENT_DOWNLOADS < requestGroups.size()) {
|
|
||||||
workingSet.insert(workingSet.end(),
|
|
||||||
requestGroups.begin(),
|
|
||||||
requestGroups.begin()+MAX_CONCURRENT_DOWNLOADS);
|
|
||||||
|
|
||||||
reservedSet.insert(reservedSet.end(),
|
|
||||||
requestGroups.begin()+MAX_CONCURRENT_DOWNLOADS,
|
|
||||||
requestGroups.end());
|
|
||||||
} else {
|
|
||||||
workingSet = requestGroups;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedHandle<EventPoll> eventPoll;
|
SharedHandle<EventPoll> eventPoll;
|
||||||
#ifdef HAVE_EPOLL
|
#ifdef HAVE_EPOLL
|
||||||
if(op->get(PREF_EVENT_POLL) == V_EPOLL) {
|
if(op->get(PREF_EVENT_POLL) == V_EPOLL) {
|
||||||
|
@ -100,7 +87,7 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
|
||||||
eventPoll = ep;
|
eventPoll = ep;
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX("Initializing EpollEventPoll failed."
|
throw DL_ABORT_EX("Initializing EpollEventPoll failed."
|
||||||
" Try --event-poll=select");
|
" Try --event-poll=select");
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // HAVE_EPLL
|
#endif // HAVE_EPLL
|
||||||
|
@ -113,9 +100,8 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
|
||||||
e->option = op;
|
e->option = op;
|
||||||
|
|
||||||
RequestGroupManHandle
|
RequestGroupManHandle
|
||||||
requestGroupMan(new RequestGroupMan(workingSet, MAX_CONCURRENT_DOWNLOADS,
|
requestGroupMan(new RequestGroupMan(requestGroups, MAX_CONCURRENT_DOWNLOADS,
|
||||||
op));
|
op));
|
||||||
requestGroupMan->addReservedGroup(reservedSet);
|
|
||||||
e->_requestGroupMan = requestGroupMan;
|
e->_requestGroupMan = requestGroupMan;
|
||||||
e->_fileAllocationMan.reset(new FileAllocationMan());
|
e->_fileAllocationMan.reset(new FileAllocationMan());
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
|
|
|
@ -160,7 +160,6 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
|
||||||
(_option->getAsInt(PREF_SERVER_STAT_TIMEOUT));
|
(_option->getAsInt(PREF_SERVER_STAT_TIMEOUT));
|
||||||
}
|
}
|
||||||
e->setStatCalc(_statCalc);
|
e->setStatCalc(_statCalc);
|
||||||
e->fillCommand();
|
|
||||||
|
|
||||||
// The number of simultaneous download is specified by
|
// The number of simultaneous download is specified by
|
||||||
// PREF_MAX_CONCURRENT_DOWNLOADS.
|
// PREF_MAX_CONCURRENT_DOWNLOADS.
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace aria2 {
|
||||||
RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups,
|
RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups,
|
||||||
unsigned int maxSimultaneousDownloads,
|
unsigned int maxSimultaneousDownloads,
|
||||||
const Option* option):
|
const Option* option):
|
||||||
_requestGroups(requestGroups),
|
_reservedGroups(requestGroups),
|
||||||
_logger(LogFactory::getInstance()),
|
_logger(LogFactory::getInstance()),
|
||||||
_maxSimultaneousDownloads(maxSimultaneousDownloads),
|
_maxSimultaneousDownloads(maxSimultaneousDownloads),
|
||||||
_gidCounter(0),
|
_gidCounter(0),
|
||||||
|
@ -445,20 +445,25 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
||||||
while(count < num && !_reservedGroups.empty()) {
|
while(count < num && !_reservedGroups.empty()) {
|
||||||
RequestGroupHandle groupToAdd = _reservedGroups.front();
|
RequestGroupHandle groupToAdd = _reservedGroups.front();
|
||||||
_reservedGroups.pop_front();
|
_reservedGroups.pop_front();
|
||||||
|
Commands commands;
|
||||||
try {
|
try {
|
||||||
if(!groupToAdd->isDependencyResolved()) {
|
if(!groupToAdd->isDependencyResolved()) {
|
||||||
temp.push_back(groupToAdd);
|
temp.push_back(groupToAdd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
configureRequestGroup(groupToAdd);
|
configureRequestGroup(groupToAdd);
|
||||||
Commands commands;
|
|
||||||
createInitialCommand(groupToAdd, commands, e);
|
createInitialCommand(groupToAdd, commands, e);
|
||||||
_requestGroups.push_back(groupToAdd);
|
_requestGroups.push_back(groupToAdd);
|
||||||
++count;
|
++count;
|
||||||
e->addCommand(commands);
|
e->addCommand(commands);
|
||||||
|
commands.clear();
|
||||||
executeStartHook(groupToAdd, e->option);
|
executeStartHook(groupToAdd, e->option);
|
||||||
} catch(RecoverableException& ex) {
|
} catch(RecoverableException& ex) {
|
||||||
_logger->error(EX_EXCEPTION_CAUGHT, ex);
|
_logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||||
|
_logger->debug("Deleting temporal commands.");
|
||||||
|
std::for_each(commands.begin(), commands.end(), Deleter());
|
||||||
|
commands.clear();
|
||||||
|
_logger->debug("Commands deleted");
|
||||||
groupToAdd->releaseRuntimeResource(e);
|
groupToAdd->releaseRuntimeResource(e);
|
||||||
_downloadResults.push_back(groupToAdd->createDownloadResult());
|
_downloadResults.push_back(groupToAdd->createDownloadResult());
|
||||||
}
|
}
|
||||||
|
@ -472,29 +477,6 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestGroupMan::getInitialCommands(std::deque<Command*>& commands,
|
|
||||||
DownloadEngine* e)
|
|
||||||
{
|
|
||||||
for(RequestGroups::iterator itr = _requestGroups.begin();
|
|
||||||
itr != _requestGroups.end();) {
|
|
||||||
try {
|
|
||||||
if((*itr)->isDependencyResolved()) {
|
|
||||||
configureRequestGroup(*itr);
|
|
||||||
createInitialCommand(*itr, commands, e);
|
|
||||||
executeStartHook(*itr, e->option);
|
|
||||||
++itr;
|
|
||||||
} else {
|
|
||||||
_reservedGroups.push_front((*itr));
|
|
||||||
itr = _requestGroups.erase(itr);
|
|
||||||
}
|
|
||||||
} catch(RecoverableException& e) {
|
|
||||||
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
|
||||||
_downloadResults.push_back((*itr)->createDownloadResult());
|
|
||||||
itr = _requestGroups.erase(itr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RequestGroupMan::save()
|
void RequestGroupMan::save()
|
||||||
{
|
{
|
||||||
for(RequestGroups::iterator itr = _requestGroups.begin();
|
for(RequestGroups::iterator itr = _requestGroups.begin();
|
||||||
|
|
|
@ -97,8 +97,6 @@ public:
|
||||||
|
|
||||||
void forceHalt();
|
void forceHalt();
|
||||||
|
|
||||||
void getInitialCommands(std::deque<Command*>& commands, DownloadEngine* e);
|
|
||||||
|
|
||||||
void removeStoppedGroup(DownloadEngine* e);
|
void removeStoppedGroup(DownloadEngine* e);
|
||||||
|
|
||||||
void fillRequestGroupFromReserver(DownloadEngine* e);
|
void fillRequestGroupFromReserver(DownloadEngine* e);
|
||||||
|
|
|
@ -54,11 +54,11 @@ void RequestGroupManTest::testIsSameFileBeingDownloaded()
|
||||||
rg1->setDownloadContext(dctx1);
|
rg1->setDownloadContext(dctx1);
|
||||||
rg2->setDownloadContext(dctx2);
|
rg2->setDownloadContext(dctx2);
|
||||||
|
|
||||||
RequestGroups rgs;
|
RequestGroupMan gm(std::deque<SharedHandle<RequestGroup> >(), 1,
|
||||||
rgs.push_back(rg1);
|
_option.get());
|
||||||
rgs.push_back(rg2);
|
|
||||||
|
|
||||||
RequestGroupMan gm(rgs, 1, _option.get());
|
gm.addRequestGroup(rg1);
|
||||||
|
gm.addRequestGroup(rg2);
|
||||||
|
|
||||||
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
|
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue