summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-12-07 22:57:34 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-12-09 21:39:43 +0900
commit12988e5282ef52a2806cbaca9f4074698f35e399 (patch)
tree7a8d5a65a8e8478ba5855e84a1077baee1a2028d /src
parentf25e67b0178511b26d55642f215a095321a169a8 (diff)
Replaced uint64_t with off_t or int64_t.
Since off_t is int64_t with LFS, we cannot take advantage of extra capacity of uint64_t.
Diffstat (limited to 'src')
-rw-r--r--src/AbstractDiskWriter.cc10
-rw-r--r--src/AbstractDiskWriter.h10
-rw-r--r--src/AbstractSingleDiskAdaptor.cc6
-rw-r--r--src/AbstractSingleDiskAdaptor.h10
-rw-r--r--src/AdaptiveFileAllocationIterator.cc10
-rw-r--r--src/AdaptiveFileAllocationIterator.h6
-rw-r--r--src/BinaryStream.h4
-rw-r--r--src/BitfieldMan.cc45
-rw-r--r--src/BitfieldMan.h38
-rw-r--r--src/BtRuntime.h6
-rw-r--r--src/ByteArrayDiskWriter.cc14
-rw-r--r--src/ByteArrayDiskWriter.h8
-rw-r--r--src/CheckIntegrityEntry.cc2
-rw-r--r--src/CheckIntegrityEntry.h2
-rw-r--r--src/ChunkChecksum.cc4
-rw-r--r--src/ChunkChecksum.h2
-rw-r--r--src/ChunkedDecodingStreamFilter.cc9
-rw-r--r--src/ChunkedDecodingStreamFilter.h2
-rw-r--r--src/DefaultBtAnnounce.cc2
-rw-r--r--src/DefaultBtProgressInfoFile.cc2
-rw-r--r--src/DefaultDiskWriter.cc2
-rw-r--r--src/DefaultDiskWriter.h2
-rw-r--r--src/DefaultPeerStorage.cc4
-rw-r--r--src/DefaultPeerStorage.h4
-rw-r--r--src/DefaultPieceStorage.cc14
-rw-r--r--src/DefaultPieceStorage.h10
-rw-r--r--src/DiskAdaptor.h2
-rw-r--r--src/DiskWriter.h8
-rw-r--r--src/DownloadCommand.cc4
-rw-r--r--src/DownloadContext.cc8
-rw-r--r--src/DownloadContext.h4
-rw-r--r--src/DownloadResult.h6
-rw-r--r--src/FallocFileAllocationIterator.cc8
-rw-r--r--src/FallocFileAllocationIterator.h6
-rw-r--r--src/File.cc2
-rw-r--r--src/File.h2
-rw-r--r--src/FileAllocationEntry.cc2
-rw-r--r--src/FileAllocationEntry.h2
-rw-r--r--src/FileAllocationIterator.h2
-rw-r--r--src/FileEntry.cc2
-rw-r--r--src/FileEntry.h8
-rw-r--r--src/FtpConnection.cc7
-rw-r--r--src/FtpConnection.h2
-rw-r--r--src/FtpNegotiationCommand.cc4
-rw-r--r--src/FtpNegotiationCommand.h2
-rw-r--r--src/HttpHeader.cc27
-rw-r--r--src/HttpHeader.h4
-rw-r--r--src/HttpRequest.cc2
-rw-r--r--src/HttpRequest.h2
-rw-r--r--src/HttpRequestCommand.cc2
-rw-r--r--src/HttpResponse.cc6
-rw-r--r--src/HttpResponse.h4
-rw-r--r--src/HttpResponseCommand.cc4
-rw-r--r--src/HttpServer.cc7
-rw-r--r--src/HttpServer.h4
-rw-r--r--src/HttpServerCommand.cc3
-rw-r--r--src/HttpSkipResponseCommand.cc2
-rw-r--r--src/HttpSkipResponseCommand.h4
-rw-r--r--src/IteratableChecksumValidator.cc4
-rw-r--r--src/IteratableChecksumValidator.h2
-rw-r--r--src/IteratableChunkChecksumValidator.cc4
-rw-r--r--src/IteratableChunkChecksumValidator.h2
-rw-r--r--src/IteratableValidator.h2
-rw-r--r--src/LpdMessageReceiver.cc2
-rw-r--r--src/MetalinkEntry.cc2
-rw-r--r--src/MetalinkEntry.h2
-rw-r--r--src/MetalinkParserController.cc2
-rw-r--r--src/MetalinkParserController.h2
-rw-r--r--src/MetalinkParserStateMachine.cc2
-rw-r--r--src/MetalinkParserStateMachine.h2
-rw-r--r--src/MetalinkParserStateV3Impl.cc4
-rw-r--r--src/MetalinkParserStateV4Impl.cc4
-rw-r--r--src/MultiDiskAdaptor.cc38
-rw-r--r--src/MultiDiskAdaptor.h4
-rw-r--r--src/MultiFileAllocationIterator.cc2
-rw-r--r--src/MultiFileAllocationIterator.h2
-rw-r--r--src/Peer.cc10
-rw-r--r--src/Peer.h10
-rw-r--r--src/PeerSessionResource.cc10
-rw-r--r--src/PeerSessionResource.h10
-rw-r--r--src/PeerStat.h4
-rw-r--r--src/PieceStorage.h10
-rw-r--r--src/ProgressAwareEntry.h2
-rw-r--r--src/Range.cc4
-rw-r--r--src/Range.h8
-rw-r--r--src/RequestGroup.cc18
-rw-r--r--src/RequestGroup.h10
-rw-r--r--src/RequestGroupMan.cc2
-rw-r--r--src/RpcMethodImpl.cc8
-rw-r--r--src/SegmentMan.cc8
-rw-r--r--src/SegmentMan.h6
-rw-r--r--src/ShareRatioSeedCriteria.cc2
-rw-r--r--src/SingleFileAllocationIterator.cc6
-rw-r--r--src/SingleFileAllocationIterator.h9
-rw-r--r--src/SpeedCalc.cc4
-rw-r--r--src/SpeedCalc.h4
-rw-r--r--src/TransferStat.h18
-rw-r--r--src/UnknownLengthPieceStorage.cc2
-rw-r--r--src/UnknownLengthPieceStorage.h12
-rw-r--r--src/bittorrent_helper.cc4
-rw-r--r--src/message_digest_helper.cc8
-rw-r--r--src/message_digest_helper.h4
-rw-r--r--src/paramed_string.cc2
-rw-r--r--src/paramed_string.h12
-rw-r--r--src/util.cc36
-rw-r--r--src/util.h6
106 files changed, 350 insertions, 361 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc
index b50a9b8e..e209018a 100644
--- a/src/AbstractDiskWriter.cc
+++ b/src/AbstractDiskWriter.cc
@@ -62,7 +62,7 @@ AbstractDiskWriter::~AbstractDiskWriter()
closeFile();
}
-void AbstractDiskWriter::openFile(uint64_t totalLength)
+void AbstractDiskWriter::openFile(off_t totalLength)
{
try {
openExistingFile(totalLength);
@@ -83,7 +83,7 @@ void AbstractDiskWriter::closeFile()
}
}
-void AbstractDiskWriter::openExistingFile(uint64_t totalLength)
+void AbstractDiskWriter::openExistingFile(off_t totalLength)
{
int flags = O_BINARY;
if(readOnly_) {
@@ -197,7 +197,7 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offs
return ret;
}
-void AbstractDiskWriter::truncate(uint64_t length)
+void AbstractDiskWriter::truncate(off_t length)
{
if(fd_ == -1) {
throw DL_ABORT_EX("File not opened.");
@@ -223,7 +223,7 @@ void AbstractDiskWriter::truncate(uint64_t length)
#endif
}
-void AbstractDiskWriter::allocate(off_t offset, uint64_t length)
+void AbstractDiskWriter::allocate(off_t offset, off_t length)
{
#ifdef HAVE_SOME_FALLOCATE
if(fd_ == -1) {
@@ -272,7 +272,7 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length)
#endif // HAVE_SOME_FALLOCATE
}
-uint64_t AbstractDiskWriter::size()
+off_t AbstractDiskWriter::size()
{
return File(filename_).size();
}
diff --git a/src/AbstractDiskWriter.h b/src/AbstractDiskWriter.h
index 297c3b26..9176dfef 100644
--- a/src/AbstractDiskWriter.h
+++ b/src/AbstractDiskWriter.h
@@ -57,22 +57,22 @@ public:
AbstractDiskWriter(const std::string& filename);
virtual ~AbstractDiskWriter();
- virtual void openFile(uint64_t totalLength = 0);
+ virtual void openFile(off_t totalLength = 0);
virtual void closeFile();
- virtual void openExistingFile(uint64_t totalLength = 0);
+ virtual void openExistingFile(off_t totalLength = 0);
virtual void writeData(const unsigned char* data, size_t len, off_t offset);
virtual ssize_t readData(unsigned char* data, size_t len, off_t offset);
- virtual void truncate(uint64_t length);
+ virtual void truncate(off_t length);
// File must be opened before calling this function.
- virtual void allocate(off_t offset, uint64_t length);
+ virtual void allocate(off_t offset, off_t length);
- virtual uint64_t size();
+ virtual off_t size();
virtual void enableReadOnly();
diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc
index ddf59059..95ef1606 100644
--- a/src/AbstractSingleDiskAdaptor.cc
+++ b/src/AbstractSingleDiskAdaptor.cc
@@ -85,12 +85,12 @@ bool AbstractSingleDiskAdaptor::fileExists()
return File(getFilePath()).exists();
}
-uint64_t AbstractSingleDiskAdaptor::size()
+off_t AbstractSingleDiskAdaptor::size()
{
return File(getFilePath()).size();
}
-void AbstractSingleDiskAdaptor::truncate(uint64_t length)
+void AbstractSingleDiskAdaptor::truncate(off_t length)
{
diskWriter_->truncate(length);
}
@@ -139,7 +139,7 @@ void AbstractSingleDiskAdaptor::setDiskWriter
diskWriter_ = diskWriter;
}
-void AbstractSingleDiskAdaptor::setTotalLength(const uint64_t& totalLength)
+void AbstractSingleDiskAdaptor::setTotalLength(const off_t& totalLength)
{
totalLength_ = totalLength;
}
diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h
index 47563d95..a5f78aa1 100644
--- a/src/AbstractSingleDiskAdaptor.h
+++ b/src/AbstractSingleDiskAdaptor.h
@@ -45,7 +45,7 @@ class FileAllocationIterator;
class AbstractSingleDiskAdaptor : public DiskAdaptor {
private:
SharedHandle<DiskWriter> diskWriter_;
- uint64_t totalLength_;
+ off_t totalLength_;
bool readOnly_;
public:
AbstractSingleDiskAdaptor();
@@ -67,9 +67,9 @@ public:
virtual bool fileExists();
- virtual uint64_t size();
+ virtual off_t size();
- virtual void truncate(uint64_t length);
+ virtual void truncate(off_t length);
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
@@ -92,9 +92,9 @@ public:
return diskWriter_;
}
- void setTotalLength(const uint64_t& totalLength);
+ void setTotalLength(const off_t& totalLength);
- uint64_t getTotalLength() const
+ off_t getTotalLength() const
{
return totalLength_;
}
diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc
index 8eeb5f99..a96c9f4a 100644
--- a/src/AdaptiveFileAllocationIterator.cc
+++ b/src/AdaptiveFileAllocationIterator.cc
@@ -45,7 +45,7 @@
namespace aria2 {
AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator
-(BinaryStream* stream, off_t offset, uint64_t totalLength)
+(BinaryStream* stream, off_t offset, off_t totalLength)
: stream_(stream),
offset_(offset),
totalLength_(totalLength)
@@ -59,8 +59,8 @@ void AdaptiveFileAllocationIterator::allocateChunk()
#ifdef HAVE_FALLOCATE
try {
A2_LOG_DEBUG("Testing file system supports fallocate.");
- if(static_cast<uint64_t>(offset_) < totalLength_) {
- off_t len = std::min(totalLength_-offset_, static_cast<uint64_t>(4096));
+ if(offset_ < totalLength_) {
+ off_t len = std::min(totalLength_-offset_, static_cast<off_t>(4096));
stream_->allocate(offset_, len);
offset_ += len;
}
@@ -89,7 +89,7 @@ void AdaptiveFileAllocationIterator::allocateChunk()
bool AdaptiveFileAllocationIterator::finished()
{
if(!allocator_) {
- return (uint64_t)offset_ == totalLength_;
+ return offset_ == totalLength_;
} else {
return allocator_->finished();
}
@@ -104,7 +104,7 @@ off_t AdaptiveFileAllocationIterator::getCurrentLength()
}
}
-uint64_t AdaptiveFileAllocationIterator::getTotalLength()
+off_t AdaptiveFileAllocationIterator::getTotalLength()
{
return totalLength_;
}
diff --git a/src/AdaptiveFileAllocationIterator.h b/src/AdaptiveFileAllocationIterator.h
index 8a3f2e3b..36217e6f 100644
--- a/src/AdaptiveFileAllocationIterator.h
+++ b/src/AdaptiveFileAllocationIterator.h
@@ -50,10 +50,10 @@ private:
off_t offset_;
- uint64_t totalLength_;
+ off_t totalLength_;
public:
AdaptiveFileAllocationIterator
- (BinaryStream* stream, off_t offset, uint64_t totalLength);
+ (BinaryStream* stream, off_t offset, off_t totalLength);
virtual ~AdaptiveFileAllocationIterator();
@@ -63,7 +63,7 @@ public:
virtual off_t getCurrentLength();
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
};
} // namespace aria2
diff --git a/src/BinaryStream.h b/src/BinaryStream.h
index 4dee179b..bb7853a5 100644
--- a/src/BinaryStream.h
+++ b/src/BinaryStream.h
@@ -53,11 +53,11 @@ public:
// Truncates a file to given length. The default implementation does
// nothing.
- virtual void truncate(uint64_t length) {}
+ virtual void truncate(off_t length) {}
// Allocates given length bytes of disk space from given offset. The
// default implementation does nothing.
- virtual void allocate(off_t offset, uint64_t length) {}
+ virtual void allocate(off_t offset, off_t length) {}
};
typedef SharedHandle<BinaryStream> BinaryStreamHandle;
diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc
index 2d50dab6..19a6d0c9 100644
--- a/src/BitfieldMan.cc
+++ b/src/BitfieldMan.cc
@@ -44,7 +44,7 @@ using namespace aria2::expr;
namespace aria2 {
-BitfieldMan::BitfieldMan(size_t blockLength, uint64_t totalLength)
+BitfieldMan::BitfieldMan(size_t blockLength, off_t totalLength)
:blockLength_(blockLength),
totalLength_(totalLength),
bitfieldLength_(0),
@@ -275,8 +275,8 @@ bool getSparseMissingUnusedIndex
} else {
if((!bitfield::test(useBitfield, blocks, maxRange.startIndex-1) &&
bitfield::test(bitfield, blocks, maxRange.startIndex-1)) ||
- ((uint64_t)(maxRange.endIndex-maxRange.startIndex)*blockLength_
- >= minSplitSize)) {
+ (static_cast<uint64_t>(maxRange.endIndex-maxRange.startIndex)*
+ blockLength_ >= minSplitSize)) {
index = maxRange.startIndex;
return true;
} else {
@@ -663,7 +663,7 @@ void BitfieldMan::ensureFilterBitfield()
}
}
-void BitfieldMan::addFilter(uint64_t offset, uint64_t length) {
+void BitfieldMan::addFilter(off_t offset, off_t length) {
ensureFilterBitfield();
if(length > 0) {
size_t startBlock = offset/blockLength_;
@@ -675,7 +675,7 @@ void BitfieldMan::addFilter(uint64_t offset, uint64_t length) {
updateCache();
}
-void BitfieldMan::removeFilter(uint64_t offset, uint64_t length) {
+void BitfieldMan::removeFilter(off_t offset, off_t length) {
ensureFilterBitfield();
if(length > 0) {
size_t startBlock = offset/blockLength_;
@@ -687,7 +687,7 @@ void BitfieldMan::removeFilter(uint64_t offset, uint64_t length) {
updateCache();
}
-void BitfieldMan::addNotFilter(uint64_t offset, uint64_t length)
+void BitfieldMan::addNotFilter(off_t offset, off_t length)
{
ensureFilterBitfield();
if(length > 0 && blocks_ > 0) {
@@ -726,7 +726,7 @@ void BitfieldMan::clearFilter() {
updateCache();
}
-uint64_t BitfieldMan::getFilteredTotalLengthNow() const {
+off_t BitfieldMan::getFilteredTotalLengthNow() const {
if(!filterBitfield_) {
return 0;
}
@@ -735,13 +735,13 @@ uint64_t BitfieldMan::getFilteredTotalLengthNow() const {
return 0;
}
if(bitfield::test(filterBitfield_, blocks_, blocks_-1)) {
- return ((uint64_t)filteredBlocks-1)*blockLength_+getLastBlockLength();
+ return ((off_t)filteredBlocks-1)*blockLength_+getLastBlockLength();
} else {
- return ((uint64_t)filteredBlocks)*blockLength_;
+ return ((off_t)filteredBlocks)*blockLength_;
}
}
-uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
+off_t BitfieldMan::getCompletedLength(bool useFilter) const {
unsigned char* temp;
if(useFilter) {
temp = new unsigned char[bitfieldLength_];
@@ -755,14 +755,15 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
temp = bitfield_;
}
size_t completedBlocks = bitfield::countSetBit(temp, blocks_);
- uint64_t completedLength = 0;
+ off_t completedLength = 0;
if(completedBlocks == 0) {
completedLength = 0;
} else {
if(bitfield::test(temp, blocks_, blocks_-1)) {
- completedLength = ((uint64_t)completedBlocks-1)*blockLength_+getLastBlockLength();
+ completedLength =
+ ((off_t)completedBlocks-1)*blockLength_+getLastBlockLength();
} else {
- completedLength = ((uint64_t)completedBlocks)*blockLength_;
+ completedLength = ((off_t)completedBlocks)*blockLength_;
}
}
if(useFilter) {
@@ -771,11 +772,11 @@ uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
return completedLength;
}
-uint64_t BitfieldMan::getCompletedLengthNow() const {
+off_t BitfieldMan::getCompletedLengthNow() const {
return getCompletedLength(false);
}
-uint64_t BitfieldMan::getFilteredCompletedLengthNow() const {
+off_t BitfieldMan::getFilteredCompletedLengthNow() const {
return getCompletedLength(true);
}
@@ -814,7 +815,7 @@ void BitfieldMan::setBitRange(size_t startIndex, size_t endIndex)
updateCache();
}
-bool BitfieldMan::isBitSetOffsetRange(uint64_t offset, uint64_t length) const
+bool BitfieldMan::isBitSetOffsetRange(off_t offset, off_t length) const
{
if(length <= 0) {
return false;
@@ -835,11 +836,11 @@ bool BitfieldMan::isBitSetOffsetRange(uint64_t offset, uint64_t length) const
return true;
}
-uint64_t BitfieldMan::getOffsetCompletedLength
-(uint64_t offset,
- uint64_t length) const
+off_t BitfieldMan::getOffsetCompletedLength
+(off_t offset,
+ off_t length) const
{
- uint64_t res = 0;
+ off_t res = 0;
if(length == 0 || totalLength_ <= offset) {
return 0;
}
@@ -868,12 +869,12 @@ uint64_t BitfieldMan::getOffsetCompletedLength
return res;
}
-uint64_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
+off_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
{
if(startingIndex < 0 || blocks_ <= startingIndex) {
return 0;
}
- uint64_t length = 0;
+ off_t length = 0;
for(size_t i = startingIndex; i < blocks_; ++i) {
if(isBitSet(i) || isUseBitSet(i)) {
break;
diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h
index d99235bf..b2ea7da4 100644
--- a/src/BitfieldMan.h
+++ b/src/BitfieldMan.h
@@ -46,7 +46,7 @@ namespace aria2 {
class BitfieldMan {
private:
size_t blockLength_;
- uint64_t totalLength_;
+ off_t totalLength_;
size_t bitfieldLength_;
size_t blocks_;
bool filterEnabled_;
@@ -57,9 +57,9 @@ private:
// for caching
size_t cachedNumMissingBlock_;
size_t cachedNumFilteredBlock_;
- uint64_t cachedCompletedLength_;
- uint64_t cachedFilteredCompletedLength_;
- uint64_t cachedFilteredTotalLength_;
+ off_t cachedCompletedLength_;
+ off_t cachedFilteredCompletedLength_;
+ off_t cachedFilteredTotalLength_;
bool setBitInternal(unsigned char* bitfield, size_t index, bool on);
bool setFilterBit(size_t index);
@@ -67,7 +67,7 @@ private:
size_t getStartIndex(size_t index) const;
size_t getEndIndex(size_t index) const;
- uint64_t getCompletedLength(bool useFilter) const;
+ off_t getCompletedLength(bool useFilter) const;
// If filterBitfield_ is 0, allocate bitfieldLength_ bytes to it and
// set 0 to all bytes.
@@ -84,7 +84,7 @@ public:
bool operator==(const Range& range) const;
};
public:
- BitfieldMan(size_t blockLength, uint64_t totalLength);
+ BitfieldMan(size_t blockLength, off_t totalLength);
BitfieldMan(const BitfieldMan& bitfieldMan);
~BitfieldMan();
@@ -99,7 +99,7 @@ public:
size_t getBlockLength(size_t index) const;
- uint64_t getTotalLength() const { return totalLength_; }
+ off_t getTotalLength() const { return totalLength_; }
// Returns true iff there is a bit index which is set in bitfield_,
// but not set in this object.
@@ -238,10 +238,10 @@ public:
void clearAllUseBit();
void setAllUseBit();
- void addFilter(uint64_t offset, uint64_t length);
- void removeFilter(uint64_t offset, uint64_t length);
+ void addFilter(off_t offset, off_t length);
+ void removeFilter(off_t offset, off_t length);
// Add filter not in the range of [offset, offset+length) bytes
- void addNotFilter(uint64_t offset, uint64_t length);
+ void addNotFilter(off_t offset, off_t length);
// Clears filter and disables filter
void clearFilter();
@@ -254,29 +254,29 @@ public:
}
// affected by filter
- uint64_t getFilteredTotalLength() const
+ off_t getFilteredTotalLength() const
{
return cachedFilteredTotalLength_;
}
// affected by filter
- uint64_t getFilteredTotalLengthNow() const;
+ off_t getFilteredTotalLengthNow() const;
- uint64_t getCompletedLength() const
+ off_t getCompletedLength() const
{
return cachedCompletedLength_;
}
- uint64_t getCompletedLengthNow() const;
+ off_t getCompletedLengthNow() const;
// affected by filter
- uint64_t getFilteredCompletedLength() const
+ off_t getFilteredCompletedLength() const
{
return cachedFilteredCompletedLength_;
}
// affected by filter
- uint64_t getFilteredCompletedLengthNow() const;
+ off_t getFilteredCompletedLengthNow() const;
void updateCache();
@@ -286,13 +286,13 @@ public:
void setBitRange(size_t startIndex, size_t endIndex);
- bool isBitSetOffsetRange(uint64_t offset, uint64_t length) const;
+ bool isBitSetOffsetRange(off_t offset, off_t length) const;
// Returns completed length in bytes in range [offset,
// offset+length). This function will not affected by filter.
- uint64_t getOffsetCompletedLength(uint64_t offset, uint64_t length) const;
+ off_t getOffsetCompletedLength(off_t offset, off_t length) const;
- uint64_t getMissingUnusedLength(size_t startingIndex) const;
+ off_t getMissingUnusedLength(size_t startingIndex) const;
const unsigned char* getFilterBitfield() const
{
diff --git a/src/BtRuntime.h b/src/BtRuntime.h
index 7ceeac65..90859f41 100644
--- a/src/BtRuntime.h
+++ b/src/BtRuntime.h
@@ -42,7 +42,7 @@ namespace aria2 {
class BtRuntime {
private:
- uint64_t uploadLengthAtStartup_;
+ off_t uploadLengthAtStartup_;
bool halt_;
unsigned int connections_;
bool ready_;
@@ -60,11 +60,11 @@ public:
~BtRuntime();
- uint64_t getUploadLengthAtStartup() const {
+ off_t getUploadLengthAtStartup() const {
return uploadLengthAtStartup_;
}
- void setUploadLengthAtStartup(uint64_t length) {
+ void setUploadLengthAtStartup(off_t length) {
uploadLengthAtStartup_ = length;
}
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index bb81dcd1..e83a573a 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -50,16 +50,16 @@ void ByteArrayDiskWriter::clear()
buf_.str(A2STR::NIL);
}
-void ByteArrayDiskWriter::initAndOpenFile(uint64_t totalLength)
+void ByteArrayDiskWriter::initAndOpenFile(off_t totalLength)
{
clear();
}
-void ByteArrayDiskWriter::openFile(uint64_t totalLength) {}
+void ByteArrayDiskWriter::openFile(off_t totalLength) {}
void ByteArrayDiskWriter::closeFile() {}
-void ByteArrayDiskWriter::openExistingFile(uint64_t totalLength)
+void ByteArrayDiskWriter::openExistingFile(off_t totalLength)
{
openFile();
}
@@ -70,10 +70,10 @@ void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength
throw DL_ABORT_EX(fmt("Maximum length(%lu) exceeded.",
static_cast<unsigned long>(maxLength_)));
}
- uint64_t length = size();
- if(length < (uint64_t)position) {
+ off_t length = size();
+ if(length < position) {
buf_.seekp(length, std::ios::beg);
- for(uint64_t i = length; i < (uint64_t)position; ++i) {
+ for(off_t i = length; i < position; ++i) {
buf_.put('\0');
}
} else {
@@ -90,7 +90,7 @@ ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t pos
return buf_.gcount();
}
-uint64_t ByteArrayDiskWriter::size()
+off_t ByteArrayDiskWriter::size()
{
buf_.seekg(0, std::ios::end);
buf_.clear();
diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h
index c51d8200..6899d63f 100644
--- a/src/ByteArrayDiskWriter.h
+++ b/src/ByteArrayDiskWriter.h
@@ -49,18 +49,18 @@ public:
ByteArrayDiskWriter(size_t maxLength = 5*1024*1024);
virtual ~ByteArrayDiskWriter();
- virtual void initAndOpenFile(uint64_t totalLength = 0);
+ virtual void initAndOpenFile(off_t totalLength = 0);
- virtual void openFile(uint64_t totalLength = 0);
+ virtual void openFile(off_t totalLength = 0);
virtual void closeFile();
- virtual void openExistingFile(uint64_t totalLength = 0);
+ virtual void openExistingFile(off_t totalLength = 0);
virtual void writeData(const unsigned char* data, size_t len, off_t position);
virtual ssize_t readData(unsigned char* data, size_t len, off_t position);
- virtual uint64_t size();
+ virtual off_t size();
void setString(const std::string& s);
diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc
index eda0b2ab..c635a540 100644
--- a/src/CheckIntegrityEntry.cc
+++ b/src/CheckIntegrityEntry.cc
@@ -56,7 +56,7 @@ void CheckIntegrityEntry::validateChunk()
validator_->validateChunk();
}
-uint64_t CheckIntegrityEntry::getTotalLength()
+off_t CheckIntegrityEntry::getTotalLength()
{
if(!validator_) {
return 0;
diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h
index a2fb7da7..5f5dcd58 100644
--- a/src/CheckIntegrityEntry.h
+++ b/src/CheckIntegrityEntry.h
@@ -61,7 +61,7 @@ public:
virtual ~CheckIntegrityEntry();
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
virtual off_t getCurrentLength();
diff --git a/src/ChunkChecksum.cc b/src/ChunkChecksum.cc
index 4d120afa..2a561819 100644
--- a/src/ChunkChecksum.cc
+++ b/src/ChunkChecksum.cc
@@ -56,9 +56,9 @@ bool ChunkChecksum::validateChunk
return !digest.empty() && actualDigest == digest;
}
-uint64_t ChunkChecksum::getEstimatedDataLength() const
+off_t ChunkChecksum::getEstimatedDataLength() const
{
- return static_cast<uint64_t>(pieceLength_)*pieceHashes_.size();
+ return static_cast<off_t>(pieceLength_)*pieceHashes_.size();
}
size_t ChunkChecksum::countPieceHash() const
diff --git a/src/ChunkChecksum.h b/src/ChunkChecksum.h
index c28364d0..126bd82f 100644
--- a/src/ChunkChecksum.h
+++ b/src/ChunkChecksum.h
@@ -60,7 +60,7 @@ public:
bool validateChunk(const std::string& actualDigest,
size_t index) const;
- uint64_t getEstimatedDataLength() const;
+ off_t getEstimatedDataLength() const;
size_t countPieceHash() const;
diff --git a/src/ChunkedDecodingStreamFilter.cc b/src/ChunkedDecodingStreamFilter.cc
index b1f98bdf..87140e9e 100644
--- a/src/ChunkedDecodingStreamFilter.cc
+++ b/src/ChunkedDecodingStreamFilter.cc
@@ -96,8 +96,11 @@ bool ChunkedDecodingStreamFilter::readChunkSize
if(extPos == std::string::npos || crlfPos < extPos) {
extPos = crlfPos;
}
- chunkSize_ = util::parseULLInt
+ chunkSize_ = util::parseLLInt
(std::string(buf_.begin(), buf_.begin()+extPos), 16);
+ if(chunkSize_ < 0) {
+ throw DL_ABORT_EX("Chunk size must be positive");
+ }
assert(crlfPos+2 > pbufSize);
inbufOffset += crlfPos+2-pbufSize;
buf_.clear();
@@ -155,8 +158,8 @@ bool ChunkedDecodingStreamFilter::readData
const SharedHandle<BinaryStream>& out,
const SharedHandle<Segment>& segment)
{
- uint64_t readlen =
- std::min(chunkSize_, static_cast<uint64_t>(inlen-inbufOffset));
+ off_t readlen =
+ std::min(chunkSize_, static_cast<off_t>(inlen-inbufOffset));
outlen += getDelegate()->transform(out, segment, inbuf+inbufOffset, readlen);
chunkSize_ -= readlen;
inbufOffset += readlen;
diff --git a/src/ChunkedDecodingStreamFilter.h b/src/ChunkedDecodingStreamFilter.h
index 6909e33e..902d3fb5 100644
--- a/src/ChunkedDecodingStreamFilter.h
+++ b/src/ChunkedDecodingStreamFilter.h
@@ -59,7 +59,7 @@ private:
std::string buf_;
- uint64_t chunkSize_;
+ off_t chunkSize_;
size_t bytesProcessed_;
diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc
index 23be204c..049f3bcd 100644
--- a/src/DefaultBtAnnounce.cc
+++ b/src/DefaultBtAnnounce.cc
@@ -142,7 +142,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
numWant = 0;
}
TransferStat stat = peerStorage_->calculateStat();
- uint64_t left =
+ off_t left =
pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
// Use last 8 bytes of peer ID as a key
const size_t keyLen = 8;
diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc
index 84627d60..9fa32b1c 100644
--- a/src/DefaultBtProgressInfoFile.cc
+++ b/src/DefaultBtProgressInfoFile.cc
@@ -275,7 +275,7 @@ void DefaultBtProgressInfoFile::load()
if(version >= 1) {
totalLength = ntoh64(totalLength);
}
- if(totalLength != dctx_->getTotalLength()) {
+ if(totalLength != static_cast<uint64_t>(dctx_->getTotalLength())) {
throw DL_ABORT_EX
(fmt("total length mismatch. expected: %lld, actual: %lld",
static_cast<long long int>(dctx_->getTotalLength()),
diff --git a/src/DefaultDiskWriter.cc b/src/DefaultDiskWriter.cc
index 7b475d8f..afa02072 100644
--- a/src/DefaultDiskWriter.cc
+++ b/src/DefaultDiskWriter.cc
@@ -41,7 +41,7 @@ DefaultDiskWriter::DefaultDiskWriter(const std::string& filename):
DefaultDiskWriter::~DefaultDiskWriter() {}
-void DefaultDiskWriter::initAndOpenFile(uint64_t totalLength)
+void DefaultDiskWriter::initAndOpenFile(off_t totalLength)
{
createFile();
}
diff --git a/src/DefaultDiskWriter.h b/src/DefaultDiskWriter.h
index 339e0edd..2bc5a488 100644
--- a/src/DefaultDiskWriter.h
+++ b/src/DefaultDiskWriter.h
@@ -45,7 +45,7 @@ public:
virtual ~DefaultDiskWriter();
- virtual void initAndOpenFile(uint64_t totalLength = 0);
+ virtual void initAndOpenFile(off_t totalLength = 0);
};
typedef SharedHandle<DefaultDiskWriter> DefaultDiskWriterHandle;
diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc
index af68de2a..dec61d6f 100644
--- a/src/DefaultPeerStorage.cc
+++ b/src/DefaultPeerStorage.cc
@@ -60,8 +60,8 @@ const size_t MAX_PEER_LIST_UPDATE = 100;
DefaultPeerStorage::DefaultPeerStorage()
: maxPeerListSize_(MAX_PEER_LIST_SIZE),
- removedPeerSessionDownloadLength_(0),
- removedPeerSessionUploadLength_(0),
+ removedPeerSessionDownloadLength_(0LL),
+ removedPeerSessionUploadLength_(0LL),
seederStateChoke_(new BtSeederStateChoke()),
leecherStateChoke_(new BtLeecherStateChoke()),
lastTransferStatMapUpdated_(0)
diff --git a/src/DefaultPeerStorage.h b/src/DefaultPeerStorage.h
index 5411eac7..8722e63b 100644
--- a/src/DefaultPeerStorage.h
+++ b/src/DefaultPeerStorage.h
@@ -56,8 +56,8 @@ private:
size_t maxPeerListSize_;
std::deque<SharedHandle<Peer> > peers_;
std::deque<SharedHandle<Peer> > droppedPeers_;
- uint64_t removedPeerSessionDownloadLength_;
- uint64_t removedPeerSessionUploadLength_;
+ int64_t removedPeerSessionDownloadLength_;
+ int64_t removedPeerSessionUploadLength_;
BtSeederStateChoke* seederStateChoke_;
BtLeecherStateChoke* leecherStateChoke_;
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 7268bcf8..0b32761b 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -518,28 +518,28 @@ bool DefaultPieceStorage::isPieceUsed(size_t index)
return bitfieldMan_->isUseBitSet(index);
}
-uint64_t DefaultPieceStorage::getTotalLength()
+off_t DefaultPieceStorage::getTotalLength()
{
return bitfieldMan_->getTotalLength();
}
-uint64_t DefaultPieceStorage::getFilteredTotalLength()
+off_t DefaultPieceStorage::getFilteredTotalLength()
{
return bitfieldMan_->getFilteredTotalLength();
}
-uint64_t DefaultPieceStorage::getCompletedLength()
+off_t DefaultPieceStorage::getCompletedLength()
{
- uint64_t completedLength =
+ off_t completedLength =
bitfieldMan_->getCompletedLength()+getInFlightPieceCompletedLength();
- uint64_t totalLength = getTotalLength();
+ off_t totalLength = getTotalLength();
if(completedLength > totalLength) {
completedLength = totalLength;
}
return completedLength;
}
-uint64_t DefaultPieceStorage::getFilteredCompletedLength()
+off_t DefaultPieceStorage::getFilteredCompletedLength()
{
return bitfieldMan_->getFilteredCompletedLength()+
getInFlightPieceCompletedLength();
@@ -712,7 +712,7 @@ void DefaultPieceStorage::markAllPiecesDone()
bitfieldMan_->setAllBit();
}
-void DefaultPieceStorage::markPiecesDone(uint64_t length)
+void DefaultPieceStorage::markPiecesDone(off_t length)
{
if(length == bitfieldMan_->getTotalLength()) {
bitfieldMan_->setAllBit();
diff --git a/src/DefaultPieceStorage.h b/src/DefaultPieceStorage.h
index 30f0ecf9..21b57fcb 100644
--- a/src/DefaultPieceStorage.h
+++ b/src/DefaultPieceStorage.h
@@ -187,13 +187,13 @@ public:
virtual bool isPieceUsed(size_t index);
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
- virtual uint64_t getFilteredTotalLength();
+ virtual off_t getFilteredTotalLength();
- virtual uint64_t getCompletedLength();
+ virtual off_t getCompletedLength();
- virtual uint64_t getFilteredCompletedLength();
+ virtual off_t getFilteredCompletedLength();
virtual void initStorage();
@@ -246,7 +246,7 @@ public:
virtual void markAllPiecesDone();
- virtual void markPiecesDone(uint64_t length);
+ virtual void markPiecesDone(off_t length);
virtual void markPieceMissing(size_t index);
diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h
index d7c06b90..6a94def0 100644
--- a/src/DiskAdaptor.h
+++ b/src/DiskAdaptor.h
@@ -66,7 +66,7 @@ public:
virtual bool fileExists() = 0;
- virtual uint64_t size() = 0;
+ virtual off_t size() = 0;
template<typename InputIterator>
void setFileEntries(InputIterator first, InputIterator last)
diff --git a/src/DiskWriter.h b/src/DiskWriter.h
index 427380d4..d7c2c8b4 100644
--- a/src/DiskWriter.h
+++ b/src/DiskWriter.h
@@ -51,9 +51,9 @@ public:
/**
* Opens file. If the file exists, then it is truncated to 0 length.
*/
- virtual void initAndOpenFile(uint64_t totalLength = 0) = 0;
+ virtual void initAndOpenFile(off_t totalLength = 0) = 0;
- virtual void openFile(uint64_t totalLength = 0) = 0;
+ virtual void openFile(off_t totalLength = 0) = 0;
/**
* Closes this output stream.
@@ -65,10 +65,10 @@ public:
* Opens a file. If the file doesnot exists, an exception may be
* thrown.
*/
- virtual void openExistingFile(uint64_t totalLength = 0) = 0;
+ virtual void openExistingFile(off_t totalLength = 0) = 0;
// Returns file length
- virtual uint64_t size() = 0;
+ virtual off_t size() = 0;
// Enables read-only mode. After this call, openExistingFile() opens
// file in read-only mode. This is an optional functionality. The
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
index 37da0cbb..2862d3d3 100644
--- a/src/DownloadCommand.cc
+++ b/src/DownloadCommand.cc
@@ -146,8 +146,8 @@ bool DownloadCommand::executeInternal() {
size_t bufSize;
if(sinkFilterOnly_) {
if(segment->getLength() > 0) {
- if(static_cast<uint64_t>(segment->getPosition()+segment->getLength()) <=
- static_cast<uint64_t>(getFileEntry()->getLastOffset())) {
+ if(static_cast<off_t>(segment->getPosition()+segment->getLength()) <=
+ getFileEntry()->getLastOffset()) {
bufSize = std::min(segment->getLength()-segment->getWrittenLength(),
getSocketRecvBuffer()->getBufferLength());
} else {
diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc
index 7f90627c..4a9e8e7a 100644
--- a/src/DownloadContext.cc
+++ b/src/DownloadContext.cc
@@ -57,7 +57,7 @@ DownloadContext::DownloadContext():
metalinkServerContacted_(false) {}
DownloadContext::DownloadContext(size_t pieceLength,
- uint64_t totalLength,
+ off_t totalLength,
const std::string& path):
pieceLength_(pieceLength),
checksumVerified_(false),
@@ -98,9 +98,7 @@ SharedHandle<FileEntry>
DownloadContext::findFileEntryByOffset(off_t offset) const
{
if(fileEntries_.empty() ||
- (offset > 0 &&
- fileEntries_.back()->getOffset()+fileEntries_.back()->getLength() <=
- static_cast<uint64_t>(offset))){
+ (offset > 0 && fileEntries_.back()->getLastOffset() <= offset)) {
return SharedHandle<FileEntry>();
}
@@ -200,7 +198,7 @@ size_t DownloadContext::getNumPieces() const
}
}
-uint64_t DownloadContext::getTotalLength() const
+off_t DownloadContext::getTotalLength() const
{
if(fileEntries_.empty()) {
return 0;
diff --git a/src/DownloadContext.h b/src/DownloadContext.h
index 46c69e69..7eee1f84 100644
--- a/src/DownloadContext.h
+++ b/src/DownloadContext.h
@@ -93,7 +93,7 @@ public:
// Convenient constructor that creates single file download. path
// should be escaped with util::escapePath(...).
DownloadContext(size_t pieceLength,
- uint64_t totalLength,
+ off_t totalLength,
const std::string& path = A2STR::NIL);
~DownloadContext();
@@ -114,7 +114,7 @@ public:
pieceHashes_.assign(first, last);
}
- uint64_t getTotalLength() const;
+ off_t getTotalLength() const;
bool knowsTotalLength() const { return knowsTotalLength_; }
diff --git a/src/DownloadResult.h b/src/DownloadResult.h
index 6c80ad29..5c920510 100644
--- a/src/DownloadResult.h
+++ b/src/DownloadResult.h
@@ -79,11 +79,11 @@ struct DownloadResult
SharedHandle<MetadataInfo> metadataInfo;
- uint64_t totalLength;
+ off_t totalLength;
- uint64_t completedLength;
+ off_t completedLength;
- uint64_t uploadLength;
+ off_t uploadLength;
std::string bitfield;
diff --git a/src/FallocFileAllocationIterator.cc b/src/FallocFileAllocationIterator.cc
index 3e4e24d1..f337bf7a 100644
--- a/src/FallocFileAllocationIterator.cc
+++ b/src/FallocFileAllocationIterator.cc
@@ -38,12 +38,12 @@
namespace aria2 {
FallocFileAllocationIterator::FallocFileAllocationIterator
-(BinaryStream* stream, off_t offset, uint64_t totalLength):
+(BinaryStream* stream, off_t offset, off_t totalLength):
stream_(stream), offset_(offset), totalLength_(totalLength) {}
void FallocFileAllocationIterator::allocateChunk()
{
- if(static_cast<uint64_t>(offset_) < totalLength_) {
+ if(offset_ < totalLength_) {
stream_->allocate(offset_, totalLength_-offset_);
offset_ = totalLength_;
} else {
@@ -54,7 +54,7 @@ void FallocFileAllocationIterator::allocateChunk()
bool FallocFileAllocationIterator::finished()
{
- return static_cast<uint64_t>(offset_) == totalLength_;
+ return offset_ == totalLength_;
}
off_t FallocFileAllocationIterator::getCurrentLength()
@@ -62,7 +62,7 @@ off_t FallocFileAllocationIterator::getCurrentLength()
return offset_;
}
-uint64_t FallocFileAllocationIterator::getTotalLength()
+off_t FallocFileAllocationIterator::getTotalLength()
{
return totalLength_;
}
diff --git a/src/FallocFileAllocationIterator.h b/src/FallocFileAllocationIterator.h
index e7e6fbc1..d43db3a6 100644
--- a/src/FallocFileAllocationIterator.h
+++ b/src/FallocFileAllocationIterator.h
@@ -45,10 +45,10 @@ class FallocFileAllocationIterator:public FileAllocationIterator {
private:
BinaryStream* stream_;
off_t offset_;
- uint64_t totalLength_;
+ off_t totalLength_;
public:
FallocFileAllocationIterator(BinaryStream* stream, off_t offset,
- uint64_t totalLength);
+ off_t totalLength);
virtual void allocateChunk();
@@ -56,7 +56,7 @@ public:
virtual off_t getCurrentLength();
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
};
} // namespace aria2
diff --git a/src/File.cc b/src/File.cc
index f47b78c7..87b95486 100644
--- a/src/File.cc
+++ b/src/File.cc
@@ -103,7 +103,7 @@ bool File::remove() {
}
}
-uint64_t File::size() {
+off_t File::size() {
a2_struct_stat fstat;
if(fillStat(fstat) < 0) {
return 0;
diff --git a/src/File.h b/src/File.h
index 37b1ba49..8290cd4e 100644
--- a/src/File.h
+++ b/src/File.h
@@ -94,7 +94,7 @@ public:
*/
bool mkdirs();
- uint64_t size();
+ off_t size();
mode_t mode();
diff --git a/src/FileAllocationEntry.cc b/src/FileAllocationEntry.cc
index 2d96f756..ff4e0f29 100644
--- a/src/FileAllocationEntry.cc
+++ b/src/FileAllocationEntry.cc
@@ -54,7 +54,7 @@ off_t FileAllocationEntry::getCurrentLength()
return fileAllocationIterator_->getCurrentLength();
}
-uint64_t FileAllocationEntry::getTotalLength()
+off_t FileAllocationEntry::getTotalLength()
{
return fileAllocationIterator_->getTotalLength();
}
diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h
index 509a8a04..4d47123f 100644
--- a/src/FileAllocationEntry.h
+++ b/src/FileAllocationEntry.h
@@ -56,7 +56,7 @@ public:
virtual off_t getCurrentLength();
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
virtual bool finished();
diff --git a/src/FileAllocationIterator.h b/src/FileAllocationIterator.h
index a57d4277..57f4e294 100644
--- a/src/FileAllocationIterator.h
+++ b/src/FileAllocationIterator.h
@@ -52,7 +52,7 @@ public:
virtual off_t getCurrentLength() = 0;
- virtual uint64_t getTotalLength() = 0;
+ virtual off_t getTotalLength() = 0;
};
} // namespace aria2
diff --git a/src/FileEntry.cc b/src/FileEntry.cc
index 23721e7a..1af951da 100644
--- a/src/FileEntry.cc
+++ b/src/FileEntry.cc
@@ -53,7 +53,7 @@ namespace aria2 {
FileEntry::FileEntry
(const std::string& path,
- uint64_t length,
+ off_t length,
off_t offset,
const std::vector<std::string>& uris)
: path_(path),
diff --git a/src/FileEntry.h b/src/FileEntry.h
index c77ca47a..1f3385ba 100644
--- a/src/FileEntry.h
+++ b/src/FileEntry.h
@@ -61,7 +61,7 @@ private:
std::string path_;
std::deque<std::string> uris_;
std::deque<std::string> spentUris_;
- uint64_t length_;
+ off_t length_;
off_t offset_;
bool requested_;
std::deque<SharedHandle<Request> > requestPool_;
@@ -79,7 +79,7 @@ private:
public:
FileEntry();
- FileEntry(const std::string& path, uint64_t length, off_t offset,
+ FileEntry(const std::string& path, off_t length, off_t offset,
const std::vector<std::string>& uris = std::vector<std::string>());
~FileEntry();
@@ -94,9 +94,9 @@ public:
void setPath(const std::string& path);
- uint64_t getLength() const { return length_; }
+ off_t getLength() const { return length_; }
- void setLength(uint64_t length) { length_ = length; }
+ void setLength(off_t length) { length_ = length; }
off_t getOffset() const { return offset_; }
diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc
index 90e430c4..4436d7c0 100644
--- a/src/FtpConnection.cc
+++ b/src/FtpConnection.cc
@@ -400,14 +400,17 @@ unsigned int FtpConnection::receiveResponse()
# define ULONGLONG_SCANF "%Lu"
#endif // __MINGW32__
-unsigned int FtpConnection::receiveSizeResponse(uint64_t& size)
+unsigned int FtpConnection::receiveSizeResponse(off_t& size)
{
std::pair<unsigned int, std::string> response;
if(bulkReceiveResponse(response)) {
if(response.first == 213) {
std::pair<Sip, Sip> rp;
util::divide(rp, response.second.begin(), response.second.end(), ' ');
- size = util::parseULLInt(std::string(rp.second.first, rp.second.second));
+ size = util::parseLLInt(std::string(rp.second.first, rp.second.second));
+ if(size < 0) {
+ throw DL_ABORT_EX("Size must be positive");
+ }
}
return response.first;
} else {
diff --git a/src/FtpConnection.h b/src/FtpConnection.h
index 6a33a33b..1abb9683 100644
--- a/src/FtpConnection.h
+++ b/src/FtpConnection.h
@@ -102,7 +102,7 @@ public:
bool sendRetr();
unsigned int receiveResponse();
- unsigned int receiveSizeResponse(uint64_t& size);
+ unsigned int receiveSizeResponse(off_t& size);
// Returns status code of MDTM reply. If the status code is 213, parses
// time-val and store it in time.
// If a code other than 213 is returned, time is not touched.
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc
index 7033715d..6412c7ac 100644
--- a/src/FtpNegotiationCommand.cc
+++ b/src/FtpNegotiationCommand.cc
@@ -364,7 +364,7 @@ bool FtpNegotiationCommand::sendSize() {
return false;
}
-bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
+bool FtpNegotiationCommand::onFileSizeDetermined(off_t totalLength)
{
getFileEntry()->setLength(totalLength);
if(getFileEntry()->getPath().empty()) {
@@ -464,7 +464,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
}
bool FtpNegotiationCommand::recvSize() {
- uint64_t size = 0;
+ off_t size = 0;
unsigned int status = ftp_->receiveSizeResponse(size);
if(status == 0) {
return false;
diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h
index b155595b..a22e6853 100644
--- a/src/FtpNegotiationCommand.h
+++ b/src/FtpNegotiationCommand.h
@@ -137,7 +137,7 @@ private:
void poolConnection() const;
- bool onFileSizeDetermined(uint64_t totalLength);
+ bool onFileSizeDetermined(off_t totalLength);
void onDryRunFileFound();
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index ad926cc0..ff6aa8d9 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -108,16 +108,23 @@ HttpHeader::equalRange(const std::string& name) const
return table_.equal_range(name);
}
-unsigned int HttpHeader::findAsUInt(const std::string& name) const {
- return findAsULLInt(name);
+int32_t HttpHeader::findAsInt(const std::string& name) const
+{
+ const std::string& value = find(name);
+ if(value.empty()) {
+ return 0;
+ } else {
+ return util::parseInt(value);
+ }
}
-uint64_t HttpHeader::findAsULLInt(const std::string& name) const {
+int64_t HttpHeader::findAsLLInt(const std::string& name) const
+{
const std::string& value = find(name);
if(value.empty()) {
return 0;
} else {
- return util::parseULLInt(value);
+ return util::parseLLInt(value);
}
}
@@ -129,7 +136,10 @@ RangeHandle HttpHeader::getRange() const
if(clenStr.empty()) {
return SharedHandle<Range>(new Range());
} else {
- uint64_t contentLength = util::parseULLInt(clenStr);
+ off_t contentLength = util::parseLLInt(clenStr);
+ if(contentLength < 0) {
+ throw DL_ABORT_EX("Content-Length must be positive");
+ }
if(contentLength == 0) {
return SharedHandle<Range>(new Range());
} else {
@@ -168,8 +178,11 @@ RangeHandle HttpHeader::getRange() const
}
off_t startByte = util::parseLLInt(std::string(byteRangeSpec, minus));
off_t endByte = util::parseLLInt(std::string(minus+1, slash));
- uint64_t entityLength =
- util::parseULLInt(std::string(slash+1, rangeStr.end()));
+ off_t entityLength =
+ util::parseLLInt(std::string(slash+1, rangeStr.end()));
+ if(startByte < 0 || endByte < 0 || entityLength < 0) {
+ throw DL_ABORT_EX("byte-range-spec must be positive");
+ }
return SharedHandle<Range>(new Range(startByte, endByte, entityLength));
}
diff --git a/src/HttpHeader.h b/src/HttpHeader.h
index 547a7615..b337e089 100644
--- a/src/HttpHeader.h
+++ b/src/HttpHeader.h
@@ -73,8 +73,8 @@ public:
std::pair<std::multimap<std::string, std::string>::const_iterator,
std::multimap<std::string, std::string>::const_iterator>
equalRange(const std::string& name) const;
- unsigned int findAsUInt(const std::string& name) const;
- uint64_t findAsULLInt(const std::string& name) const;
+ int32_t findAsInt(const std::string& name) const;
+ int64_t findAsLLInt(const std::string& name) const;
SharedHandle<Range> getRange() const;
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index fa99b583..50404956 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -368,7 +368,7 @@ const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const
return authConfig_;
}
-uint64_t HttpRequest::getEntityLength() const
+off_t HttpRequest::getEntityLength() const
{
assert(fileEntry_);
return fileEntry_->getLength();
diff --git a/src/HttpRequest.h b/src/HttpRequest.h
index 11d6642b..1e72f754 100644
--- a/src/HttpRequest.h
+++ b/src/HttpRequest.h
@@ -105,7 +105,7 @@ public:
void setRequest(const SharedHandle<Request>& request);
- uint64_t getEntityLength() const;
+ off_t getEntityLength() const;
const std::string& getHost() const;
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc
index 74ba8e10..a52ce99e 100644
--- a/src/HttpRequestCommand.cc
+++ b/src/HttpRequestCommand.cc
@@ -86,7 +86,7 @@ SharedHandle<HttpRequest>
createHttpRequest(const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const SharedHandle<Segment>& segment,
- uint64_t totalLength,
+ off_t totalLength,
const SharedHandle<Option>& option,
const RequestGroup* rg,
const SharedHandle<CookieStorage>& cookieStorage,
diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc
index bb2d1d09..b07d873a 100644
--- a/src/HttpResponse.cc
+++ b/src/HttpResponse.cc
@@ -227,7 +227,7 @@ SharedHandle<StreamFilter> HttpResponse::getContentEncodingStreamFilter() const
return filter;
}
-uint64_t HttpResponse::getContentLength() const
+off_t HttpResponse::getContentLength() const
{
if(!httpHeader_) {
return 0;
@@ -236,7 +236,7 @@ uint64_t HttpResponse::getContentLength() const
}
}
-uint64_t HttpResponse::getEntityLength() const
+off_t HttpResponse::getEntityLength() const
{
if(!httpHeader_) {
return 0;
@@ -279,7 +279,7 @@ bool HttpResponse::hasRetryAfter() const
time_t HttpResponse::getRetryAfter() const
{
- return httpHeader_->findAsUInt(HttpHeader::RETRY_AFTER);
+ return httpHeader_->findAsInt(HttpHeader::RETRY_AFTER);
}
Time HttpResponse::getLastModifiedTime() const
diff --git a/src/HttpResponse.h b/src/HttpResponse.h
index 0b379f75..7e43cb8c 100644
--- a/src/HttpResponse.h
+++ b/src/HttpResponse.h
@@ -96,9 +96,9 @@ public:
SharedHandle<StreamFilter> getContentEncodingStreamFilter() const;
- uint64_t getContentLength() const;
+ off_t getContentLength() const;
- uint64_t getEntityLength() const;
+ off_t getEntityLength() const;
// Returns type "/" subtype. The parameter is removed.
std::string getContentType() const;
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index f9242591..70af2e89 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -180,7 +180,7 @@ bool HttpResponseCommand::executeInternal()
int statusCode = httpResponse->getStatusCode();
if(statusCode == 304) {
- uint64_t totalLength = httpResponse->getEntityLength();
+ off_t totalLength = httpResponse->getEntityLength();
getFileEntry()->setLength(totalLength);
getRequestGroup()->initPieceStorage();
getPieceStorage()->markAllPiecesDone();
@@ -245,7 +245,7 @@ bool HttpResponseCommand::executeInternal()
}
if(!getPieceStorage()) {
util::removeMetalinkContentTypes(getRequestGroup());
- uint64_t totalLength = httpResponse->getEntityLength();
+ off_t totalLength = httpResponse->getEntityLength();
getFileEntry()->setLength(totalLength);
if(getFileEntry()->getPath().empty()) {
getFileEntry()->setPath
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index a30cc9ae..58add493 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -90,7 +90,10 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
lastBody_.clear();
lastBody_.str("");
lastContentLength_ =
- lastRequestHeader_->findAsUInt(HttpHeader::CONTENT_LENGTH);
+ lastRequestHeader_->findAsLLInt(HttpHeader::CONTENT_LENGTH);
+ if(lastContentLength_ < 0) {
+ throw DL_ABORT_EX("Content-Length must be positive.");
+ }
headerProcessor_->clear();
const std::string& connection =
@@ -144,7 +147,7 @@ bool HttpServer::receiveBody()
lastBody_.write(reinterpret_cast<const char*>(socketRecvBuffer_->getBuffer()),
length);
socketRecvBuffer_->shiftBuffer(length);
- return lastContentLength_ == static_cast<uint64_t>(lastBody_.tellp());
+ return lastContentLength_ == lastBody_.tellp();
}
std::string HttpServer::getBody() const
diff --git a/src/HttpServer.h b/src/HttpServer.h
index 665c6d88..f5ebb4ee 100644
--- a/src/HttpServer.h
+++ b/src/HttpServer.h
@@ -60,7 +60,7 @@ private:
DownloadEngine* e_;
SharedHandle<HttpHeaderProcessor> headerProcessor_;
SharedHandle<HttpHeader> lastRequestHeader_;
- uint64_t lastContentLength_;
+ off_t lastContentLength_;
std::stringstream lastBody_;
bool keepAlive_;
bool gzip_;
@@ -118,7 +118,7 @@ public:
void disableGZip() { gzip_ = false; }
- uint64_t getContentLength() const { return lastContentLength_; }
+ off_t getContentLength() const { return lastContentLength_; }
const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
{
diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc
index a2089645..d5653c92 100644
--- a/src/HttpServerCommand.cc
+++ b/src/HttpServerCommand.cc
@@ -133,8 +133,7 @@ bool HttpServerCommand::execute()
e_->setNoWait(true);
return true;
}
- if(static_cast<uint64_t>
- (e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE)) <
+ if(e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE) <
httpServer_->getContentLength()) {
A2_LOG_INFO
(fmt("Request too long. ContentLength=%lld."
diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc
index c9744929..56d96ecc 100644
--- a/src/HttpSkipResponseCommand.cc
+++ b/src/HttpSkipResponseCommand.cc
@@ -127,7 +127,7 @@ bool HttpSkipResponseCommand::executeInternal()
if(totalLength_ > 0) {
bufSize = std::min
(totalLength_-receivedBytes_,
- static_cast<uint64_t>(getSocketRecvBuffer()->getBufferLength()));
+ static_cast<off_t>(getSocketRecvBuffer()->getBufferLength()));
} else {
bufSize = getSocketRecvBuffer()->getBufferLength();
}
diff --git a/src/HttpSkipResponseCommand.h b/src/HttpSkipResponseCommand.h
index 4a04b43c..c4a99041 100644
--- a/src/HttpSkipResponseCommand.h
+++ b/src/HttpSkipResponseCommand.h
@@ -53,9 +53,9 @@ private:
bool sinkFilterOnly_;
- uint64_t totalLength_;
+ off_t totalLength_;
- uint64_t receivedBytes_;
+ off_t receivedBytes_;
bool processResponse();
diff --git a/src/IteratableChecksumValidator.cc b/src/IteratableChecksumValidator.cc
index 29451d4f..c086522b 100644
--- a/src/IteratableChecksumValidator.cc
+++ b/src/IteratableChecksumValidator.cc
@@ -84,14 +84,14 @@ void IteratableChecksumValidator::validateChunk()
bool IteratableChecksumValidator::finished() const
{
- if((uint64_t)currentOffset_ >= dctx_->getTotalLength()) {
+ if(currentOffset_ >= dctx_->getTotalLength()) {
return true;
} else {
return false;
}
}
-uint64_t IteratableChecksumValidator::getTotalLength() const
+off_t IteratableChecksumValidator::getTotalLength() const
{
return dctx_->getTotalLength();
}
diff --git a/src/IteratableChecksumValidator.h b/src/IteratableChecksumValidator.h
index d38fb42c..2c4e60d5 100644
--- a/src/IteratableChecksumValidator.h
+++ b/src/IteratableChecksumValidator.h
@@ -70,7 +70,7 @@ public:
return currentOffset_;
}
- virtual uint64_t getTotalLength() const;
+ virtual off_t getTotalLength() const;
};
typedef SharedHandle<IteratableChecksumValidator> IteratableChecksumValidatorHandle;
diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc
index db479dc8..f3f7f2b2 100644
--- a/src/IteratableChunkChecksumValidator.cc
+++ b/src/IteratableChunkChecksumValidator.cc
@@ -149,10 +149,10 @@ bool IteratableChunkChecksumValidator::finished() const
off_t IteratableChunkChecksumValidator::getCurrentOffset() const
{
- return (off_t)currentIndex_*dctx_->getPieceLength();
+ return static_cast<off_t>(currentIndex_)*dctx_->getPieceLength();
}
-uint64_t IteratableChunkChecksumValidator::getTotalLength() const
+off_t IteratableChunkChecksumValidator::getTotalLength() const
{
return dctx_->getTotalLength();
}
diff --git a/src/IteratableChunkChecksumValidator.h b/src/IteratableChunkChecksumValidator.h
index 5e9bfef1..314e5765 100644
--- a/src/IteratableChunkChecksumValidator.h
+++ b/src/IteratableChunkChecksumValidator.h
@@ -73,7 +73,7 @@ public:
virtual off_t getCurrentOffset() const;
- virtual uint64_t getTotalLength() const;
+ virtual off_t getTotalLength() const;
};
typedef SharedHandle<IteratableChunkChecksumValidator> IteratableChunkChecksumValidatorHandle;
diff --git a/src/IteratableValidator.h b/src/IteratableValidator.h
index f208f0ed..ca339ccc 100644
--- a/src/IteratableValidator.h
+++ b/src/IteratableValidator.h
@@ -62,7 +62,7 @@ public:
virtual off_t getCurrentOffset() const = 0;
- virtual uint64_t getTotalLength() const = 0;
+ virtual off_t getTotalLength() const = 0;
};
typedef SharedHandle<IteratableValidator> IteratableValidatorHandle;
diff --git a/src/LpdMessageReceiver.cc b/src/LpdMessageReceiver.cc
index 0d817776..ff2faab1 100644
--- a/src/LpdMessageReceiver.cc
+++ b/src/LpdMessageReceiver.cc
@@ -97,7 +97,7 @@ SharedHandle<LpdMessage> LpdMessageReceiver::receiveMessage()
static const std::string A2_INFOHASH = "infohash";
static const std::string A2_PORT = "port";
const std::string& infoHashString = header->find(A2_INFOHASH);
- uint16_t port = header->findAsUInt(A2_PORT);
+ uint16_t port = header->findAsInt(A2_PORT);
A2_LOG_INFO(fmt("LPD message received infohash=%s, port=%u from %s",
infoHashString.c_str(),
port,
diff --git a/src/MetalinkEntry.cc b/src/MetalinkEntry.cc
index 9c720a2d..d1ae70be 100644
--- a/src/MetalinkEntry.cc
+++ b/src/MetalinkEntry.cc
@@ -101,7 +101,7 @@ const std::string& MetalinkEntry::getPath() const
return file->getPath();
}
-uint64_t MetalinkEntry::getLength() const
+off_t MetalinkEntry::getLength() const
{
return file->getLength();
}
diff --git a/src/MetalinkEntry.h b/src/MetalinkEntry.h
index 43b1ebdb..94395e7c 100644
--- a/src/MetalinkEntry.h
+++ b/src/MetalinkEntry.h
@@ -79,7 +79,7 @@ public:
const std::string& getPath() const;
- uint64_t getLength() const;
+ off_t getLength() const;
const SharedHandle<FileEntry>& getFile() const
{
diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc
index 51146930..1820c949 100644
--- a/src/MetalinkParserController.cc
+++ b/src/MetalinkParserController.cc
@@ -87,7 +87,7 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
}
}
-void MetalinkParserController::setFileLengthOfEntry(uint64_t length)
+void MetalinkParserController::setFileLengthOfEntry(off_t length)
{
if(!tEntry_) {
return;
diff --git a/src/MetalinkParserController.h b/src/MetalinkParserController.h
index c886becc..65f6124b 100644
--- a/src/MetalinkParserController.h
+++ b/src/MetalinkParserController.h
@@ -96,7 +96,7 @@ public:
void setFileNameOfEntry(const std::string& filename);
- void setFileLengthOfEntry(uint64_t length);
+ void setFileLengthOfEntry(off_t length);
void setVersionOfEntry(const std::string& version);
diff --git a/src/MetalinkParserStateMachine.cc b/src/MetalinkParserStateMachine.cc
index d97c6bbe..17eb0304 100644
--- a/src/MetalinkParserStateMachine.cc
+++ b/src/MetalinkParserStateMachine.cc
@@ -262,7 +262,7 @@ void MetalinkParserStateMachine::setFileNameOfEntry(const std::string& filename)
ctrl_->setFileNameOfEntry(filename);
}
-void MetalinkParserStateMachine::setFileLengthOfEntry(uint64_t length)
+void MetalinkParserStateMachine::setFileLengthOfEntry(off_t length)
{
ctrl_->setFileLengthOfEntry(length);
}
diff --git a/src/MetalinkParserStateMachine.h b/src/MetalinkParserStateMachine.h
index e0d9038c..b4e1da5c 100644
--- a/src/MetalinkParserStateMachine.h
+++ b/src/MetalinkParserStateMachine.h
@@ -159,7 +159,7 @@ public:
void setFileNameOfEntry(const std::string& filename);
- void setFileLengthOfEntry(uint64_t length);
+ void setFileLengthOfEntry(off_t length);
void setVersionOfEntry(const std::string& version);
diff --git a/src/MetalinkParserStateV3Impl.cc b/src/MetalinkParserStateV3Impl.cc
index 783f0e69..fd85270f 100644
--- a/src/MetalinkParserStateV3Impl.cc
+++ b/src/MetalinkParserStateV3Impl.cc
@@ -148,8 +148,8 @@ void SizeMetalinkParserState::endElement
const std::string& characters)
{
// current metalink specification doesn't require size element.
- uint64_t size;
- if(util::parseULLIntNoThrow(size, characters)) {
+ off_t size;
+ if(util::parseLLIntNoThrow(size, characters) && size >= 0) {
psm->setFileLengthOfEntry(size);
}
}
diff --git a/src/MetalinkParserStateV4Impl.cc b/src/MetalinkParserStateV4Impl.cc
index 2ba07297..31573139 100644
--- a/src/MetalinkParserStateV4Impl.cc
+++ b/src/MetalinkParserStateV4Impl.cc
@@ -253,8 +253,8 @@ void SizeMetalinkParserStateV4::endElement
const char* nsUri,
const std::string& characters)
{
- uint64_t size;
- if(util::parseULLIntNoThrow(size, characters)) {
+ off_t size;
+ if(util::parseLLIntNoThrow(size, characters) && size >= 0) {
psm->setFileLengthOfEntry(size);
} else {
psm->cancelEntryTransaction();
diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc
index 65bec7e3..2f815f06 100644
--- a/src/MultiDiskAdaptor.cc
+++ b/src/MultiDiskAdaptor.cc
@@ -101,7 +101,7 @@ bool DiskWriterEntry::fileExists()
return fileEntry_->exists();
}
-uint64_t DiskWriterEntry::size() const
+off_t DiskWriterEntry::size() const
{
return File(getFilePath()).size();
}
@@ -169,8 +169,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
itr-1; true; --i) {
const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
if(pieceStartOffset <= fileEntry->getOffset() ||
- (uint64_t)pieceStartOffset <
- fileEntry->getOffset()+fileEntry->getLength()) {
+ pieceStartOffset < fileEntry->getLastOffset()) {
(*i)->needsFileAllocation(true);
} else {
break;
@@ -306,22 +305,19 @@ namespace {
bool isInRange(const DiskWriterEntryHandle entry, off_t offset)
{
return entry->getFileEntry()->getOffset() <= offset &&
- (uint64_t)offset <
- entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength();
+ offset < entry->getFileEntry()->getLastOffset();
}
} // namespace
namespace {
-size_t calculateLength(const DiskWriterEntryHandle entry,
- off_t fileOffset, size_t rem)
+ssize_t calculateLength(const DiskWriterEntryHandle entry,
+ off_t fileOffset, ssize_t rem)
{
- size_t length;
- if(entry->getFileEntry()->getLength() < (uint64_t)fileOffset+rem) {
- length = entry->getFileEntry()->getLength()-fileOffset;
+ if(entry->getFileEntry()->getLength() < fileOffset+rem) {
+ return entry->getFileEntry()->getLength()-fileOffset;
} else {
- length = rem;
+ return rem;
}
- return length;
}
} // namespace
@@ -371,11 +367,11 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
DiskWriterEntries::const_iterator first =
findFirstDiskWriterEntry(diskWriterEntries_, offset);
- size_t rem = len;
+ ssize_t rem = len;
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
for(DiskWriterEntries::const_iterator i = first,
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
- size_t writeLength = calculateLength(*i, fileOffset, rem);
+ ssize_t writeLength = calculateLength(*i, fileOffset, rem);
openIfNot(*i, &DiskWriterEntry::openFile);
@@ -398,12 +394,12 @@ ssize_t MultiDiskAdaptor::readData
DiskWriterEntries::const_iterator first =
findFirstDiskWriterEntry(diskWriterEntries_, offset);
- size_t rem = len;
- size_t totalReadLength = 0;
+ ssize_t rem = len;
+ ssize_t totalReadLength = 0;
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
for(DiskWriterEntries::const_iterator i = first,
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
- size_t readLength = calculateLength(*i, fileOffset, rem);
+ ssize_t readLength = calculateLength(*i, fileOffset, rem);
openIfNot(*i, &DiskWriterEntry::openFile);
@@ -429,9 +425,9 @@ bool MultiDiskAdaptor::fileExists()
getFileEntries().end();
}
-uint64_t MultiDiskAdaptor::size()
+off_t MultiDiskAdaptor::size()
{
- uint64_t size = 0;
+ off_t size = 0;
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
size += File((*i)->getPath()).size();
@@ -460,9 +456,9 @@ void MultiDiskAdaptor::cutTrailingGarbage()
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
i != eoi; ++i) {
- uint64_t length = (*i)->getFileEntry()->getLength();
+ off_t length = (*i)->getFileEntry()->getLength();
if(File((*i)->getFilePath()).size() > length) {
- // We need open file before calling DiskWriter::truncate(uint64_t)
+ // We need open file before calling DiskWriter::truncate(off_t)
openIfNot(*i, &DiskWriterEntry::openFile);
(*i)->getDiskWriter()->truncate(length);
}
diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h
index 4eecaae0..dea911f5 100644
--- a/src/MultiDiskAdaptor.h
+++ b/src/MultiDiskAdaptor.h
@@ -69,7 +69,7 @@ public:
bool fileExists();
- uint64_t size() const;
+ off_t size() const;
const SharedHandle<FileEntry>& getFileEntry() const
{
@@ -139,7 +139,7 @@ public:
virtual bool fileExists();
- virtual uint64_t size();
+ virtual off_t size();
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc
index 85b3f527..6b6a89fa 100644
--- a/src/MultiFileAllocationIterator.cc
+++ b/src/MultiFileAllocationIterator.cc
@@ -104,7 +104,7 @@ off_t MultiFileAllocationIterator::getCurrentLength()
}
}
-uint64_t MultiFileAllocationIterator::getTotalLength()
+off_t MultiFileAllocationIterator::getTotalLength()
{
if(!fileAllocationIterator_) {
return 0;
diff --git a/src/MultiFileAllocationIterator.h b/src/MultiFileAllocationIterator.h
index c649cedf..55d607b6 100644
--- a/src/MultiFileAllocationIterator.h
+++ b/src/MultiFileAllocationIterator.h
@@ -61,7 +61,7 @@ public:
virtual off_t getCurrentLength();
- virtual uint64_t getTotalLength();
+ virtual off_t getTotalLength();
const std::deque<SharedHandle<DiskWriterEntry> >&
getDiskWriterEntries() const;
diff --git a/src/Peer.cc b/src/Peer.cc
index fc690cc9..07d2f22a 100644
--- a/src/Peer.cc
+++ b/src/Peer.cc
@@ -73,7 +73,7 @@ void Peer::usedBy(cuid_t cuid)
cuid_ = cuid;
}
-void Peer::allocateSessionResource(size_t pieceLength, uint64_t totalLength)
+void Peer::allocateSessionResource(size_t pieceLength, off_t totalLength)
{
delete res_;
res_ = new PeerSessionResource(pieceLength, totalLength);
@@ -81,7 +81,7 @@ void Peer::allocateSessionResource(size_t pieceLength, uint64_t totalLength)
updateSeeder();
}
-void Peer::reconfigureSessionResource(size_t pieceLength, uint64_t totalLength)
+void Peer::reconfigureSessionResource(size_t pieceLength, off_t totalLength)
{
assert(res_);
res_->reconfigure(pieceLength, totalLength);
@@ -228,13 +228,13 @@ unsigned int Peer::calculateDownloadSpeed()
return res_->getPeerStat().calculateDownloadSpeed();
}
-uint64_t Peer::getSessionUploadLength() const
+off_t Peer::getSessionUploadLength() const
{
assert(res_);
return res_->uploadLength();
}
-uint64_t Peer::getSessionDownloadLength() const
+off_t Peer::getSessionDownloadLength() const
{
assert(res_);
return res_->downloadLength();
@@ -388,7 +388,7 @@ const Timer& Peer::getLastAmUnchoking() const
return res_->getLastAmUnchoking();
}
-uint64_t Peer::getCompletedLength() const
+off_t Peer::getCompletedLength() const
{
assert(res_);
return res_->getCompletedLength();
diff --git a/src/Peer.h b/src/Peer.h
index 92fff8a8..0d25eca0 100644
--- a/src/Peer.h
+++ b/src/Peer.h
@@ -160,9 +160,9 @@ public:
bool isGood() const;
- void allocateSessionResource(size_t pieceLength, uint64_t totalLength);
+ void allocateSessionResource(size_t pieceLength, off_t totalLength);
- void reconfigureSessionResource(size_t pieceLength, uint64_t totalLength);
+ void reconfigureSessionResource(size_t pieceLength, off_t totalLength);
void releaseSessionResource();
@@ -234,12 +234,12 @@ public:
/**
* Returns the number of bytes uploaded to the remote host.
*/
- uint64_t getSessionUploadLength() const;
+ off_t getSessionUploadLength() const;
/**
* Returns the number of bytes downloaded from the remote host.
*/
- uint64_t getSessionDownloadLength() const;
+ off_t getSessionDownloadLength() const;
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
@@ -293,7 +293,7 @@ public:
const Timer& getLastAmUnchoking() const;
- uint64_t getCompletedLength() const;
+ off_t getCompletedLength() const;
bool isIncomingPeer() const
{
diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc
index 790f1148..912f665d 100644
--- a/src/PeerSessionResource.cc
+++ b/src/PeerSessionResource.cc
@@ -44,7 +44,7 @@
namespace aria2 {
-PeerSessionResource::PeerSessionResource(size_t pieceLength, uint64_t totalLength):
+PeerSessionResource::PeerSessionResource(size_t pieceLength, off_t totalLength):
amChoking_(true),
amInterested_(false),
peerChoking_(true),
@@ -237,7 +237,7 @@ void PeerSessionResource::dhtEnabled(bool b)
dhtEnabled_ = b;
}
-uint64_t PeerSessionResource::uploadLength() const
+off_t PeerSessionResource::uploadLength() const
{
return peerStat_.getSessionUploadLength();
}
@@ -247,7 +247,7 @@ void PeerSessionResource::updateUploadLength(size_t bytes)
peerStat_.updateUploadLength(bytes);
}
-uint64_t PeerSessionResource::downloadLength() const
+off_t PeerSessionResource::downloadLength() const
{
return peerStat_.getSessionDownloadLength();
}
@@ -259,7 +259,7 @@ void PeerSessionResource::updateDownloadLength(size_t bytes)
lastDownloadUpdate_ = global::wallclock();
}
-uint64_t PeerSessionResource::getCompletedLength() const
+off_t PeerSessionResource::getCompletedLength() const
{
return bitfieldMan_->getCompletedLength();
}
@@ -275,7 +275,7 @@ size_t PeerSessionResource::countOutstandingUpload() const
return dispatcher_->countOutstandingUpload();
}
-void PeerSessionResource::reconfigure(size_t pieceLength, uint64_t totalLenth)
+void PeerSessionResource::reconfigure(size_t pieceLength, off_t totalLenth)
{
delete bitfieldMan_;
bitfieldMan_ = new BitfieldMan(pieceLength, totalLenth);
diff --git a/src/PeerSessionResource.h b/src/PeerSessionResource.h
index fecd23fd..3d4a6869 100644
--- a/src/PeerSessionResource.h
+++ b/src/PeerSessionResource.h
@@ -83,7 +83,7 @@ private:
BtMessageDispatcher* dispatcher_;
public:
- PeerSessionResource(size_t pieceLength, uint64_t totalLength);
+ PeerSessionResource(size_t pieceLength, off_t totalLength);
~PeerSessionResource();
@@ -155,7 +155,7 @@ public:
size_t getBitfieldLength() const;
- void reconfigure(size_t index, uint64_t totalLength);
+ void reconfigure(size_t index, off_t totalLength);
bool hasPiece(size_t index) const;
@@ -210,11 +210,11 @@ public:
return peerStat_;
}
- uint64_t uploadLength() const;
+ off_t uploadLength() const;
void updateUploadLength(size_t bytes);
- uint64_t downloadLength() const;
+ off_t downloadLength() const;
void updateDownloadLength(size_t bytes);
@@ -228,7 +228,7 @@ public:
return lastAmUnchoking_;
}
- uint64_t getCompletedLength() const;
+ off_t getCompletedLength() const;
void setBtMessageDispatcher(BtMessageDispatcher* dpt);
diff --git a/src/PeerStat.h b/src/PeerStat.h
index fc491c1a..c328173d 100644
--- a/src/PeerStat.h
+++ b/src/PeerStat.h
@@ -61,8 +61,8 @@ private:
PeerStat::STATUS status_;
unsigned int avgDownloadSpeed_;
unsigned int avgUploadSpeed_;
- uint64_t sessionDownloadLength_;
- uint64_t sessionUploadLength_;
+ int64_t sessionDownloadLength_;
+ int64_t sessionUploadLength_;
public:
PeerStat
(cuid_t cuid, const std::string& hostname, const::std::string& protocol);
diff --git a/src/PieceStorage.h b/src/PieceStorage.h
index b3d3e46c..5f53122e 100644
--- a/src/PieceStorage.h
+++ b/src/PieceStorage.h
@@ -179,13 +179,13 @@ public:
virtual bool isPieceUsed(size_t index) = 0;
- virtual uint64_t getTotalLength() = 0;
+ virtual off_t getTotalLength() = 0;
- virtual uint64_t getFilteredTotalLength() = 0;
+ virtual off_t getFilteredTotalLength() = 0;
- virtual uint64_t getCompletedLength() = 0;
+ virtual off_t getCompletedLength() = 0;
- virtual uint64_t getFilteredCompletedLength() = 0;
+ virtual off_t getFilteredCompletedLength() = 0;
virtual void setupFileFilter() = 0;
@@ -258,7 +258,7 @@ public:
/**
* Sets all bits in bitfield(0 to length) to 1.
*/
- virtual void markPiecesDone(uint64_t length) = 0;
+ virtual void markPiecesDone(off_t length) = 0;
virtual void
addInFlightPiece(const std::vector<SharedHandle<Piece> >& pieces) = 0;
diff --git a/src/ProgressAwareEntry.h b/src/ProgressAwareEntry.h
index 48f0ad0f..82d78217 100644
--- a/src/ProgressAwareEntry.h
+++ b/src/ProgressAwareEntry.h
@@ -50,7 +50,7 @@ public:
virtual off_t getCurrentLength() = 0;
- virtual uint64_t getTotalLength() = 0;
+ virtual off_t getTotalLength() = 0;
virtual bool finished() = 0;
};
diff --git a/src/Range.cc b/src/Range.cc
index ba2439c7..e61e66f8 100644
--- a/src/Range.cc
+++ b/src/Range.cc
@@ -38,7 +38,7 @@ namespace aria2 {
Range::Range():startByte_(0), endByte_(0), entityLength_(0) {}
-Range::Range(off_t startByte, off_t endByte, uint64_t entityLength)
+Range::Range(off_t startByte, off_t endByte, off_t entityLength)
: startByte_(startByte), endByte_(endByte), entityLength_(entityLength)
{}
@@ -72,7 +72,7 @@ bool Range::operator!=(const Range& range) const
return !(*this == range);
}
-uint64_t Range::getContentLength() const
+off_t Range::getContentLength() const
{
if(endByte_ >= startByte_) {
return endByte_-startByte_+1;
diff --git a/src/Range.h b/src/Range.h
index c43b99b2..6852a272 100644
--- a/src/Range.h
+++ b/src/Range.h
@@ -47,11 +47,11 @@ class Range {
private:
off_t startByte_;
off_t endByte_;
- uint64_t entityLength_;
+ off_t entityLength_;
public:
Range();
- Range(off_t startByte, off_t endByte, uint64_t entityLength);
+ Range(off_t startByte, off_t endByte, off_t entityLength);
Range(const Range& c);
@@ -73,12 +73,12 @@ public:
return endByte_;
}
- uint64_t getEntityLength() const
+ off_t getEntityLength() const
{
return entityLength_;
}
- uint64_t getContentLength() const;
+ off_t getContentLength() const;
};
typedef SharedHandle<Range> RangeHandle;
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index 9f71548f..b09fb818 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -390,7 +390,7 @@ void RequestGroup::createInitialCommand
}
removeDefunctControlFile(progressInfoFile);
{
- uint64_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
+ off_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
if(actualFileSize == downloadContext_->getTotalLength()) {
// First, make DiskAdaptor read-only mode to allow the
// program to seed file in read-only media.
@@ -555,7 +555,7 @@ void RequestGroup::processCheckIntegrityEntry
const SharedHandle<CheckIntegrityEntry>& entry,
DownloadEngine* e)
{
- uint64_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
+ off_t actualFileSize = pieceStorage_->getDiskAdaptor()->size();
if(actualFileSize > downloadContext_->getTotalLength()) {
entry->cutTrailingGarbage();
}
@@ -863,7 +863,7 @@ std::string RequestGroup::getFirstFilePath() const
}
}
-uint64_t RequestGroup::getTotalLength() const
+off_t RequestGroup::getTotalLength() const
{
if(!pieceStorage_) {
return 0;
@@ -876,7 +876,7 @@ uint64_t RequestGroup::getTotalLength() const
}
}
-uint64_t RequestGroup::getCompletedLength() const
+off_t RequestGroup::getCompletedLength() const
{
if(!pieceStorage_) {
return 0;
@@ -902,8 +902,8 @@ void RequestGroup::validateFilename(const std::string& expectedFilename,
}
}
-void RequestGroup::validateTotalLength(uint64_t expectedTotalLength,
- uint64_t actualTotalLength) const
+void RequestGroup::validateTotalLength(off_t expectedTotalLength,
+ off_t actualTotalLength) const
{
if(expectedTotalLength <= 0) {
return;
@@ -921,7 +921,7 @@ void RequestGroup::validateFilename(const std::string& actualFilename) const
validateFilename(downloadContext_->getFileEntries().front()->getBasename(), actualFilename);
}
-void RequestGroup::validateTotalLength(uint64_t actualTotalLength) const
+void RequestGroup::validateTotalLength(off_t actualTotalLength) const
{
validateTotalLength(getTotalLength(), actualTotalLength);
}
@@ -1155,7 +1155,7 @@ void RequestGroup::setProgressInfoFile(const BtProgressInfoFileHandle& progressI
bool RequestGroup::needsFileAllocation() const
{
return isFileAllocationEnabled() &&
- (uint64_t)option_->getAsLLInt(PREF_NO_FILE_ALLOCATION_LIMIT) <= getTotalLength() &&
+ option_->getAsLLInt(PREF_NO_FILE_ALLOCATION_LIMIT) <= getTotalLength() &&
!pieceStorage_->getDiskAdaptor()->fileAllocationIterator()->finished();
}
@@ -1204,7 +1204,7 @@ void RequestGroup::reportDownloadFinished()
#ifdef ENABLE_BITTORRENT
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
TransferStat stat = calculateStat();
- uint64_t completedLength = getCompletedLength();
+ off_t completedLength = getCompletedLength();
double shareRatio = completedLength == 0 ? 0.0 :
1.0*stat.getAllTimeUploadLength()/completedLength;
SharedHandle<TorrentAttribute> attrs =
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index bd694ad7..b2bfb9cd 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -230,9 +230,9 @@ public:
std::string getFirstFilePath() const;
- uint64_t getTotalLength() const;
+ off_t getTotalLength() const;
- uint64_t getCompletedLength() const;
+ off_t getCompletedLength() const;
/**
* Compares expected filename with specified actualFilename.
@@ -241,10 +241,10 @@ public:
*/
void validateFilename(const std::string& actualFilename) const;
- void validateTotalLength(uint64_t expectedTotalLength,
- uint64_t actualTotalLength) const;
+ void validateTotalLength(off_t expectedTotalLength,
+ off_t actualTotalLength) const;
- void validateTotalLength(uint64_t actualTotalLength) const;
+ void validateTotalLength(off_t actualTotalLength) const;
void setNumConcurrentCommand(unsigned int num)
{
diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc
index bb0f1232..857ec571 100644
--- a/src/RequestGroupMan.cc
+++ b/src/RequestGroupMan.cc
@@ -711,7 +711,7 @@ void RequestGroupMan::formatDownloadResultFull
if((*i)->getLength() == 0 || downloadResult->bitfield.empty()) {
o << " -|";
} else {
- uint64_t completedLength =
+ off_t completedLength =
bt.getOffsetCompletedLength((*i)->getOffset(), (*i)->getLength());
o << std::setw(3) << 100*completedLength/(*i)->getLength() << "|";
}
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index 99f113ee..4e0904fa 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -585,9 +585,9 @@ void createFileEntry
entry->put(KEY_PATH, (*first)->getPath());
entry->put(KEY_SELECTED, (*first)->isRequested()?VLB_TRUE:VLB_FALSE);
entry->put(KEY_LENGTH, util::uitos((*first)->getLength()));
- uint64_t completedLength = bf->getOffsetCompletedLength
+ off_t completedLength = bf->getOffsetCompletedLength
((*first)->getOffset(), (*first)->getLength());
- entry->put(KEY_COMPLETED_LENGTH, util::uitos(completedLength));
+ entry->put(KEY_COMPLETED_LENGTH, util::itos(completedLength));
SharedHandle<List> uriList = List::g();
createUriEntry(uriList, *first);
@@ -602,7 +602,7 @@ template<typename InputIterator>
void createFileEntry
(const SharedHandle<List>& files,
InputIterator first, InputIterator last,
- uint64_t totalLength,
+ off_t totalLength,
size_t pieceLength,
const std::string& bitfield)
{
@@ -618,7 +618,7 @@ template<typename InputIterator>
void createFileEntry
(const SharedHandle<List>& files,
InputIterator first, InputIterator last,
- uint64_t totalLength,
+ off_t totalLength,
size_t pieceLength,
const SharedHandle<PieceStorage>& ps)
{
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index 3664f862..3914a660 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -94,7 +94,7 @@ void SegmentMan::init()
// PieceStorage here?
}
-uint64_t SegmentMan::getTotalLength() const
+off_t SegmentMan::getTotalLength() const
{
if(!pieceStorage_) {
return 0;
@@ -342,7 +342,7 @@ bool SegmentMan::hasSegment(size_t index) const {
return pieceStorage_->hasPiece(index);
}
-uint64_t SegmentMan::getDownloadLength() const {
+off_t SegmentMan::getDownloadLength() const {
if(!pieceStorage_) {
return 0;
} else {
@@ -444,14 +444,14 @@ void SegmentMan::updateDownloadSpeedFor(const SharedHandle<PeerStat>& pstat)
namespace {
class PeerStatDownloadLengthOperator {
public:
- uint64_t operator()(uint64_t total, const SharedHandle<PeerStat>& ps)
+ off_t operator()(off_t total, const SharedHandle<PeerStat>& ps)
{
return ps->getSessionDownloadLength()+total;
}
};
} // namespace
-uint64_t SegmentMan::calculateSessionDownloadLength() const
+off_t SegmentMan::calculateSessionDownloadLength() const
{
return std::accumulate(fastestPeerStats_.begin(), fastestPeerStats_.end(),
0LL, PeerStatDownloadLengthOperator());
diff --git a/src/SegmentMan.h b/src/SegmentMan.h
index 3eae1501..a19fce3e 100644
--- a/src/SegmentMan.h
+++ b/src/SegmentMan.h
@@ -124,7 +124,7 @@ public:
* If Transfer-Encoding is Chunked or Content-Length header is not provided,
* then this value is set to be 0.
*/
- uint64_t getTotalLength() const;
+ off_t getTotalLength() const;
/**
* Returs true when the download has finished.
@@ -202,7 +202,7 @@ public:
/**
* Returns the length of bytes downloaded.
*/
- uint64_t getDownloadLength() const;
+ off_t getDownloadLength() const;
// If there is inactive PeerStat in peerStats_, it is replaced with
@@ -238,7 +238,7 @@ public:
/**
* Returns the downloaded bytes in this session.
*/
- uint64_t calculateSessionDownloadLength() const;
+ off_t calculateSessionDownloadLength() const;
size_t countFreePieceFrom(size_t index) const;
diff --git a/src/ShareRatioSeedCriteria.cc b/src/ShareRatioSeedCriteria.cc
index 9b60e0fc..fa1aac2c 100644
--- a/src/ShareRatioSeedCriteria.cc
+++ b/src/ShareRatioSeedCriteria.cc
@@ -51,7 +51,7 @@ void ShareRatioSeedCriteria::reset() {}
bool ShareRatioSeedCriteria::evaluate()
{
- uint64_t completedLength = pieceStorage_->getCompletedLength();
+ off_t completedLength = pieceStorage_->getCompletedLength();
if(completedLength == 0) {
return true;
}
diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc
index fb72da8a..5a1d5598 100644
--- a/src/SingleFileAllocationIterator.cc
+++ b/src/SingleFileAllocationIterator.cc
@@ -51,7 +51,7 @@ namespace aria2 {
SingleFileAllocationIterator::SingleFileAllocationIterator
(BinaryStream* stream,
off_t offset,
- uint64_t totalLength)
+ off_t totalLength)
: stream_(stream),
offset_(offset),
totalLength_(totalLength),
@@ -90,7 +90,7 @@ void SingleFileAllocationIterator::allocateChunk()
stream_->writeData(buffer_, BUFSIZE, offset_);
offset_ += BUFSIZE;
- if(totalLength_ < (uint64_t)offset_) {
+ if(totalLength_ < offset_) {
stream_->truncate(totalLength_);
offset_ = totalLength_;
}
@@ -98,7 +98,7 @@ void SingleFileAllocationIterator::allocateChunk()
bool SingleFileAllocationIterator::finished()
{
- return (uint64_t)offset_ == totalLength_;
+ return offset_ == totalLength_;
}
} // namespace aria2
diff --git a/src/SingleFileAllocationIterator.h b/src/SingleFileAllocationIterator.h
index a3d12602..b905aaea 100644
--- a/src/SingleFileAllocationIterator.h
+++ b/src/SingleFileAllocationIterator.h
@@ -48,11 +48,14 @@ private:
off_t offset_;
- uint64_t totalLength_;
+ off_t totalLength_;
unsigned char* buffer_;
public:
- SingleFileAllocationIterator(BinaryStream* stream, off_t offset, uint64_t totalLength);
+ SingleFileAllocationIterator
+ (BinaryStream* stream,
+ off_t offset,
+ off_t totalLength);
virtual ~SingleFileAllocationIterator();
@@ -65,7 +68,7 @@ public:
return offset_;
}
- virtual uint64_t getTotalLength()
+ virtual off_t getTotalLength()
{
return totalLength_;
}
diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc
index c792df9e..719a1cc3 100644
--- a/src/SpeedCalc.cc
+++ b/src/SpeedCalc.cc
@@ -79,7 +79,7 @@ unsigned int SpeedCalc::calculateSpeed() {
void SpeedCalc::update(size_t bytes) {
accumulatedLength_ += bytes;
std::transform(&lengthArray_[0], &lengthArray_[2], &lengthArray_[0],
- std::bind1st(std::plus<uint64_t>(), (uint64_t)bytes));
+ std::bind1st(std::plus<int64_t>(), (int64_t)bytes));
if(isIntervalOver()) {
changeSw();
}
@@ -103,7 +103,7 @@ void SpeedCalc::changeSw() {
}
unsigned int SpeedCalc::calculateAvgSpeed() const {
- uint64_t milliElapsed = start_.differenceInMillis(global::wallclock());
+ int64_t milliElapsed = start_.differenceInMillis(global::wallclock());
// if milliElapsed is too small, the average speed is rubish, better return 0
if(milliElapsed > 4) {
diff --git a/src/SpeedCalc.h b/src/SpeedCalc.h
index 716831b3..e2d5266c 100644
--- a/src/SpeedCalc.h
+++ b/src/SpeedCalc.h
@@ -42,13 +42,13 @@ namespace aria2 {
class SpeedCalc {
private:
- uint64_t lengthArray_[2];
+ int64_t lengthArray_[2];
int sw_;
Timer cpArray_[2];
unsigned int maxSpeed_;
unsigned int prevSpeed_;
Timer start_;
- uint64_t accumulatedLength_;
+ int64_t accumulatedLength_;
time_t nextInterval_;
bool isIntervalOver() const;
diff --git a/src/TransferStat.h b/src/TransferStat.h
index b8ffef46..c0c0febf 100644
--- a/src/TransferStat.h
+++ b/src/TransferStat.h
@@ -44,9 +44,9 @@ class TransferStat {
public:
unsigned int downloadSpeed;
unsigned int uploadSpeed;
- uint64_t sessionDownloadLength;
- uint64_t sessionUploadLength;
- uint64_t allTimeUploadLength;
+ int64_t sessionDownloadLength;
+ int64_t sessionUploadLength;
+ int64_t allTimeUploadLength;
void copy(const TransferStat& stat)
{
@@ -98,28 +98,28 @@ public:
* Returns the number of bytes downloaded since the program started.
* This is not the total number of bytes downloaded.
*/
- uint64_t getSessionDownloadLength() const {
+ int64_t getSessionDownloadLength() const {
return sessionDownloadLength;
}
- void setSessionDownloadLength(uint64_t s) { sessionDownloadLength = s; }
+ void setSessionDownloadLength(int64_t s) { sessionDownloadLength = s; }
/**
* Returns the number of bytes uploaded since the program started.
* This is not the total number of bytes uploaded.
*/
- uint64_t getSessionUploadLength() const {
+ int64_t getSessionUploadLength() const {
return sessionUploadLength;
}
- void setSessionUploadLength(uint64_t s) { sessionUploadLength = s; }
+ void setSessionUploadLength(int64_t s) { sessionUploadLength = s; }
- void setAllTimeUploadLength(uint64_t s)
+ void setAllTimeUploadLength(int64_t s)
{
allTimeUploadLength = s;
}
- uint64_t getAllTimeUploadLength() const
+ int64_t getAllTimeUploadLength() const
{
return allTimeUploadLength;
}
diff --git a/src/UnknownLengthPieceStorage.cc b/src/UnknownLengthPieceStorage.cc
index c0809dff..d87ddad3 100644
--- a/src/UnknownLengthPieceStorage.cc
+++ b/src/UnknownLengthPieceStorage.cc
@@ -238,7 +238,7 @@ void UnknownLengthPieceStorage::markAllPiecesDone()
downloadFinished_ = true;
}
-void UnknownLengthPieceStorage::markPiecesDone(uint64_t length)
+void UnknownLengthPieceStorage::markPiecesDone(off_t length)
{
// TODO not implemented yet
abort();
diff --git a/src/UnknownLengthPieceStorage.h b/src/UnknownLengthPieceStorage.h
index b6b340f6..39154f17 100644
--- a/src/UnknownLengthPieceStorage.h
+++ b/src/UnknownLengthPieceStorage.h
@@ -54,7 +54,7 @@ private:
SharedHandle<DiskWriterFactory> diskWriterFactory_;
- uint64_t totalLength_;
+ off_t totalLength_;
bool downloadFinished_;
@@ -152,23 +152,23 @@ public:
virtual bool isPieceUsed(size_t index);
- virtual uint64_t getTotalLength()
+ virtual off_t getTotalLength()
{
return totalLength_;
}
- virtual uint64_t getFilteredTotalLength()
+ virtual off_t getFilteredTotalLength()
{
return totalLength_;
}
- virtual uint64_t getCompletedLength()
+ virtual off_t getCompletedLength()
{
// TODO we have to return actual completed length here?
return totalLength_;
}
- virtual uint64_t getFilteredCompletedLength()
+ virtual off_t getFilteredCompletedLength()
{
return getCompletedLength();
}
@@ -259,7 +259,7 @@ public:
*/
virtual void markAllPiecesDone();
- virtual void markPiecesDone(uint64_t length);
+ virtual void markPiecesDone(off_t length);
virtual void markPieceMissing(size_t index);
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index fffbde80..1aa51d46 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -232,7 +232,7 @@ void extractFileEntries
const List* filesList = downcast<List>(infoDict->get(C_FILES));
if(filesList) {
fileEntries.reserve(filesList->size());
- uint64_t length = 0;
+ off_t length = 0;
off_t offset = 0;
// multi-file mode
torrent->mode = MULTI;
@@ -304,7 +304,7 @@ void extractFileEntries
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_LENGTH.c_str()),
error_code::BITTORRENT_PARSE_ERROR);
}
- uint64_t totalLength = lengthData->i();
+ off_t totalLength = lengthData->i();
// For each uri in urlList, if it ends with '/', then
// concatenate name to it. Specification just says so.
diff --git a/src/message_digest_helper.cc b/src/message_digest_helper.cc
index b0fa8d3d..26e26a23 100644
--- a/src/message_digest_helper.cc
+++ b/src/message_digest_helper.cc
@@ -66,7 +66,7 @@ void staticSHA1DigestFree()
}
std::string staticSHA1Digest
-(const BinaryStreamHandle& bs, off_t offset, uint64_t length)
+(const BinaryStreamHandle& bs, off_t offset, off_t length)
{
sha1Ctx_->reset();
return digest(sha1Ctx_, bs, offset, length);
@@ -75,14 +75,14 @@ std::string staticSHA1Digest
std::string digest
(const SharedHandle<MessageDigest>& ctx,
const SharedHandle<BinaryStream>& bs,
- off_t offset, uint64_t length)
+ off_t offset, off_t length)
{
size_t BUFSIZE = 4096;
unsigned char BUF[BUFSIZE];
lldiv_t res = lldiv(length, BUFSIZE);
- uint64_t iteration = res.quot;
+ int64_t iteration = res.quot;
size_t tail = res.rem;
- for(uint64_t i = 0; i < iteration; ++i) {
+ for(int64_t i = 0; i < iteration; ++i) {
ssize_t readLength = bs->readData(BUF, BUFSIZE, offset);
if((size_t)readLength != BUFSIZE) {
throw DL_ABORT_EX(fmt(EX_FILE_READ, "n/a", "data is too short"));
diff --git a/src/message_digest_helper.h b/src/message_digest_helper.h
index 4bf5d582..b6179d92 100644
--- a/src/message_digest_helper.h
+++ b/src/message_digest_helper.h
@@ -63,7 +63,7 @@ void staticSHA1DigestInit();
void staticSHA1DigestFree();
std::string staticSHA1Digest
-(const SharedHandle<BinaryStream>& bs, off_t offset, uint64_t length);
+(const SharedHandle<BinaryStream>& bs, off_t offset, off_t length);
/**
* ctx must be initialized or reseted before calling this function.
@@ -72,7 +72,7 @@ std::string staticSHA1Digest
std::string digest
(const SharedHandle<MessageDigest>& ctx,
const SharedHandle<BinaryStream>& bs,
- off_t offset, uint64_t length);
+ off_t offset, off_t length);
/**
* Stores *raw* message digest into md.
diff --git a/src/paramed_string.cc b/src/paramed_string.cc
index b2dc1406..bed6760c 100644
--- a/src/paramed_string.cc
+++ b/src/paramed_string.cc
@@ -38,7 +38,7 @@ namespace aria2 {
namespace paramed_string {
-std::string toBase26(uint32_t n, char zero, size_t width)
+std::string toBase26(int32_t n, char zero, size_t width)
{
std::string res;
if(n == 0 && width == 0) {
diff --git a/src/paramed_string.h b/src/paramed_string.h
index a2b617fe..b4b330f5 100644
--- a/src/paramed_string.h
+++ b/src/paramed_string.h
@@ -75,20 +75,20 @@ InputIterator expandChoice
}
template<typename InputIterator>
-uint32_t fromBase26(InputIterator first, InputIterator last, char zero)
+int32_t fromBase26(InputIterator first, InputIterator last, char zero)
{
- uint64_t res = 0;
+ int32_t res = 0;
for(; first != last; ++first) {
res *= 26;
res += *first-zero;
- if(res > UINT16_MAX) {
+ if(res > static_cast<int32_t>(UINT16_MAX)) {
throw DL_ABORT_EX("Loop range overflow.");
}
}
return res;
}
-std::string toBase26(uint32_t n, char zero, size_t width);
+std::string toBase26(int32_t n, char zero, size_t width);
template<typename InputIterator>
InputIterator expandLoop
@@ -147,7 +147,7 @@ InputIterator expandLoop
(util::isUppercase(first, minus) &&
util::isUppercase(minus+1, colon))) {
char zero = ('a' <= *first && *first <= 'z' ? 'a' : 'A');
- uint32_t start, end;
+ int32_t start, end;
start = fromBase26(first, minus, zero);
end = fromBase26(minus+1, colon, zero);
if(start <= end) {
@@ -161,7 +161,7 @@ InputIterator expandLoop
res2.reserve(res.size()*((end+1-start)/step));
for(std::vector<std::string>::const_iterator i = res.begin(),
eoi = res.end(); i != eoi; ++i) {
- for(uint32_t j = start; j <= end; j += step) {
+ for(int32_t j = start; j <= end; j += step) {
res2.push_back(*i);
res2.back() += toBase26(j, zero, width);
}
diff --git a/src/util.cc b/src/util.cc
index fabd9494..817cdc3d 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -645,32 +645,6 @@ int64_t parseLLInt(const std::string& s, int base)
}
}
-bool parseULLIntNoThrow(uint64_t& res, const std::string& s, int base)
-{
- long long int t;
- if(parseLong(t, strtoll, s, base) &&
- t >= 0 &&
- t <= std::numeric_limits<int64_t>::max()) {
- res = t;
- return true;
- } else {
- return false;
- }
-}
-
-uint64_t parseULLInt(const std::string& s, int base)
-{
- uint64_t res;
- if(parseULLIntNoThrow(res, s, base)) {
- return res;
- } else {
- throw DL_ABORT_EX
- (fmt("Failed to convert string into 64bit unsigned integer. '%s'",
- s.c_str()));
- }
-}
-
-
void parseIntSegments(SegList<int>& sgl, const std::string& src)
{
for(std::string::const_iterator i = src.begin(), eoi = src.end(); i != eoi;) {
@@ -702,7 +676,7 @@ void computeHeadPieces
(std::vector<size_t>& indexes,
const std::vector<SharedHandle<FileEntry> >& fileEntries,
size_t pieceLength,
- uint64_t head)
+ int64_t head)
{
if(head == 0) {
return;
@@ -727,7 +701,7 @@ void computeTailPieces
(std::vector<size_t>& indexes,
const std::vector<SharedHandle<FileEntry> >& fileEntries,
size_t pieceLength,
- uint64_t tail)
+ int64_t tail)
{
if(tail == 0) {
return;
@@ -737,7 +711,7 @@ void computeTailPieces
if((*fi)->getLength() == 0) {
continue;
}
- uint64_t endOffset = (*fi)->getLastOffset();
+ int64_t endOffset = (*fi)->getLastOffset();
size_t fromIndex =
(endOffset-1-(std::min(tail, (*fi)->getLength())-1))/pieceLength;
for(size_t index = fromIndex; index <= (endOffset-1)/pieceLength;
@@ -752,7 +726,7 @@ void parsePrioritizePieceRange
(std::vector<size_t>& result, const std::string& src,
const std::vector<SharedHandle<FileEntry> >& fileEntries,
size_t pieceLength,
- uint64_t defaultSize)
+ int64_t defaultSize)
{
std::vector<size_t> indexes;
std::vector<Scip> parts;
@@ -1181,7 +1155,7 @@ void convertBitfield(BitfieldMan* dest, const BitfieldMan* src)
{
size_t numBlock = dest->countBlock();
for(size_t index = 0; index < numBlock; ++index) {
- if(src->isBitSetOffsetRange((uint64_t)index*dest->getBlockLength(),
+ if(src->isBitSetOffsetRange((off_t)index*dest->getBlockLength(),
dest->getBlockLength())) {
dest->setBit(index);
}
diff --git a/src/util.h b/src/util.h
index 1c357cb3..33bd51b7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -274,10 +274,6 @@ uint32_t parseUInt(const std::string& s, int base = 10);
bool parseLLIntNoThrow(int64_t& res, const std::string& s, int base = 10);
int64_t parseLLInt(const std::string& s, int base = 10);
-// Valid range: [0, INT64_MAX]
-bool parseULLIntNoThrow(uint64_t& res, const std::string& s, int base = 10);
-uint64_t parseULLInt(const std::string& s, int base = 10);
-
void parseIntSegments(SegList<int>& sgl, const std::string& src);
// Parses string which specifies the range of piece index for higher
@@ -296,7 +292,7 @@ void parsePrioritizePieceRange
(std::vector<size_t>& result, const std::string& src,
const std::vector<SharedHandle<FileEntry> >& fileEntries,
size_t pieceLength,
- uint64_t defaultSize = 1048576 /* 1MiB */);
+ int64_t defaultSize = 1048576LL /* 1MiB */);
// Converts ISO/IEC 8859-1 string src to utf-8.
std::string iso8859ToUtf8(const std::string& src);