mirror of https://github.com/aria2/aria2
Show bitfield for unknown length download in aria2.tellStatus RPC method
Generally, bitfield is not available for download whose total length is unknown. We create bitfield when download is completed (usually connection EOF) so that we can use it to show additional info in RPC aria2.tellStatus response. Specifically, bitfield is now shown. And completedLength under files key (or completedLength in aria2.getFiles() response) is correctly shown.pull/260/head
parent
98681552fc
commit
a6b7bd0342
|
@ -43,6 +43,7 @@
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "Piece.h"
|
#include "Piece.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "BitfieldMan.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -182,6 +183,8 @@ void UnknownLengthPieceStorage::completePiece(const std::shared_ptr<Piece>& piec
|
||||||
totalLength_ = piece_->getLength();
|
totalLength_ = piece_->getLength();
|
||||||
diskAdaptor_->setTotalLength(totalLength_);
|
diskAdaptor_->setTotalLength(totalLength_);
|
||||||
piece_.reset();
|
piece_.reset();
|
||||||
|
|
||||||
|
createBitfield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,10 +222,17 @@ std::shared_ptr<DiskAdaptor> UnknownLengthPieceStorage::getDiskAdaptor()
|
||||||
|
|
||||||
int32_t UnknownLengthPieceStorage::getPieceLength(size_t index)
|
int32_t UnknownLengthPieceStorage::getPieceLength(size_t index)
|
||||||
{
|
{
|
||||||
if(index == 0) {
|
// TODO Basically, PieceStorage::getPieceLength() is only used by
|
||||||
return totalLength_;
|
// BitTorrent, and it does not use UnknownLengthPieceStorage.
|
||||||
} else {
|
abort();
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
void UnknownLengthPieceStorage::createBitfield()
|
||||||
|
{
|
||||||
|
if(totalLength_ > 0) {
|
||||||
|
bitfield_ = make_unique<BitfieldMan>(downloadContext_->getPieceLength(),
|
||||||
|
totalLength_);
|
||||||
|
bitfield_->setAllBit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +242,9 @@ void UnknownLengthPieceStorage::markAllPiecesDone()
|
||||||
totalLength_ = piece_->getLength();
|
totalLength_ = piece_->getLength();
|
||||||
piece_.reset();
|
piece_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createBitfield();
|
||||||
|
|
||||||
downloadFinished_ = true;
|
downloadFinished_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,4 +270,22 @@ void UnknownLengthPieceStorage::setDiskWriterFactory
|
||||||
diskWriterFactory_ = diskWriterFactory;
|
diskWriterFactory_ = diskWriterFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unsigned char* UnknownLengthPieceStorage::getBitfield()
|
||||||
|
{
|
||||||
|
if(bitfield_) {
|
||||||
|
return bitfield_->getBitfield();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t UnknownLengthPieceStorage::getBitfieldLength()
|
||||||
|
{
|
||||||
|
if(bitfield_) {
|
||||||
|
return bitfield_->getBitfieldLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Option;
|
||||||
class DownloadContext;
|
class DownloadContext;
|
||||||
class DiskWriterFactory;
|
class DiskWriterFactory;
|
||||||
class DirectDiskAdaptor;
|
class DirectDiskAdaptor;
|
||||||
|
class BitfieldMan;
|
||||||
|
|
||||||
class UnknownLengthPieceStorage:public PieceStorage {
|
class UnknownLengthPieceStorage:public PieceStorage {
|
||||||
private:
|
private:
|
||||||
|
@ -54,9 +55,14 @@ private:
|
||||||
|
|
||||||
int64_t totalLength_;
|
int64_t totalLength_;
|
||||||
|
|
||||||
|
std::unique_ptr<BitfieldMan> bitfield_;
|
||||||
|
|
||||||
bool downloadFinished_;
|
bool downloadFinished_;
|
||||||
|
|
||||||
std::shared_ptr<Piece> piece_;
|
std::shared_ptr<Piece> piece_;
|
||||||
|
|
||||||
|
void createBitfield();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnknownLengthPieceStorage(const std::shared_ptr<DownloadContext>& downloadContext);
|
UnknownLengthPieceStorage(const std::shared_ptr<DownloadContext>& downloadContext);
|
||||||
|
|
||||||
|
@ -203,18 +209,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void initStorage() CXX11_OVERRIDE;
|
virtual void initStorage() CXX11_OVERRIDE;
|
||||||
|
|
||||||
virtual const unsigned char* getBitfield() CXX11_OVERRIDE
|
virtual const unsigned char* getBitfield() CXX11_OVERRIDE;
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setBitfield(const unsigned char* bitfield,
|
virtual void setBitfield(const unsigned char* bitfield,
|
||||||
size_t bitfieldLength) CXX11_OVERRIDE {}
|
size_t bitfieldLength) CXX11_OVERRIDE {}
|
||||||
|
|
||||||
virtual size_t getBitfieldLength() CXX11_OVERRIDE
|
virtual size_t getBitfieldLength() CXX11_OVERRIDE;
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool isSelectiveDownloadingMode() CXX11_OVERRIDE
|
virtual bool isSelectiveDownloadingMode() CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue