2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added --bt-max-open-files option.
	* src/DefaultPieceStorage.cc
	* src/HelpItemFactory.cc
	* src/MultiDiskAdaptor.cc
	* src/MultiDiskAdaptor.h
	* src/OptionHandlerFactory.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
pull/1/head
Tatsuhiro Tsujikawa 2008-06-08 12:34:36 +00:00
parent b4e5ba2779
commit cf71523fe2
10 changed files with 46 additions and 3 deletions

View File

@ -1,3 +1,16 @@
2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added --bt-max-open-files option.
* src/DefaultPieceStorage.cc
* src/HelpItemFactory.cc
* src/MultiDiskAdaptor.cc
* src/MultiDiskAdaptor.h
* src/OptionHandlerFactory.cc
* src/option_processing.cc
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that aria2 aborts when a path to a directory is given

View File

@ -444,6 +444,7 @@ void DefaultPieceStorage::initStorage()
multiDiskAdaptor->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
multiDiskAdaptor->setPieceLength(downloadContext->getPieceLength());
multiDiskAdaptor->setTopDir(downloadContext->getName());
multiDiskAdaptor->setMaxOpenFiles(option->getAsInt(PREF_BT_MAX_OPEN_FILES));
this->diskAdaptor = multiDiskAdaptor;
} else {
logger->debug("Instantiating CopyDiskAdaptor");

View File

@ -381,6 +381,13 @@ TagContainerHandle HelpItemFactory::createHelpItems(const Option* op)
item->addTag(TAG_BITTORRENT);
tc->addItem(item);
}
{
HelpItemHandle item(new HelpItem(PREF_BT_MAX_OPEN_FILES,
TEXT_BT_MAX_OPEN_FILES,
op->get(PREF_BT_MAX_OPEN_FILES)));
item->addTag(TAG_BITTORRENT);
tc->addItem(item);
}
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
{

View File

@ -145,7 +145,7 @@ void DiskWriterEntry::disableDirectIO()
}
MultiDiskAdaptor::MultiDiskAdaptor():
pieceLength(0) {}
pieceLength(0), _maxOpenFiles(DEFAULT_MAX_OPEN_FILES) {}
MultiDiskAdaptor::~MultiDiskAdaptor() {}
@ -190,7 +190,7 @@ void MultiDiskAdaptor::openIfNot
size_t numOpened = _openedDiskWriterEntries.size();
(entry.get()->*open)(topDirPath);
if(numOpened >= OPEN_FILE_MAX) {
if(numOpened >= _maxOpenFiles) {
// Cache is full.
// Choose one DiskWriterEntry randomly and close it.
size_t index = SimpleRandomizer::getInstance()->getRandomNumber(numOpened);
@ -386,4 +386,9 @@ void MultiDiskAdaptor::disableDirectIO()
}
}
void MultiDiskAdaptor::setMaxOpenFiles(size_t maxOpenFiles)
{
_maxOpenFiles = maxOpenFiles;
}
} // namespace aria2

View File

@ -104,6 +104,8 @@ private:
std::deque<SharedHandle<DiskWriterEntry> > _openedDiskWriterEntries;
size_t _maxOpenFiles;
bool _directIOAllowed;
void resetDiskWriterEntries();
@ -116,7 +118,7 @@ private:
void (DiskWriterEntry::*f)(const std::string&),
const std::string& topDirPath);
static const size_t OPEN_FILE_MAX = 100;
static const size_t DEFAULT_MAX_OPEN_FILES = 100;
public:
MultiDiskAdaptor();
@ -178,6 +180,8 @@ public:
{
_directIOAllowed = b;
}
void setMaxOpenFiles(size_t maxOpenFiles);
};
typedef SharedHandle<MultiDiskAdaptor> MultiDiskAdaptorHandle;

View File

@ -127,6 +127,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
handlers.push_back(SH(new ParameterOptionHandler(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN, V_ARC4)));
handlers.push_back(SH(new BooleanOptionHandler(PREF_BT_REQUIRE_CRYPTO)));
handlers.push_back(SH(new NumberOptionHandler(PREF_BT_REQUEST_PEER_SPEED_LIMIT, 0)));
handlers.push_back(SH(new NumberOptionHandler(PREF_BT_MAX_OPEN_FILES, 1)));
handlers.push_back(SH(new CumulativeOptionHandler(PREF_HEADER, "\n")));
handlers.push_back(SH(new BooleanOptionHandler(PREF_QUIET)));
#ifdef ENABLE_ASYNC_DNS

View File

@ -144,6 +144,7 @@ Option* createDefaultOption()
op->put(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN);
op->put(PREF_BT_REQUIRE_CRYPTO, V_FALSE);
op->put(PREF_BT_REQUEST_PEER_SPEED_LIMIT, "51200");
op->put(PREF_BT_MAX_OPEN_FILES, "100");
op->put(PREF_QUIET, V_FALSE);
op->put(PREF_STOP, "0");
#ifdef ENABLE_ASYNC_DNS
@ -254,6 +255,7 @@ Option* option_processing(int argc, char* const argv[])
{ PREF_BT_MIN_CRYPTO_LEVEL.c_str(), required_argument, &lopt, 30 },
{ PREF_BT_REQUIRE_CRYPTO.c_str(), required_argument, &lopt, 31 },
{ PREF_BT_REQUEST_PEER_SPEED_LIMIT.c_str(), required_argument, &lopt, 32 },
{ PREF_BT_MAX_OPEN_FILES.c_str(), required_argument, &lopt, 33},
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
{ PREF_METALINK_FILE.c_str(), required_argument, NULL, 'M' },
@ -367,6 +369,9 @@ Option* option_processing(int argc, char* const argv[])
case 32:
cmdstream << PREF_BT_REQUEST_PEER_SPEED_LIMIT << "=" << optarg << "\n";
break;
case 33:
cmdstream << PREF_BT_MAX_OPEN_FILES << "=" << optarg << "\n";
break;
case 100:
cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
break;

View File

@ -249,6 +249,8 @@ const std::string V_ARC4("arc4");
const std::string PREF_BT_REQUIRE_CRYPTO("bt-require-crypto");
// values: 1*digit
const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT("bt-request-peer-speed-limit");
// values: 1*digit
const std::string PREF_BT_MAX_OPEN_FILES("bt-max-open-files");
/**
* Metalink related preferences

View File

@ -253,6 +253,8 @@ extern const std::string V_ARC4;
extern const std::string PREF_BT_REQUIRE_CRYPTO;
// values: 1*digit
extern const std::string PREF_BT_REQUEST_PEER_SPEED_LIMIT;
// values: 1*digit
extern const std::string PREF_BT_MAX_OPEN_FILES;
/**
* Metalink related preferences

View File

@ -279,6 +279,9 @@ _(" --bt-request-peer-speed-limit=SPEED In BitTorrent downloads, if the download
" speed is lower than SPEED, aria2 initiates and\n"\
" accepts connections ignoring max peer cap.\n"\
" You can append K or M(1K = 1024, 1M = 1024K).")
#define TEXT_BT_MAX_OPEN_FILES \
_(" --bt-max-open-files=NUM Specify maximum number of files to open in each\n"\
" BitTorrent download.")
#define TEXT_METALINK_FILE \
_(" -M, --metalink-file=METALINK_FILE The file path to the .metalink file.")
#define TEXT_METALINK_SERVERS \