summaryrefslogtreecommitdiff
path: root/src/BitfieldMan.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-06-11 21:32:33 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-06-11 21:41:56 +0900
commitdeaea9537b718a4527e7033ac4543b5af58a62f2 (patch)
treeda810714e4b00aa6e4ae547c5dc153a20c78d933 /src/BitfieldMan.cc
parent595a514b171441fb8706b19b3a46773e7c2bcf70 (diff)
Added --stream-piece-selector option.
This option specifies piece selection algorithm used in HTTP/FTP download. Piece means fixed length segment which is downloaded in parallel in segmented download. If 'default' is given, aria2 selects piece so that it reduces the number of establishing connection. This is reasonable default behaviour because establishing connection is an expensive operation. If 'inorder' is given, aria2 selects piece which has minimum index. Index=0 means first of the file. This will be useful to view movie while downloading it. --enable-http-pipelining option may be useful to reduce reconnection overhead. Please note that aria2 honors --min-split-size option, so it will be necessary to specify a reasonable value to --min-split-size option.
Diffstat (limited to 'src/BitfieldMan.cc')
-rw-r--r--src/BitfieldMan.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc
index 99b3cfb3..5535af14 100644
--- a/src/BitfieldMan.cc
+++ b/src/BitfieldMan.cc
@@ -311,6 +311,73 @@ bool BitfieldMan::getSparseMissingUnusedIndex
namespace {
template<typename Array>
+bool getInorderMissingUnusedIndex
+(size_t& index,
+ size_t minSplitSize,
+ const Array& bitfield,
+ const unsigned char* useBitfield,
+ size_t blockLength_,
+ size_t blocks)
+{
+ // We always return first piece if it is available.
+ if(!bitfield::test(bitfield, blocks, 0) &&
+ !bitfield::test(useBitfield, blocks, 0)) {
+ index = 0;
+ return true;
+ }
+ for(size_t i = 1; i < blocks;) {
+ if(!bitfield::test(bitfield, blocks, i) &&
+ !bitfield::test(useBitfield, blocks, i)) {
+ // If previous piece has already been retrieved, we can download
+ // from this index.
+ if(!bitfield::test(useBitfield, blocks, i-1) &&
+ bitfield::test(bitfield, blocks, i-1)) {
+ index = i;
+ return true;
+ }
+ // Check free space of minSplitSize.
+ size_t j;
+ for(j = i; j < blocks; ++j) {
+ if(bitfield::test(bitfield, blocks, j) ||
+ bitfield::test(useBitfield, blocks, j)) {
+ break;
+ }
+ if((j-i+1)*blockLength_ >= minSplitSize) {
+ index = j;
+ return true;
+ }
+ }
+ i = j+1;
+ } else {
+ ++i;
+ }
+ }
+ return false;
+}
+} // namespace
+
+bool BitfieldMan::getInorderMissingUnusedIndex
+(size_t& index,
+ size_t minSplitSize,
+ const unsigned char* ignoreBitfield,
+ size_t ignoreBitfieldLength) const
+{
+ if(filterEnabled_) {
+ return aria2::getInorderMissingUnusedIndex
+ (index, minSplitSize,
+ array(ignoreBitfield)|~array(filterBitfield_)|
+ array(bitfield_)|array(useBitfield_),
+ useBitfield_, blockLength_, blocks_);
+ } else {
+ return aria2::getInorderMissingUnusedIndex
+ (index, minSplitSize,
+ array(ignoreBitfield)|array(bitfield_)|array(useBitfield_),
+ useBitfield_, blockLength_, blocks_);
+ }
+}
+
+namespace {
+template<typename Array>
bool copyBitfield(unsigned char* dst, const Array& src, size_t blocks)
{
unsigned char bits = 0;