Explorar o código

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.
Tatsuhiro Tsujikawa %!s(int64=14) %!d(string=hai) anos
pai
achega
7e7aeac3ff

+ 16 - 0
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 *<<aria2_optref_piece_length, --piece-length>>*
+option is change the request range in one HTTP pipelined request.
+To enable HTTP pipelining use
+*<<aria2_optref_enable_http_pipelining, --enable-http-pipelining>>*.
+
 [[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).
 * *<<aria2_optref_stream_piece_selector, stream-piece-selector>>*
 * *<<aria2_optref_hash_check_only, hash-check-only>>*
 * *<<aria2_optref_checksum, checksum>>*
+* *<<aria2_optref_piece_length, piece_length>>*
 
 These options have exactly same meaning of the ones in the
 command-line options, but it just applies to the URIs it belongs to.

+ 3 - 3
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<SharedHandle<FileEntry> > fileEntries;
       off_t offset = 0;
       for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =

+ 12 - 9
src/OptionHandlerFactory.cc

@@ -762,6 +762,18 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_FILE);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<UnitNumberOptionHandler> 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<OptionHandler> op(new BooleanOptionHandler
                                    (PREF_REMOTE_TIME,
@@ -793,15 +805,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_HTTP);
     handlers.push_back(op);
   }
-  {
-    SharedHandle<UnitNumberOptionHandler> op(new UnitNumberOptionHandler
-                                             (PREF_SEGMENT_SIZE,
-                                              NO_DESCRIPTION,
-                                              "1M",
-                                              1024, -1));
-    op->hide();
-    handlers.push_back(op);
-  }
   {
     SharedHandle<OptionHandler> op(new DefaultOptionHandler
                                    (PREF_SERVER_STAT_IF,

+ 1 - 1
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<DownloadContext> dctx
-    (new DownloadContext(getOption()->getAsInt(PREF_SEGMENT_SIZE),
+    (new DownloadContext(getOption()->getAsInt(PREF_PIECE_LENGTH),
                          0,
                          TRACKER_ANNOUNCE_FILE));
   dctx->getFileEntries().front()->setUris(uris);

+ 3 - 2
src/download_helper.cc

@@ -170,7 +170,8 @@ const std::set<std::string>& listRequestOptions()
     PREF_PAUSE,
     PREF_STREAM_PIECE_SELECTOR,
     PREF_HASH_CHECK_ONLY,
-    PREF_CHECKSUM
+    PREF_CHECKSUM,
+    PREF_PIECE_LENGTH
   };
   static std::set<std::string> requestOptions
     (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));
@@ -223,7 +224,7 @@ SharedHandle<RequestGroup> createRequestGroup
   SharedHandle<RequestGroup> rg(new RequestGroup(option));
   SharedHandle<DownloadContext> 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));

+ 1 - 1
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

+ 1 - 1
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

+ 7 - 0
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.")

+ 1 - 1
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<EventPoll>(new SelectEventPoll())));