From 7e7aeac3ff12ecac15995c83cf51e66338d64447 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 27 Sep 2011 21:48:41 +0900 Subject: [PATCH] Added --piece-length option. This option sets a piece length for HTTP/FTP downloads. This is the boundary when aria2 splits a file. All splits occur at multiple of this length. This option will be ignored in BitTorrent downloads. It will be also ignored if Metalink file contains piece hashes. --- doc/aria2c.1.asciidoc | 16 ++++++++++++++++ src/Metalink2RequestGroup.cc | 6 +++--- src/OptionHandlerFactory.cc | 21 ++++++++++++--------- src/TrackerWatcherCommand.cc | 2 +- src/download_helper.cc | 5 +++-- src/prefs.cc | 2 +- src/prefs.h | 2 +- src/usage_text.h | 7 +++++++ test/RpcMethodTest.cc | 2 +- 9 files changed, 45 insertions(+), 18 deletions(-) diff --git a/doc/aria2c.1.asciidoc b/doc/aria2c.1.asciidoc index dca413e2..fa23fff4 100644 --- a/doc/aria2c.1.asciidoc +++ b/doc/aria2c.1.asciidoc @@ -1052,6 +1052,21 @@ name. See *<<_event_hook, Event Hook>>* for more details about COMMAND. Possible Values: '/path/to/command' +[[aria2_optref_piece_length]]*--piece-length*=LENGTH:: + + Set a piece length for HTTP/FTP downloads. This is the boundary when + aria2 splits a file. All splits occur at multiple of this + length. This option will be ignored in BitTorrent downloads. It + will be also ignored if Metalink file contains piece hashes. + Default: '1M' + +[NOTE] + +The possible usecase of *<>* +option is change the request range in one HTTP pipelined request. +To enable HTTP pipelining use +*<>*. + [[aria2_optref_show_console_readout]]*--show-console-readout*[='true'|'false']:: Show console readout. Default: 'true' @@ -1597,6 +1612,7 @@ of URIs. These optional lines must start with white space(s). * *<>* * *<>* * *<>* +* *<>* These options have exactly same meaning of the ones in the command-line options, but it just applies to the URIs it belongs to. diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 07291dda..21f1f289 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -243,12 +243,12 @@ Metalink2RequestGroup::createRequestGroup size_t pieceLength; #ifdef ENABLE_MESSAGE_DIGEST if(!entry->chunkChecksum) { - pieceLength = option->getAsInt(PREF_SEGMENT_SIZE); + pieceLength = option->getAsInt(PREF_PIECE_LENGTH); } else { pieceLength = entry->chunkChecksum->getPieceLength(); } #else - pieceLength = option->getAsInt(PREF_SEGMENT_SIZE); + pieceLength = option->getAsInt(PREF_PIECE_LENGTH); #endif // ENABLE_MESSAGE_DIGEST dctx.reset(new DownloadContext (pieceLength, @@ -281,7 +281,7 @@ Metalink2RequestGroup::createRequestGroup } else { dctx.reset(new DownloadContext()); // piece length is overridden by the one in torrent file. - dctx->setPieceLength(option->getAsInt(PREF_SEGMENT_SIZE)); + dctx->setPieceLength(option->getAsInt(PREF_PIECE_LENGTH)); std::vector > fileEntries; off_t offset = 0; for(std::vector >::const_iterator i = diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 59636c52..596db314 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -762,6 +762,18 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_FILE); handlers.push_back(op); } + { + SharedHandle op(new UnitNumberOptionHandler + (PREF_PIECE_LENGTH, + TEXT_PIECE_LENGTH, + "1M", + 1024*1024, + 1024*1024*1024)); + op->addTag(TAG_ADVANCED); + op->addTag(TAG_FTP); + op->addTag(TAG_HTTP); + handlers.push_back(op); + } { SharedHandle op(new BooleanOptionHandler (PREF_REMOTE_TIME, @@ -793,15 +805,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_HTTP); handlers.push_back(op); } - { - SharedHandle op(new UnitNumberOptionHandler - (PREF_SEGMENT_SIZE, - NO_DESCRIPTION, - "1M", - 1024, -1)); - op->hide(); - handlers.push_back(op); - } { SharedHandle op(new DefaultOptionHandler (PREF_SERVER_STAT_IF, diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index d486aa5a..fd4f3465 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -236,7 +236,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri) rg->getOption()->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE); static const std::string TRACKER_ANNOUNCE_FILE("[tracker.announce]"); SharedHandle dctx - (new DownloadContext(getOption()->getAsInt(PREF_SEGMENT_SIZE), + (new DownloadContext(getOption()->getAsInt(PREF_PIECE_LENGTH), 0, TRACKER_ANNOUNCE_FILE)); dctx->getFileEntries().front()->setUris(uris); diff --git a/src/download_helper.cc b/src/download_helper.cc index 1c523809..8201ac58 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -170,7 +170,8 @@ const std::set& listRequestOptions() PREF_PAUSE, PREF_STREAM_PIECE_SELECTOR, PREF_HASH_CHECK_ONLY, - PREF_CHECKSUM + PREF_CHECKSUM, + PREF_PIECE_LENGTH }; static std::set requestOptions (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS)); @@ -223,7 +224,7 @@ SharedHandle createRequestGroup SharedHandle rg(new RequestGroup(option)); SharedHandle dctx (new DownloadContext - (option->getAsInt(PREF_SEGMENT_SIZE), + (option->getAsInt(PREF_PIECE_LENGTH), 0, useOutOption&&!option->blank(PREF_OUT)? util::applyDir(option->get(PREF_DIR), option->get(PREF_OUT)):A2STR::NIL)); diff --git a/src/prefs.cc b/src/prefs.cc index 9a4ba8a6..4080ceea 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -76,7 +76,7 @@ const std::string PREF_REFERER("referer"); // value: 1*digit const std::string PREF_LOWEST_SPEED_LIMIT("lowest-speed-limit"); // value: 1*digit -const std::string PREF_SEGMENT_SIZE("segment-size"); +const std::string PREF_PIECE_LENGTH("piece-length"); // value: 1*digit const std::string PREF_MAX_OVERALL_DOWNLOAD_LIMIT("max-overall-download-limit"); // value: 1*digit diff --git a/src/prefs.h b/src/prefs.h index 802e4916..37de2a68 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -80,7 +80,7 @@ extern const std::string PREF_REFERER; // value: 1*digit extern const std::string PREF_LOWEST_SPEED_LIMIT; // value: 1*digit -extern const std::string PREF_SEGMENT_SIZE; +extern const std::string PREF_PIECE_LENGTH; // value: 1*digit extern const std::string PREF_MAX_DOWNLOAD_LIMIT; // value: 1*digit diff --git a/src/usage_text.h b/src/usage_text.h index 90e54865..6698130a 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -847,3 +847,10 @@ " sha-1=0192ba11326fe2298c8cb4de616f4d4140213838\n" \ " This option applies only to HTTP(S)/FTP\n" \ " downloads.") +#define TEXT_PIECE_LENGTH \ + _(" --piece-length=LENGTH Set a piece length for HTTP/FTP downloads. This\n" \ + " is the boundary when aria2 splits a file. All\n" \ + " splits occur at multiple of this length. This\n" \ + " option will be ignored in BitTorrent downloads.\n" \ + " It will be also ignored if Metalink file\n" \ + " contains piece hashes.") diff --git a/test/RpcMethodTest.cc b/test/RpcMethodTest.cc index 3aa8067a..eeab4cc2 100644 --- a/test/RpcMethodTest.cc +++ b/test/RpcMethodTest.cc @@ -86,7 +86,7 @@ public: RequestGroup::resetGIDCounter(); option_.reset(new Option()); option_->put(PREF_DIR, A2_TEST_OUT_DIR"/aria2_RpcMethodTest"); - option_->put(PREF_SEGMENT_SIZE, "1048576"); + option_->put(PREF_PIECE_LENGTH, "1048576"); File(option_->get(PREF_DIR)).mkdirs(); e_.reset (new DownloadEngine(SharedHandle(new SelectEventPoll())));