mirror of https://github.com/aria2/aria2
Added PieceStorage::onDownloadIncomplete() virtual function.
In DefaultPieceStorage::onDownloadIncomplete(), we call StreamPieceSelector::onBitfieldInit(). Added GeomStreamPieceSelectorTest.pull/2/head
parent
b94bf3355b
commit
c7ac147287
|
@ -51,11 +51,12 @@ BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
|
||||||
void BtCheckIntegrityEntry::onDownloadIncomplete
|
void BtCheckIntegrityEntry::onDownloadIncomplete
|
||||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
|
const SharedHandle<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
|
||||||
|
ps->onDownloadIncomplete();
|
||||||
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
|
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const SharedHandle<DiskAdaptor>& diskAdaptor =
|
const SharedHandle<DiskAdaptor>& diskAdaptor = ps->getDiskAdaptor();
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor();
|
|
||||||
if(diskAdaptor->isReadOnlyEnabled()) {
|
if(diskAdaptor->isReadOnlyEnabled()) {
|
||||||
// Now reopen DiskAdaptor with read only disabled.
|
// Now reopen DiskAdaptor with read only disabled.
|
||||||
diskAdaptor->closeFile();
|
diskAdaptor->closeFile();
|
||||||
|
|
|
@ -810,4 +810,9 @@ size_t DefaultPieceStorage::getNextUsedIndex(size_t index)
|
||||||
return bitfieldMan_->countBlock();
|
return bitfieldMan_->countBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefaultPieceStorage::onDownloadIncomplete()
|
||||||
|
{
|
||||||
|
streamPieceSelector_->onBitfieldInit();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -272,6 +272,8 @@ public:
|
||||||
|
|
||||||
virtual size_t getNextUsedIndex(size_t index);
|
virtual size_t getNextUsedIndex(size_t index);
|
||||||
|
|
||||||
|
virtual void onDownloadIncomplete();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is made private for test purpose only.
|
* This method is made private for test purpose only.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -54,4 +54,6 @@ bool DefaultStreamPieceSelector::select
|
||||||
(index, minSplitSize, ignoreBitfield, length);
|
(index, minSplitSize, ignoreBitfield, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DefaultStreamPieceSelector::onBitfieldInit() {}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
size_t minSplitSize,
|
size_t minSplitSize,
|
||||||
const unsigned char* ignoreBitfield,
|
const unsigned char* ignoreBitfield,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
|
virtual void onBitfieldInit();
|
||||||
private:
|
private:
|
||||||
BitfieldMan* bitfieldMan_;
|
BitfieldMan* bitfieldMan_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,8 @@ GeomStreamPieceSelector::GeomStreamPieceSelector
|
||||||
(BitfieldMan* bitfieldMan,
|
(BitfieldMan* bitfieldMan,
|
||||||
double base)
|
double base)
|
||||||
: bitfieldMan_(bitfieldMan),
|
: bitfieldMan_(bitfieldMan),
|
||||||
base_(base)
|
base_(base),
|
||||||
|
offsetIndex_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
GeomStreamPieceSelector::~GeomStreamPieceSelector() {}
|
GeomStreamPieceSelector::~GeomStreamPieceSelector() {}
|
||||||
|
@ -53,7 +54,16 @@ bool GeomStreamPieceSelector::select
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
return bitfieldMan_->getGeomMissingUnusedIndex
|
return bitfieldMan_->getGeomMissingUnusedIndex
|
||||||
(index, minSplitSize, ignoreBitfield, length, base_, 0);
|
(index, minSplitSize, ignoreBitfield, length, base_, offsetIndex_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeomStreamPieceSelector::onBitfieldInit()
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
bool r = bitfieldMan_->getFirstMissingIndex(index);
|
||||||
|
if(r) {
|
||||||
|
offsetIndex_ = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -51,9 +51,12 @@ public:
|
||||||
size_t minSplitSize,
|
size_t minSplitSize,
|
||||||
const unsigned char* ignoreBitfield,
|
const unsigned char* ignoreBitfield,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
|
virtual void onBitfieldInit();
|
||||||
private:
|
private:
|
||||||
BitfieldMan* bitfieldMan_;
|
BitfieldMan* bitfieldMan_;
|
||||||
double base_;
|
double base_;
|
||||||
|
size_t offsetIndex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -54,4 +54,6 @@ bool InorderStreamPieceSelector::select
|
||||||
(index, minSplitSize, ignoreBitfield, length);
|
(index, minSplitSize, ignoreBitfield, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InorderStreamPieceSelector::onBitfieldInit() {}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
size_t minSplitSize,
|
size_t minSplitSize,
|
||||||
const unsigned char* ignoreBitfield,
|
const unsigned char* ignoreBitfield,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
|
virtual void onBitfieldInit();
|
||||||
private:
|
private:
|
||||||
BitfieldMan* bitfieldMan_;
|
BitfieldMan* bitfieldMan_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -283,6 +283,9 @@ public:
|
||||||
// are not used and not completed. If all pieces after index+1 are
|
// are not used and not completed. If all pieces after index+1 are
|
||||||
// used or completed, returns the number of pieces.
|
// used or completed, returns the number of pieces.
|
||||||
virtual size_t getNextUsedIndex(size_t index) = 0;
|
virtual size_t getNextUsedIndex(size_t index) = 0;
|
||||||
|
|
||||||
|
// Called when system detects download is not finished
|
||||||
|
virtual void onDownloadIncomplete() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<PieceStorage> PieceStorageHandle;
|
typedef SharedHandle<PieceStorage> PieceStorageHandle;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "StreamFileAllocationEntry.h"
|
#include "StreamFileAllocationEntry.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
#include "PieceStorage.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -51,6 +52,8 @@ StreamCheckIntegrityEntry::~StreamCheckIntegrityEntry() {}
|
||||||
void StreamCheckIntegrityEntry::onDownloadIncomplete
|
void StreamCheckIntegrityEntry::onDownloadIncomplete
|
||||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
|
const SharedHandle<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
|
||||||
|
ps->onDownloadIncomplete();
|
||||||
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
|
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,10 @@ public:
|
||||||
size_t minSplitSize,
|
size_t minSplitSize,
|
||||||
const unsigned char* ignoreBitfield,
|
const unsigned char* ignoreBitfield,
|
||||||
size_t length) = 0;
|
size_t length) = 0;
|
||||||
|
|
||||||
|
// Called when initial bitfield was fixed. Optimize
|
||||||
|
// StreamPieceSelector to take advantages of the initial bitfield.
|
||||||
|
virtual void onBitfieldInit() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -292,6 +292,8 @@ public:
|
||||||
virtual size_t getNextUsedIndex(size_t index) { return 0; }
|
virtual size_t getNextUsedIndex(size_t index) { return 0; }
|
||||||
|
|
||||||
void setDiskWriterFactory(const SharedHandle<DiskWriterFactory>& diskWriterFactory);
|
void setDiskWriterFactory(const SharedHandle<DiskWriterFactory>& diskWriterFactory);
|
||||||
|
|
||||||
|
virtual void onDownloadIncomplete() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<UnknownLengthPieceStorage> UnknownLengthPieceStorageHandle;
|
typedef SharedHandle<UnknownLengthPieceStorage> UnknownLengthPieceStorageHandle;
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include "GeomStreamPieceSelector.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
#include "Exception.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "BitfieldMan.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class GeomStreamPieceSelectorTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE(GeomStreamPieceSelectorTest);
|
||||||
|
CPPUNIT_TEST(testOnBitfieldInit);
|
||||||
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
public:
|
||||||
|
void testOnBitfieldInit();
|
||||||
|
};
|
||||||
|
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION(GeomStreamPieceSelectorTest);
|
||||||
|
|
||||||
|
void GeomStreamPieceSelectorTest::testOnBitfieldInit()
|
||||||
|
{
|
||||||
|
BitfieldMan bf(1024, 1024*20);
|
||||||
|
bf.setBitRange(0, 10);
|
||||||
|
GeomStreamPieceSelector sel(&bf, 2);
|
||||||
|
sel.onBitfieldInit();
|
||||||
|
unsigned char igbf[3];
|
||||||
|
memset(igbf, 0, 3);
|
||||||
|
size_t index;
|
||||||
|
// 11111|11111|00000|00000
|
||||||
|
CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf)));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)11, index);
|
||||||
|
bf.setUseBit(11);
|
||||||
|
// 11111|11111|10000|00000
|
||||||
|
CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf)));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)12, index);
|
||||||
|
bf.setUseBit(12);
|
||||||
|
// 11111|11111|11000|00000
|
||||||
|
CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf)));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)13, index);
|
||||||
|
bf.setUseBit(13);
|
||||||
|
// 11111|11111|11100|00000
|
||||||
|
CPPUNIT_ASSERT(sel.select(index, 1024*20, igbf, sizeof(igbf)));
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)15, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
|
@ -80,7 +80,8 @@ aria2c_SOURCES = AllTest.cc\
|
||||||
JsonTest.cc\
|
JsonTest.cc\
|
||||||
RpcResponseTest.cc\
|
RpcResponseTest.cc\
|
||||||
RpcMethodTest.cc\
|
RpcMethodTest.cc\
|
||||||
BufferedFileTest.cc
|
BufferedFileTest.cc\
|
||||||
|
GeomStreamPieceSelectorTest.cc
|
||||||
|
|
||||||
if ENABLE_XML_RPC
|
if ENABLE_XML_RPC
|
||||||
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
|
aria2c_SOURCES += XmlRpcRequestParserControllerTest.cc\
|
||||||
|
|
|
@ -280,6 +280,8 @@ public:
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void onDownloadIncomplete() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue