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
pull/1/head
Tatsuhiro Tsujikawa 2009-10-31 09:53:23 +00:00
parent a71b642db1
commit 07dc5bdfee
9 changed files with 35 additions and 63 deletions

View File

@ -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>
Fixed the bug that when downloading more than one torrent,

View File

@ -153,10 +153,11 @@ void BtSetup::setup(std::deque<Command*>& commands,
uint16_t port;
if(listenCommand->bindPort(port, seq)) {
btRuntime->setListenPort(port);
commands.push_back(listenCommand);
// Add command to DownloadEngine directly.
e->commands.push_back(listenCommand);
} else {
_logger->error(_("Errors occurred while binding port.\n"));
delete listenCommand;
throw DL_ABORT_EX(_("Errors occurred while binding port.\n"));
}
} else {
PeerListenCommand* listenCommand = PeerListenCommand::getInstance(e);

View File

@ -229,13 +229,6 @@ void DownloadEngine::requestHalt()
_requestGroupMan->halt();
}
void DownloadEngine::fillCommand()
{
std::deque<Command*> commands;
_requestGroupMan->getInitialCommands(commands, this);
addCommand(commands);
}
void DownloadEngine::setStatCalc(const StatCalcHandle& statCalc)
{
_statCalc = statCalc;

View File

@ -184,8 +184,6 @@ public:
void addCommand(const std::deque<Command*>& commands);
void fillCommand();
void setStatCalc(const SharedHandle<StatCalc>& statCalc);
bool isHaltRequested() const

View File

@ -74,24 +74,11 @@ DownloadEngineFactory::DownloadEngineFactory():
_logger(LogFactory::getInstance()) {}
DownloadEngineHandle
DownloadEngineFactory::newDownloadEngine(Option* op,
const RequestGroups& requestGroups)
DownloadEngineFactory::newDownloadEngine
(Option* op, const RequestGroups& requestGroups)
{
RequestGroups workingSet;
RequestGroups reservedSet;
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;
}
const size_t MAX_CONCURRENT_DOWNLOADS =
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS);
SharedHandle<EventPoll> eventPoll;
#ifdef HAVE_EPOLL
if(op->get(PREF_EVENT_POLL) == V_EPOLL) {
@ -100,7 +87,7 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
eventPoll = ep;
} else {
throw DL_ABORT_EX("Initializing EpollEventPoll failed."
" Try --event-poll=select");
" Try --event-poll=select");
}
} else
#endif // HAVE_EPLL
@ -113,9 +100,8 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
e->option = op;
RequestGroupManHandle
requestGroupMan(new RequestGroupMan(workingSet, MAX_CONCURRENT_DOWNLOADS,
requestGroupMan(new RequestGroupMan(requestGroups, MAX_CONCURRENT_DOWNLOADS,
op));
requestGroupMan->addReservedGroup(reservedSet);
e->_requestGroupMan = requestGroupMan;
e->_fileAllocationMan.reset(new FileAllocationMan());
#ifdef ENABLE_MESSAGE_DIGEST

View File

@ -160,7 +160,6 @@ downloadresultcode::RESULT MultiUrlRequestInfo::execute()
(_option->getAsInt(PREF_SERVER_STAT_TIMEOUT));
}
e->setStatCalc(_statCalc);
e->fillCommand();
// The number of simultaneous download is specified by
// PREF_MAX_CONCURRENT_DOWNLOADS.

View File

@ -72,7 +72,7 @@ namespace aria2 {
RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups,
unsigned int maxSimultaneousDownloads,
const Option* option):
_requestGroups(requestGroups),
_reservedGroups(requestGroups),
_logger(LogFactory::getInstance()),
_maxSimultaneousDownloads(maxSimultaneousDownloads),
_gidCounter(0),
@ -445,20 +445,25 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
while(count < num && !_reservedGroups.empty()) {
RequestGroupHandle groupToAdd = _reservedGroups.front();
_reservedGroups.pop_front();
Commands commands;
try {
if(!groupToAdd->isDependencyResolved()) {
temp.push_back(groupToAdd);
continue;
}
configureRequestGroup(groupToAdd);
Commands commands;
createInitialCommand(groupToAdd, commands, e);
_requestGroups.push_back(groupToAdd);
++count;
e->addCommand(commands);
commands.clear();
executeStartHook(groupToAdd, e->option);
} catch(RecoverableException& 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);
_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()
{
for(RequestGroups::iterator itr = _requestGroups.begin();

View File

@ -97,8 +97,6 @@ public:
void forceHalt();
void getInitialCommands(std::deque<Command*>& commands, DownloadEngine* e);
void removeStoppedGroup(DownloadEngine* e);
void fillRequestGroupFromReserver(DownloadEngine* e);

View File

@ -54,11 +54,11 @@ void RequestGroupManTest::testIsSameFileBeingDownloaded()
rg1->setDownloadContext(dctx1);
rg2->setDownloadContext(dctx2);
RequestGroups rgs;
rgs.push_back(rg1);
rgs.push_back(rg2);
RequestGroupMan gm(std::deque<SharedHandle<RequestGroup> >(), 1,
_option.get());
RequestGroupMan gm(rgs, 1, _option.get());
gm.addRequestGroup(rg1);
gm.addRequestGroup(rg2);
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));