diff --git a/ChangeLog b/ChangeLog index c52fafe9..0ed53a4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2009-01-24 Tatsuhiro Tsujikawa + + Replaced FileAllocationMan with + SequentialPicker. + * src/BtCheckIntegrityEntry.cc + * src/ConsoleStatCalc.cc + * src/DownloadEngine.cc + * src/DownloadEngine.h + * src/DownloadEngineFactory.cc + * src/FileAllocationCommand.cc + * src/FileAllocationDispatcherCommand.cc + * src/FileAllocationMan.h + * src/Makefile.am + * src/SequentialPicker.h + * src/StatCalc.h + * src/StreamCheckIntegrityEntry.cc + * test/Makefile.am + * test/SequentialPickerTest.cc + 2009-01-19 Tatsuhiro Tsujikawa Added doc for adaptive URI selector. diff --git a/src/BtCheckIntegrityEntry.cc b/src/BtCheckIntegrityEntry.cc index 203cf315..feeb924e 100644 --- a/src/BtCheckIntegrityEntry.cc +++ b/src/BtCheckIntegrityEntry.cc @@ -54,7 +54,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque& commands, { FileAllocationEntryHandle entry(new BtFileAllocationEntry(_requestGroup)); if(_requestGroup->needsFileAllocation()) { - e->_fileAllocationMan->pushFileAllocationEntry(entry); + e->_fileAllocationMan->pushEntry(entry); } else { entry->prepareForNextAction(commands, e); } diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index 8b8f9d56..d40bed8e 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -162,9 +162,10 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval): {} void -ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan, - const FileAllocationManHandle& fileAllocationMan, - const CheckIntegrityManHandle& checkIntegrityMan) +ConsoleStatCalc::calculateStat +(const RequestGroupManHandle& requestGroupMan, + const SharedHandle& fileAllocationMan, + const CheckIntegrityManHandle& checkIntegrityMan) { if(!_cp.elapsed(1)) { return; @@ -211,7 +212,7 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan, } { - FileAllocationEntryHandle entry = fileAllocationMan->getCurrentFileAllocationEntry(); + SharedHandle entry=fileAllocationMan->getPickedEntry(); if(!entry.isNull()) { o << " " << "[FileAlloc:" @@ -229,9 +230,9 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan, } o << "%)" << "]"; - if(fileAllocationMan->countFileAllocationEntryInQueue() > 0) { + if(fileAllocationMan->hasNext()) { o << "(" - << fileAllocationMan->countFileAllocationEntryInQueue() + << fileAllocationMan->countEntryInQueue() << "waiting...)"; } } diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 1cb4c0f5..3da08503 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -44,7 +44,6 @@ #include "StatCalc.h" #include "RequestGroup.h" #include "RequestGroupMan.h" -#include "FileAllocationMan.h" #include "CheckIntegrityMan.h" #include "DownloadResult.h" #include "StatCalc.h" @@ -65,6 +64,7 @@ #include "Request.h" #include "EventPoll.h" #include "Command.h" +#include "FileAllocationEntry.h" #include "BtRegistry.h" #include "BtContext.h" diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index e8ca3452..f6d79a8c 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -49,13 +49,13 @@ # include "AsyncNameResolver.h" #endif // ENABLE_ASYNC_DNS #include "CUIDCounter.h" +#include "FileAllocationMan.h" namespace aria2 { class Logger; class Option; class RequestGroupMan; -class FileAllocationMan; class StatCalc; class CheckIntegrityMan; class SocketCore; diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index 13f9ea1d..a8b826a9 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -60,6 +60,7 @@ #endif // HAVE_EPOLL #include "SelectEventPoll.h" #include "DlAbortEx.h" +#include "FileAllocationEntry.h" namespace aria2 { diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc index 2fc94481..5f39c52c 100644 --- a/src/FileAllocationCommand.cc +++ b/src/FileAllocationCommand.cc @@ -60,7 +60,7 @@ bool FileAllocationCommand::executeInternal() logger->debug(MSG_ALLOCATION_COMPLETED, _timer.difference(), Util::itos(_requestGroup->getTotalLength(), true).c_str()); - _e->_fileAllocationMan->markCurrentFileAllocationEntryDone(); + _e->_fileAllocationMan->dropPickedEntry(); std::deque commands; _fileAllocationEntry->prepareForNextAction(commands, _e); @@ -75,7 +75,7 @@ bool FileAllocationCommand::executeInternal() bool FileAllocationCommand::handleException(Exception& e) { - _e->_fileAllocationMan->markCurrentFileAllocationEntryDone(); + _e->_fileAllocationMan->dropPickedEntry(); logger->error(MSG_FILE_ALLOCATION_FAILURE, e, cuid); logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid, _requestGroup->getFilePath().c_str()); return true; diff --git a/src/FileAllocationDispatcherCommand.cc b/src/FileAllocationDispatcherCommand.cc index 72622dfe..b6ee18fa 100644 --- a/src/FileAllocationDispatcherCommand.cc +++ b/src/FileAllocationDispatcherCommand.cc @@ -56,9 +56,8 @@ bool FileAllocationDispatcherCommand::execute() if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) { return true; } - if(_e->_fileAllocationMan->nextFileAllocationEntryExists() && - !_e->_fileAllocationMan->isFileAllocationBeingExecuted()) { - FileAllocationEntryHandle entry = _e->_fileAllocationMan->popNextFileAllocationEntry(); + if(_e->_fileAllocationMan->hasNext() && !_e->_fileAllocationMan->isPicked()) { + FileAllocationEntryHandle entry = _e->_fileAllocationMan->pickNext(); int32_t newCUID = _e->newCUID(); logger->info(MSG_FILE_ALLOCATION_DISPATCH, newCUID); FileAllocationCommand* command = diff --git a/src/FileAllocationMan.h b/src/FileAllocationMan.h index a13b7693..5244d581 100644 --- a/src/FileAllocationMan.h +++ b/src/FileAllocationMan.h @@ -36,38 +36,13 @@ #define _D_FILE_ALLOCATION_MAN_H_ #include "common.h" -#include "SharedHandle.h" -#include +#include "SequentialPicker.h" namespace aria2 { class FileAllocationEntry; -class FileAllocationMan { -private: - std::deque > _fileAllocationEntries; - SharedHandle _currentFileAllocationEntry; -public: - FileAllocationMan(); - - ~FileAllocationMan(); - - bool isFileAllocationBeingExecuted() const; - - SharedHandle getCurrentFileAllocationEntry(); - - void markCurrentFileAllocationEntryDone(); - - bool nextFileAllocationEntryExists() const; - - SharedHandle popNextFileAllocationEntry(); - - void pushFileAllocationEntry(const SharedHandle& entry); - - size_t countFileAllocationEntryInQueue() const; -}; - -typedef SharedHandle FileAllocationManHandle; +typedef SequentialPicker FileAllocationMan; } // namespace aria2 diff --git a/src/Makefile.am b/src/Makefile.am index 8bc1a448..ea2abc18 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -84,7 +84,7 @@ SRCS = Socket.h\ RequestGroup.cc RequestGroup.h\ RequestGroupAware.cc RequestGroupAware.h\ RequestGroupMan.cc RequestGroupMan.h\ - FileAllocationMan.cc FileAllocationMan.h\ + FileAllocationMan.h\ FileAllocationCommand.cc FileAllocationCommand.h\ FillRequestGroupCommand.cc FillRequestGroupCommand.h\ FileAllocationDispatcherCommand.cc FileAllocationDispatcherCommand.h\ @@ -198,7 +198,8 @@ SRCS = Socket.h\ bencode.cc bencode.h\ URIResult.cc URIResult.h\ EventPoll.h\ - SelectEventPoll.cc SelectEventPoll.h + SelectEventPoll.cc SelectEventPoll.h\ + SequentialPicker.h if HAVE_EPOLL SRCS += EpollEventPoll.cc EpollEventPoll.h diff --git a/src/Makefile.in b/src/Makefile.in index e8a0948f..6050c4ad 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -341,10 +341,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ NameMatchOptionHandler.h NameResolver.cc NameResolver.h \ RequestGroup.cc RequestGroup.h RequestGroupAware.cc \ RequestGroupAware.h RequestGroupMan.cc RequestGroupMan.h \ - FileAllocationMan.cc FileAllocationMan.h \ - FileAllocationCommand.cc FileAllocationCommand.h \ - FillRequestGroupCommand.cc FillRequestGroupCommand.h \ - FileAllocationDispatcherCommand.cc \ + FileAllocationMan.h FileAllocationCommand.cc \ + FileAllocationCommand.h FillRequestGroupCommand.cc \ + FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \ FileAllocationDispatcherCommand.h FileAllocationEntry.cc \ FileAllocationEntry.h StreamFileAllocationEntry.cc \ StreamFileAllocationEntry.h MultiUrlRequestInfo.cc \ @@ -414,8 +413,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ SocketBuffer.h OptionHandlerException.cc \ OptionHandlerException.h bencode.cc bencode.h URIResult.cc \ URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \ - EpollEventPoll.cc EpollEventPoll.h TLSContext.h \ - LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \ + SequentialPicker.h EpollEventPoll.cc EpollEventPoll.h \ + TLSContext.h LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \ LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \ GZipDecoder.h Sqlite3MozCookieParser.cc \ Sqlite3MozCookieParser.h AsyncNameResolver.cc \ @@ -764,7 +763,7 @@ am__objects_22 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \ OptionHandlerFactory.$(OBJEXT) OptionHandler.$(OBJEXT) \ NameResolver.$(OBJEXT) RequestGroup.$(OBJEXT) \ RequestGroupAware.$(OBJEXT) RequestGroupMan.$(OBJEXT) \ - FileAllocationMan.$(OBJEXT) FileAllocationCommand.$(OBJEXT) \ + FileAllocationCommand.$(OBJEXT) \ FillRequestGroupCommand.$(OBJEXT) \ FileAllocationDispatcherCommand.$(OBJEXT) \ FileAllocationEntry.$(OBJEXT) \ @@ -1068,10 +1067,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \ NameMatchOptionHandler.h NameResolver.cc NameResolver.h \ RequestGroup.cc RequestGroup.h RequestGroupAware.cc \ RequestGroupAware.h RequestGroupMan.cc RequestGroupMan.h \ - FileAllocationMan.cc FileAllocationMan.h \ - FileAllocationCommand.cc FileAllocationCommand.h \ - FillRequestGroupCommand.cc FillRequestGroupCommand.h \ - FileAllocationDispatcherCommand.cc \ + FileAllocationMan.h FileAllocationCommand.cc \ + FileAllocationCommand.h FillRequestGroupCommand.cc \ + FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \ FileAllocationDispatcherCommand.h FileAllocationEntry.cc \ FileAllocationEntry.h StreamFileAllocationEntry.cc \ StreamFileAllocationEntry.h MultiUrlRequestInfo.cc \ @@ -1141,13 +1139,14 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \ SocketBuffer.h OptionHandlerException.cc \ OptionHandlerException.h bencode.cc bencode.h URIResult.cc \ URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \ - $(am__append_1) $(am__append_2) $(am__append_3) \ - $(am__append_4) $(am__append_5) $(am__append_6) \ - $(am__append_7) $(am__append_8) $(am__append_9) \ - $(am__append_10) $(am__append_11) $(am__append_12) \ - $(am__append_13) $(am__append_14) $(am__append_15) \ - $(am__append_16) $(am__append_17) $(am__append_18) \ - $(am__append_19) $(am__append_20) $(am__append_21) + SequentialPicker.h $(am__append_1) $(am__append_2) \ + $(am__append_3) $(am__append_4) $(am__append_5) \ + $(am__append_6) $(am__append_7) $(am__append_8) \ + $(am__append_9) $(am__append_10) $(am__append_11) \ + $(am__append_12) $(am__append_13) $(am__append_14) \ + $(am__append_15) $(am__append_16) $(am__append_17) \ + $(am__append_18) $(am__append_19) $(am__append_20) \ + $(am__append_21) noinst_LIBRARIES = libaria2c.a libaria2c_a_SOURCES = $(SRCS) aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ @@ -1382,7 +1381,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationDispatcherCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationEntry.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationMan.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileEntry.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileMetalinkParserState.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FilesMetalinkParserState.Po@am__quote@ diff --git a/src/SequentialPicker.h b/src/SequentialPicker.h new file mode 100644 index 00000000..9d2f45dc --- /dev/null +++ b/src/SequentialPicker.h @@ -0,0 +1,96 @@ +/* */ +#ifndef _D_SEQUENTIAL_PICKER_H_ +#define _D_SEQUENTIAL_PICKER_H_ + +#include "common.h" + +#include + +#include "SharedHandle.h" + +namespace aria2 { + +template +class SequentialPicker { +private: + std::deque > _entries; + SharedHandle _pickedEntry; +public: + bool isPicked() const + { + return !_pickedEntry.isNull(); + } + + SharedHandle getPickedEntry() const + { + return _pickedEntry; + } + + void dropPickedEntry() + { + _pickedEntry.reset(); + } + + bool hasNext() const + { + return !_entries.empty(); + } + + SharedHandle pickNext() + { + SharedHandle r; + if(hasNext()) { + r = _entries.front(); + _entries.pop_front(); + _pickedEntry = r; + } + return r; + } + + void pushEntry(const SharedHandle& entry) + { + _entries.push_back(entry); + } + + size_t countEntryInQueue() const + { + return _entries.size(); + } +}; + +} // namespace aria2 + +#endif // _D_SEQUENTIAL_PICKER_H_ diff --git a/src/StatCalc.h b/src/StatCalc.h index bfe00561..405a9bb7 100644 --- a/src/StatCalc.h +++ b/src/StatCalc.h @@ -37,11 +37,11 @@ #include "common.h" #include "SharedHandle.h" +#include "FileAllocationMan.h" namespace aria2 { class RequestGroupMan; -class FileAllocationMan; class CheckIntegrityMan; class StatCalc { diff --git a/src/StreamCheckIntegrityEntry.cc b/src/StreamCheckIntegrityEntry.cc index 22904c6b..e8685422 100644 --- a/src/StreamCheckIntegrityEntry.cc +++ b/src/StreamCheckIntegrityEntry.cc @@ -57,7 +57,7 @@ void StreamCheckIntegrityEntry::onDownloadIncomplete(std::deque& comma (new StreamFileAllocationEntry(_currentRequest, _requestGroup, popNextCommand())); if(_requestGroup->needsFileAllocation()) { - e->_fileAllocationMan->pushFileAllocationEntry(entry); + e->_fileAllocationMan->pushEntry(entry); } else { entry->prepareForNextAction(commands, e); } diff --git a/test/Makefile.am b/test/Makefile.am index d2051c9a..5d60cc46 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -64,7 +64,8 @@ aria2c_SOURCES = AllTest.cc\ OptionParserTest.cc\ SimpleDNSCacheTest.cc\ DownloadHelperTest.cc\ - BencodeTest.cc + BencodeTest.cc\ + SequentialPickerTest.cc if HAVE_LIBZ aria2c_SOURCES += GZipDecoderTest.cc diff --git a/test/Makefile.in b/test/Makefile.in index 3f38f392..5ba37c94 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -192,8 +192,9 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \ DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \ TimeTest.cc CopyDiskAdaptorTest.cc FtpConnectionTest.cc \ OptionParserTest.cc SimpleDNSCacheTest.cc \ - DownloadHelperTest.cc BencodeTest.cc GZipDecoderTest.cc \ - Sqlite3MozCookieParserTest.cc MessageDigestHelperTest.cc \ + DownloadHelperTest.cc BencodeTest.cc SequentialPickerTest.cc \ + GZipDecoderTest.cc Sqlite3MozCookieParserTest.cc \ + MessageDigestHelperTest.cc \ IteratableChunkChecksumValidatorTest.cc \ IteratableChecksumValidatorTest.cc BtAllowedFastMessageTest.cc \ BtBitfieldMessageTest.cc BtCancelMessageTest.cc \ @@ -360,8 +361,9 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \ TimeTest.$(OBJEXT) CopyDiskAdaptorTest.$(OBJEXT) \ FtpConnectionTest.$(OBJEXT) OptionParserTest.$(OBJEXT) \ SimpleDNSCacheTest.$(OBJEXT) DownloadHelperTest.$(OBJEXT) \ - BencodeTest.$(OBJEXT) $(am__objects_1) $(am__objects_2) \ - $(am__objects_3) $(am__objects_4) $(am__objects_5) + BencodeTest.$(OBJEXT) SequentialPickerTest.$(OBJEXT) \ + $(am__objects_1) $(am__objects_2) $(am__objects_3) \ + $(am__objects_4) $(am__objects_5) aria2c_OBJECTS = $(am_aria2c_OBJECTS) am__DEPENDENCIES_1 = aria2c_DEPENDENCIES = ../src/libaria2c.a ../src/download_helper.o \ @@ -584,9 +586,9 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \ DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \ TimeTest.cc CopyDiskAdaptorTest.cc FtpConnectionTest.cc \ OptionParserTest.cc SimpleDNSCacheTest.cc \ - DownloadHelperTest.cc BencodeTest.cc $(am__append_1) \ - $(am__append_2) $(am__append_3) $(am__append_4) \ - $(am__append_5) + DownloadHelperTest.cc BencodeTest.cc SequentialPickerTest.cc \ + $(am__append_1) $(am__append_2) $(am__append_3) \ + $(am__append_4) $(am__append_5) #aria2c_CXXFLAGS = ${CPPUNIT_CFLAGS} -I../src -I../lib -Wall -D_FILE_OFFSET_BITS=64 #aria2c_LDFLAGS = ${CPPUNIT_LIBS} @@ -796,6 +798,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SegmentManTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SegmentTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SequenceTest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SequentialPickerTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatManTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatURISelectorTest.Po@am__quote@ diff --git a/test/SequentialPickerTest.cc b/test/SequentialPickerTest.cc new file mode 100644 index 00000000..171e201a --- /dev/null +++ b/test/SequentialPickerTest.cc @@ -0,0 +1,51 @@ +#include "SequentialPicker.h" + +#include + +namespace aria2 { + +typedef SharedHandle Integer; + +class SequentialPickerTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(SequentialPickerTest); + CPPUNIT_TEST(testPick); + CPPUNIT_TEST_SUITE_END(); +public: + void testPick(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION(SequentialPickerTest); + +void SequentialPickerTest::testPick() +{ + SequentialPicker picker; + + CPPUNIT_ASSERT(!picker.isPicked()); + CPPUNIT_ASSERT(!picker.hasNext()); + CPPUNIT_ASSERT_EQUAL((size_t)0, picker.countEntryInQueue()); + + picker.pushEntry(Integer(new int(1))); + picker.pushEntry(Integer(new int(2))); + + CPPUNIT_ASSERT(picker.hasNext()); + CPPUNIT_ASSERT_EQUAL((size_t)2, picker.countEntryInQueue()); + + picker.pickNext(); + + CPPUNIT_ASSERT(picker.isPicked()); + CPPUNIT_ASSERT_EQUAL(Integer(new int(1)), picker.getPickedEntry()); + + picker.dropPickedEntry(); + + CPPUNIT_ASSERT(!picker.isPicked()); + CPPUNIT_ASSERT(picker.hasNext()); + + picker.pickNext(); + + CPPUNIT_ASSERT_EQUAL(Integer(new int(2)), picker.getPickedEntry()); + CPPUNIT_ASSERT(!picker.hasNext()); +} + +} // namespace aria2