diff --git a/ChangeLog b/ChangeLog index 5e4866ad70..6cc38d5952 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-03-09 Tatsuhiro Tsujikawa + + type cleanup for allmost all remaining files. + 2008-03-08 Tatsuhiro Tsujikawa Type clarification diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 50245b02a6..9833ed1017 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -119,13 +119,13 @@ bool AbstractCommand::execute() { checkPoint.reset(); if(!_requestGroup->getPieceStorage().isNull()) { _segments = _requestGroup->getSegmentMan()->getInFlightSegment(cuid); - int32_t maxSegments; + size_t maxSegments; if(req->isKeepAlive() && e->option->get(PREF_ENABLE_HTTP_PIPELINING) == V_TRUE) { maxSegments = e->option->getAsInt(PREF_MAX_HTTP_PIPELINING); } else { maxSegments = 1; } - while((int32_t)_segments.size() < maxSegments) { + while(_segments.size() < maxSegments) { SegmentHandle segment = _requestGroup->getSegmentMan()->getSegment(cuid); if(segment.isNull()) { break; @@ -156,7 +156,7 @@ bool AbstractCommand::execute() { logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str()); req->addTryCount(); bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 && - req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRIES); + req->getTryCount() >= (unsigned int)e->option->getAsInt(PREF_MAX_TRIES); if(isAbort) { onAbort(err); } @@ -184,7 +184,7 @@ void AbstractCommand::tryReserved() { e->addCommand(commands); } -bool AbstractCommand::prepareForRetry(int32_t wait) { +bool AbstractCommand::prepareForRetry(time_t wait) { if(!_requestGroup->getPieceStorage().isNull()) { _requestGroup->getSegmentMan()->cancelSegment(cuid); } diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index a92555e171..4f15269927 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -53,7 +53,7 @@ class SocketCore; class AbstractCommand : public Command, public RequestGroupAware { private: Time checkPoint; - int32_t timeout; + time_t timeout; protected: SharedHandle req; DownloadEngine* e; @@ -61,7 +61,7 @@ class AbstractCommand : public Command, public RequestGroupAware { std::deque > _segments; void tryReserved(); - virtual bool prepareForRetry(int32_t wait); + virtual bool prepareForRetry(time_t wait); virtual void onAbort(Exception* ex); virtual bool executeInternal() = 0; @@ -76,7 +76,7 @@ class AbstractCommand : public Command, public RequestGroupAware { void disableNameResolverCheck(const SharedHandle& resolver); virtual bool nameResolveFinished() const; #endif // ENABLE_ASYNC_DNS - void setTimeout(int32_t timeout) { this->timeout = timeout; } + void setTimeout(time_t timeout) { this->timeout = timeout; } void prepareForNextAction(Command* nextCommand = 0); diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 3fd5498242..74b9fec0f5 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -54,7 +54,7 @@ AbstractDiskWriter::~AbstractDiskWriter() closeFile(); } -void AbstractDiskWriter::openFile(const std::string& filename, int64_t totalLength) +void AbstractDiskWriter::openFile(const std::string& filename, uint64_t totalLength) { File f(filename); if(f.exists()) { @@ -73,7 +73,7 @@ void AbstractDiskWriter::closeFile() } void AbstractDiskWriter::openExistingFile(const std::string& filename, - int64_t totalLength) + uint64_t totalLength) { this->filename = filename; File f(filename); @@ -86,7 +86,7 @@ void AbstractDiskWriter::openExistingFile(const std::string& filename, } } -void AbstractDiskWriter::createFile(const std::string& filename, int32_t addFlags) +void AbstractDiskWriter::createFile(const std::string& filename, int addFlags) { this->filename = filename; assert(filename.size()); @@ -96,11 +96,11 @@ void AbstractDiskWriter::createFile(const std::string& filename, int32_t addFlag } } -int32_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, int32_t len) +ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, size_t len) { - int32_t writtenLength = 0; - while(writtenLength < len) { - int32_t ret = 0; + ssize_t writtenLength = 0; + while((size_t)writtenLength < len) { + ssize_t ret = 0; while((ret = write(fd, data+writtenLength, len-writtenLength)) == -1 && errno == EINTR); if(ret == -1) { return -1; @@ -110,21 +110,21 @@ int32_t AbstractDiskWriter::writeDataInternal(const unsigned char* data, int32_t return writtenLength; } -int32_t AbstractDiskWriter::readDataInternal(unsigned char* data, int32_t len) +ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len) { - int32_t ret = 0; + ssize_t ret = 0; while((ret = read(fd, data, len)) == -1 && errno == EINTR); return ret; } -void AbstractDiskWriter::seek(int64_t offset) +void AbstractDiskWriter::seek(off_t offset) { if(offset != lseek(fd, offset, SEEK_SET)) { throw new DlAbortEx(EX_FILE_SEEK, filename.c_str(), strerror(errno)); } } -void AbstractDiskWriter::writeData(const unsigned char* data, int32_t len, int64_t offset) +void AbstractDiskWriter::writeData(const unsigned char* data, size_t len, off_t offset) { seek(offset); if(writeDataInternal(data, len) < 0) { @@ -132,9 +132,9 @@ void AbstractDiskWriter::writeData(const unsigned char* data, int32_t len, int64 } } -int32_t AbstractDiskWriter::readData(unsigned char* data, int32_t len, int64_t offset) +ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len, off_t offset) { - int32_t ret; + ssize_t ret; seek(offset); if((ret = readDataInternal(data, len)) < 0) { throw new DlAbortEx(EX_FILE_READ, filename.c_str(), strerror(errno)); @@ -142,7 +142,7 @@ int32_t AbstractDiskWriter::readData(unsigned char* data, int32_t len, int64_t o return ret; } -void AbstractDiskWriter::truncate(int64_t length) +void AbstractDiskWriter::truncate(uint64_t length) { if(fd == -1) { throw new DlAbortEx("File not opened."); @@ -151,7 +151,7 @@ void AbstractDiskWriter::truncate(int64_t length) } // TODO the file descriptor fd must be opened before calling this function. -int64_t AbstractDiskWriter::size() const +uint64_t AbstractDiskWriter::size() const { if(fd == -1) { throw new DlAbortEx("File not opened."); @@ -167,7 +167,7 @@ void AbstractDiskWriter::enableDirectIO() { #ifdef ENABLE_DIRECT_IO if(_directIOAllowed) { - int32_t flg; + int flg; while((flg = fcntl(fd, F_GETFL)) == -1 && errno == EINTR); while(fcntl(fd, F_SETFL, flg|O_DIRECT) == -1 && errno == EINTR); } @@ -177,7 +177,7 @@ void AbstractDiskWriter::enableDirectIO() void AbstractDiskWriter::disableDirectIO() { #ifdef ENABLE_DIRECT_IO - int32_t flg; + int flg; while((flg = fcntl(fd, F_GETFL)) == -1 && errno == EINTR); while(fcntl(fd, F_SETFL, flg&(~O_DIRECT)) == -1 && errno == EINTR); #endif // ENABLE_DIRECT_IO diff --git a/src/AbstractDiskWriter.h b/src/AbstractDiskWriter.h index 4d2b1b790a..9f7704cc85 100644 --- a/src/AbstractDiskWriter.h +++ b/src/AbstractDiskWriter.h @@ -45,34 +45,34 @@ class Logger; class AbstractDiskWriter : public DiskWriter { protected: std::string filename; - int32_t fd; + int fd; const Logger* logger; - void createFile(const std::string& filename, int32_t addFlags = 0); + void createFile(const std::string& filename, int addFlags = 0); private: - int32_t writeDataInternal(const unsigned char* data, int32_t len); - int32_t readDataInternal(unsigned char* data, int32_t len); + ssize_t writeDataInternal(const unsigned char* data, size_t len); + ssize_t readDataInternal(unsigned char* data, size_t len); - void seek(int64_t offset); + void seek(off_t offset); public: AbstractDiskWriter(); virtual ~AbstractDiskWriter(); - virtual void openFile(const std::string& filename, int64_t totalLength = 0); + virtual void openFile(const std::string& filename, uint64_t totalLength = 0); virtual void closeFile(); - virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0); + virtual void openExistingFile(const std::string& filename, uint64_t totalLength = 0); - virtual void writeData(const unsigned char* data, int32_t len, int64_t offset); + virtual void writeData(const unsigned char* data, size_t len, off_t offset); - virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset); + virtual ssize_t readData(unsigned char* data, size_t len, off_t offset); - virtual void truncate(int64_t length); + virtual void truncate(uint64_t length); - virtual int64_t size() const; + virtual uint64_t size() const; virtual void enableDirectIO(); diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index ca6343506d..0b21eac0c4 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -65,12 +65,12 @@ void AbstractSingleDiskAdaptor::openExistingFile() diskWriter->openExistingFile(getFilePath(), totalLength); } -void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, int32_t len, int64_t offset) +void AbstractSingleDiskAdaptor::writeData(const unsigned char* data, size_t len, off_t offset) { diskWriter->writeData(data, len, offset); } -int32_t AbstractSingleDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset) +ssize_t AbstractSingleDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset) { return diskWriter->readData(data, len, offset); } @@ -80,12 +80,12 @@ bool AbstractSingleDiskAdaptor::fileExists() return File(getFilePath()).exists(); } -int64_t AbstractSingleDiskAdaptor::size() const +uint64_t AbstractSingleDiskAdaptor::size() const { return diskWriter->size(); } -void AbstractSingleDiskAdaptor::truncate(int64_t length) +void AbstractSingleDiskAdaptor::truncate(uint64_t length) { diskWriter->truncate(length); } @@ -123,12 +123,12 @@ DiskWriterHandle AbstractSingleDiskAdaptor::getDiskWriter() const return diskWriter; } -void AbstractSingleDiskAdaptor::setTotalLength(const int64_t& totalLength) +void AbstractSingleDiskAdaptor::setTotalLength(const uint64_t& totalLength) { this->totalLength = totalLength; } -int64_t AbstractSingleDiskAdaptor::getTotalLength() const +uint64_t AbstractSingleDiskAdaptor::getTotalLength() const { return totalLength; } diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index 3772a6620b..ac3668b45b 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -45,7 +45,7 @@ class FileAllocationIterator; class AbstractSingleDiskAdaptor : public DiskAdaptor { protected: SharedHandle diskWriter; - int64_t totalLength; + uint64_t totalLength; public: AbstractSingleDiskAdaptor(); @@ -59,16 +59,16 @@ class AbstractSingleDiskAdaptor : public DiskAdaptor { virtual void openExistingFile(); - virtual void writeData(const unsigned char* data, int32_t len, - int64_t offset); + virtual void writeData(const unsigned char* data, size_t len, + off_t offset); - virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset); + virtual ssize_t readData(unsigned char* data, size_t len, off_t offset); virtual bool fileExists(); - virtual int64_t size() const; + virtual uint64_t size() const; - virtual void truncate(int64_t length); + virtual void truncate(uint64_t length); virtual SharedHandle fileAllocationIterator(); @@ -82,9 +82,9 @@ class AbstractSingleDiskAdaptor : public DiskAdaptor { SharedHandle getDiskWriter() const; - void setTotalLength(const int64_t& totalLength); + void setTotalLength(const uint64_t& totalLength); - int64_t getTotalLength() const; + uint64_t getTotalLength() const; }; } // namespace aria2 diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index f6049ba334..21bb9a6402 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -53,7 +53,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const BtContextHandle& btContext, - int32_t interval) + time_t interval) :Command(cuid), BtContextAwareCommand(btContext), RequestGroupAware(requestGroup), @@ -62,7 +62,7 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid, _thresholdSpeed(SLOW_SPEED_THRESHOLD), _numNewConnection(5) { - int32_t maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); + unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); if(maxDownloadSpeed > 0) { _thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed); } diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h index 7d78c3f2a5..cd8ad69462 100644 --- a/src/ActivePeerConnectionCommand.h +++ b/src/ActivePeerConnectionCommand.h @@ -50,17 +50,17 @@ class ActivePeerConnectionCommand : public Command, public RequestGroupAware { private: - int32_t interval; // UNIT: sec + time_t interval; // UNIT: sec DownloadEngine* e; Time checkPoint; - int32_t _thresholdSpeed; // UNIT: byte/sec - int32_t _numNewConnection; // the number of the connection to establish. + unsigned int _thresholdSpeed; // UNIT: byte/sec + size_t _numNewConnection; // the number of the connection to establish. public: ActivePeerConnectionCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const SharedHandle& btContext, - int32_t interval); + time_t interval); virtual ~ActivePeerConnectionCommand(); @@ -68,12 +68,12 @@ class ActivePeerConnectionCommand : public Command, void connectToPeer(const SharedHandle& peer); - void setThresholdSpeed(int32_t speed) + void setThresholdSpeed(unsigned int speed) { _thresholdSpeed = speed; } - void setNumNewConnection(int32_t numNewConnection) + void setNumNewConnection(size_t numNewConnection) { _numNewConnection = numNewConnection; } diff --git a/src/AlphaNumberDecorator.h b/src/AlphaNumberDecorator.h index ff71c66207..a533b9bc02 100644 --- a/src/AlphaNumberDecorator.h +++ b/src/AlphaNumberDecorator.h @@ -44,37 +44,34 @@ class AlphaNumberDecorator : public NumberDecorator { private: - int32_t _width; + size_t _width; std::string _zero; - std::string widen(const std::string& s, int32_t width) + std::string widen(const std::string& s, size_t width) { std::string t = s; - while(t.size() < (size_t)width) { + while(t.size() < width) { t.insert(0, _zero); } return t; } public: - AlphaNumberDecorator(int32_t width, bool uppercase = false): + AlphaNumberDecorator(size_t width, bool uppercase = false): _width(width), _zero(uppercase?"A":"a") {} virtual ~AlphaNumberDecorator() {} - virtual std::string decorate(int32_t number) + virtual std::string decorate(unsigned int number) { - if(number < 0) { - throw new DlAbortEx("The number must be greater than 0."); - } if(number == 0) { return widen(_zero, _width); } - int32_t base = 26; + int base = 26; std::string x; while(number > 0) { - int32_t r = number%base; + int r = number%base; char alpha = _zero[0]+r; x.insert(0, std::string(1, alpha)); number /= base; diff --git a/src/AnnounceList.cc b/src/AnnounceList.cc index 845f26e48b..fa984d03d1 100644 --- a/src/AnnounceList.cc +++ b/src/AnnounceList.cc @@ -187,11 +187,11 @@ class FindCompletedAllowedTier { } }; -int32_t AnnounceList::countStoppedAllowedTier() const { +size_t AnnounceList::countStoppedAllowedTier() const { return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier()); } -int32_t AnnounceList::countCompletedAllowedTier() const { +size_t AnnounceList::countCompletedAllowedTier() const { return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier()); } diff --git a/src/AnnounceList.h b/src/AnnounceList.h index 59011c571c..081d05bcbb 100644 --- a/src/AnnounceList.h +++ b/src/AnnounceList.h @@ -61,7 +61,7 @@ class AnnounceList { void reconfigure(const MetaEntry* announceListEntry); void reconfigure(const std::string& url); - int32_t countTier() const { + size_t countTier() const { return tiers.size(); } @@ -102,12 +102,12 @@ class AnnounceList { /** * Counts the number of tiers to which the "stopped" event can be sent. */ - int32_t countStoppedAllowedTier() const; + size_t countStoppedAllowedTier() const; /** * Counts the number of tiers to which the "completed" event can be sent. */ - int32_t countCompletedAllowedTier() const; + size_t countCompletedAllowedTier() const; /** * Moves current tier pointer to the tier to which the "stopped" event can diff --git a/src/AutoSaveCommand.cc b/src/AutoSaveCommand.cc index 703ed53109..e6c6d6220a 100644 --- a/src/AutoSaveCommand.cc +++ b/src/AutoSaveCommand.cc @@ -38,7 +38,7 @@ namespace aria2 { -AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval): +AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval): TimeBasedCommand(cuid, e, interval) {} AutoSaveCommand::~AutoSaveCommand() {} diff --git a/src/AutoSaveCommand.h b/src/AutoSaveCommand.h index 8ed07ba5b7..03c5d33ac9 100644 --- a/src/AutoSaveCommand.h +++ b/src/AutoSaveCommand.h @@ -42,7 +42,7 @@ namespace aria2 { class AutoSaveCommand : public TimeBasedCommand { public: - AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval); + AutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval); virtual ~AutoSaveCommand(); diff --git a/src/BencodeVisitor.cc b/src/BencodeVisitor.cc index f8fc044692..2371339971 100644 --- a/src/BencodeVisitor.cc +++ b/src/BencodeVisitor.cc @@ -68,7 +68,7 @@ void BencodeVisitor::visit(const Dictionary* d) _bencodedData += "d"; for(std::deque::const_iterator itr = d->getOrder().begin(); itr != d->getOrder().end(); ++itr) { - _bencodedData += Util::itos((int32_t)(*itr).size()); + _bencodedData += Util::uitos((*itr).size()); _bencodedData += ":"; _bencodedData += *itr; d->get(*itr)->accept(this); diff --git a/src/BinaryStream.h b/src/BinaryStream.h index 24b188d4fb..b0ba396a74 100644 --- a/src/BinaryStream.h +++ b/src/BinaryStream.h @@ -44,11 +44,11 @@ class BinaryStream { public: virtual ~BinaryStream() {} - virtual void writeData(const unsigned char* data, int32_t len, int64_t offset) = 0; + virtual void writeData(const unsigned char* data, size_t len, off_t offset) = 0; - virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset) = 0; + virtual ssize_t readData(unsigned char* data, size_t len, off_t offset) = 0; - virtual void truncate(int64_t length) = 0; + virtual void truncate(uint64_t length) = 0; virtual void enableDirectIO() = 0; diff --git a/src/BitfieldManFactory.cc b/src/BitfieldManFactory.cc index e4a30f6e79..74f990c4b2 100644 --- a/src/BitfieldManFactory.cc +++ b/src/BitfieldManFactory.cc @@ -53,7 +53,7 @@ BitfieldManFactory::BitfieldManFactory():randomizer(0) {} BitfieldManFactory::~BitfieldManFactory() {} BitfieldMan* -BitfieldManFactory::createBitfieldMan(int32_t blockLength, int64_t totalLength) +BitfieldManFactory::createBitfieldMan(size_t blockLength, uint64_t totalLength) { BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength); bitfieldMan->setRandomizer(randomizer); diff --git a/src/BitfieldManFactory.h b/src/BitfieldManFactory.h index c9a1217aa0..93a4b71261 100644 --- a/src/BitfieldManFactory.h +++ b/src/BitfieldManFactory.h @@ -55,7 +55,7 @@ class BitfieldManFactory { static SharedHandle getFactoryInstance(); - BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength); + BitfieldMan* createBitfieldMan(size_t blockLength, uint64_t totalLength); static void setDefaultRandomizer(const SharedHandle& randomizer); diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc index 7f3f29ebfb..dbceb8a75b 100644 --- a/src/BtAllowedFastMessage.cc +++ b/src/BtAllowedFastMessage.cc @@ -41,11 +41,11 @@ namespace aria2 { -BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, int32_t dataLength) { +BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 5) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "allowed fast", dataLength, 5); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "allowed fast", ID); } @@ -62,7 +62,7 @@ void BtAllowedFastMessage::doReceivedAction() { peer->addPeerAllowedIndex(index); } -int32_t BtAllowedFastMessage::MESSAGE_LENGTH = 9; +size_t BtAllowedFastMessage::MESSAGE_LENGTH = 9; const unsigned char* BtAllowedFastMessage::getMessage() { if(!msg) { @@ -79,7 +79,7 @@ const unsigned char* BtAllowedFastMessage::getMessage() { return msg; } -int32_t BtAllowedFastMessage::getMessageLength() { +size_t BtAllowedFastMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtAllowedFastMessage.h b/src/BtAllowedFastMessage.h index 90900a43d4..b435b5e81b 100644 --- a/src/BtAllowedFastMessage.h +++ b/src/BtAllowedFastMessage.h @@ -45,12 +45,12 @@ typedef SharedHandle BtAllowedFastMessageHandle; class BtAllowedFastMessage : public SimpleBtMessage { private: - int32_t index; + size_t index; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: - BtAllowedFastMessage(int32_t index = 0) + BtAllowedFastMessage(size_t index = 0) :SimpleBtMessage(), index(index), msg(0) {} @@ -59,22 +59,22 @@ class BtAllowedFastMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 17; + static const uint8_t ID = 17; - void setIndex(int32_t index) { + void setIndex(size_t index) { this->index = index; } - int32_t getIndex() const { return index; } + size_t getIndex() const { return index; } - static BtAllowedFastMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtAllowedFastMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/BtAllowedFastMessageValidator.h b/src/BtAllowedFastMessageValidator.h index 70083de8a7..a298ae1ff8 100644 --- a/src/BtAllowedFastMessageValidator.h +++ b/src/BtAllowedFastMessageValidator.h @@ -44,10 +44,10 @@ namespace aria2 { class BtAllowedFastMessageValidator : public BtMessageValidator { private: const BtAllowedFastMessage* message; - int32_t numPiece; + size_t numPiece; public: BtAllowedFastMessageValidator(const BtAllowedFastMessage* message, - int32_t numPiece): + size_t numPiece): message(message), numPiece(numPiece) {} diff --git a/src/BtBitfieldMessage.cc b/src/BtBitfieldMessage.cc index 19d2a4a9e4..b98c478100 100644 --- a/src/BtBitfieldMessage.cc +++ b/src/BtBitfieldMessage.cc @@ -42,7 +42,7 @@ namespace aria2 { -void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) { +void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, size_t bitfieldLength) { if(this->bitfield == bitfield) { return; } @@ -54,12 +54,12 @@ void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfi } BtBitfieldMessageHandle -BtBitfieldMessage::create(const unsigned char* data, int32_t dataLength) +BtBitfieldMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength <= 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "bitfield", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "bitfield", ID); } @@ -89,7 +89,7 @@ const unsigned char* BtBitfieldMessage::getMessage() { return msg; } -int32_t BtBitfieldMessage::getMessageLength() { +size_t BtBitfieldMessage::getMessageLength() { getMessage(); return msgLength; } diff --git a/src/BtBitfieldMessage.h b/src/BtBitfieldMessage.h index d9361b3899..0808d917bd 100644 --- a/src/BtBitfieldMessage.h +++ b/src/BtBitfieldMessage.h @@ -46,9 +46,9 @@ typedef SharedHandle BtBitfieldMessageHandle; class BtBitfieldMessage : public SimpleBtMessage { private: unsigned char* bitfield; - int32_t bitfieldLength; + size_t bitfieldLength; unsigned char* msg; - int32_t msgLength; + size_t msgLength; void init() { bitfield = 0; @@ -63,7 +63,7 @@ class BtBitfieldMessage : public SimpleBtMessage { } BtBitfieldMessage(const unsigned char* bitfield, - int32_t bitfieldLength):SimpleBtMessage() + size_t bitfieldLength):SimpleBtMessage() { init(); setBitfield(bitfield, bitfieldLength); @@ -74,23 +74,23 @@ class BtBitfieldMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 5; + static const uint8_t ID = 5; - void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength); + void setBitfield(const unsigned char* bitfield, size_t bitfieldLength); const unsigned char* getBitfield() const { return bitfield; } - int32_t getBitfieldLength() const { return bitfieldLength; } + size_t getBitfieldLength() const { return bitfieldLength; } - static BtBitfieldMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtBitfieldMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtBitfieldMessageValidator.h b/src/BtBitfieldMessageValidator.h index 15eb5c18b5..cd8058e1b2 100644 --- a/src/BtBitfieldMessageValidator.h +++ b/src/BtBitfieldMessageValidator.h @@ -43,10 +43,10 @@ namespace aria2 { class BtBitfieldMessageValidator : public BtMessageValidator { private: const BtBitfieldMessage* message; - int32_t numPiece; + size_t numPiece; public: BtBitfieldMessageValidator(const BtBitfieldMessage* message, - int32_t numPiece): + size_t numPiece): message(message), numPiece(numPiece) {} diff --git a/src/BtCancelMessage.cc b/src/BtCancelMessage.cc index 63d4a44abe..83540e0482 100644 --- a/src/BtCancelMessage.cc +++ b/src/BtCancelMessage.cc @@ -41,11 +41,11 @@ namespace aria2 { -BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, int32_t dataLength) { +BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 13) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "cancel", dataLength, 13); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "cancel", ID); } @@ -60,7 +60,7 @@ void BtCancelMessage::doReceivedAction() { dispatcher->doCancelSendingPieceAction(index, begin, length); } -int32_t BtCancelMessage::MESSAGE_LENGTH = 17; +size_t BtCancelMessage::MESSAGE_LENGTH = 17; const unsigned char* BtCancelMessage::getMessage() { if(!msg) { @@ -81,13 +81,13 @@ const unsigned char* BtCancelMessage::getMessage() { return msg; } -int32_t BtCancelMessage::getMessageLength() { +size_t BtCancelMessage::getMessageLength() { return MESSAGE_LENGTH; } std::string BtCancelMessage::toString() const { - return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+ - ", length="+Util::itos(length); + return "cancel index="+Util::uitos(index)+", begin="+Util::uitos(begin)+ + ", length="+Util::uitos(length); } } // namespace aria2 diff --git a/src/BtCancelMessage.h b/src/BtCancelMessage.h index babefe3eac..d6fd55698e 100644 --- a/src/BtCancelMessage.h +++ b/src/BtCancelMessage.h @@ -45,14 +45,14 @@ typedef SharedHandle BtCancelMessageHandle; class BtCancelMessage : public SimpleBtMessage { private: - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: - BtCancelMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0) + BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0) :SimpleBtMessage(), index(index), begin(begin), @@ -65,27 +65,27 @@ class BtCancelMessage : public SimpleBtMessage { static const int8_t ID = 8; - int32_t getIndex() const { return index; } + size_t getIndex() const { return index; } - void setIndex(int32_t index) { this->index = index; } + void setIndex(size_t index) { this->index = index; } - int32_t getBegin() const { return begin; } + uint32_t getBegin() const { return begin; } - void setBegin(int32_t begin) { this->begin = begin; } + void setBegin(uint32_t begin) { this->begin = begin; } - int32_t getLength() const { return length; } + size_t getLength() const { return length; } - void setLength(int32_t length) { this->length = length; } + void setLength(size_t length) { this->length = length; } - static BtCancelMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtCancelMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtCancelMessageValidator.h b/src/BtCancelMessageValidator.h index 23fa77b407..5f75f352fc 100644 --- a/src/BtCancelMessageValidator.h +++ b/src/BtCancelMessageValidator.h @@ -44,12 +44,12 @@ namespace aria2 { class BtCancelMessageValidator : public BtMessageValidator { private: const BtCancelMessage* message; - int32_t numPiece; - int32_t pieceLength; + size_t numPiece; + size_t pieceLength; public: BtCancelMessageValidator(const BtCancelMessage* message, - int32_t numPiece, - int32_t pieceLength): + size_t numPiece, + size_t pieceLength): message(message), numPiece(numPiece), pieceLength(pieceLength) {} diff --git a/src/BtCancelSendingPieceEvent.h b/src/BtCancelSendingPieceEvent.h index ced34bb67b..6574dd24df 100644 --- a/src/BtCancelSendingPieceEvent.h +++ b/src/BtCancelSendingPieceEvent.h @@ -41,36 +41,36 @@ namespace aria2 { class BtCancelSendingPieceEvent : public BtEvent { private: - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; public: - BtCancelSendingPieceEvent(int32_t index, int32_t begin, int32_t length): + BtCancelSendingPieceEvent(size_t index, uint32_t begin, size_t length): index(index), begin(begin), length(length) {} virtual ~BtCancelSendingPieceEvent() {} - void setIndex(int32_t index) { + void setIndex(size_t index) { this->index = index; } - int32_t getIndex() const { + size_t getIndex() const { return index; } - void setBegin(int32_t begin) { + void setBegin(uint32_t begin) { this->begin = begin; } - int32_t getBegin() const { + uint32_t getBegin() const { return begin; } - void setLength(int32_t length) { + void setLength(size_t length) { this->length = length; } - int32_t getLength() const { + size_t getLength() const { return length; } }; diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc index cac5a8b9c5..2432678734 100644 --- a/src/BtChokeMessage.cc +++ b/src/BtChokeMessage.cc @@ -42,11 +42,11 @@ namespace aria2 { -BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) { +BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "choke", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "choke", ID); } @@ -64,7 +64,7 @@ bool BtChokeMessage::sendPredicate() const { return !peer->amChoking(); } -int32_t BtChokeMessage::MESSAGE_LENGTH = 5; +size_t BtChokeMessage::MESSAGE_LENGTH = 5; const unsigned char* BtChokeMessage::getMessage() { if(!msg) { @@ -79,7 +79,7 @@ const unsigned char* BtChokeMessage::getMessage() { return msg; } -int32_t BtChokeMessage::getMessageLength() { +size_t BtChokeMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtChokeMessage.h b/src/BtChokeMessage.h index 35b5c98aad..dba5223feb 100644 --- a/src/BtChokeMessage.h +++ b/src/BtChokeMessage.h @@ -47,7 +47,7 @@ class BtChokeMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtChokeMessage():SimpleBtMessage(), msg(0) {} @@ -55,19 +55,19 @@ class BtChokeMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 0; + static const uint8_t ID = 0; - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; - static BtChokeMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtChokeMessageHandle create(const unsigned char* data, size_t dataLength); virtual bool sendPredicate() const; diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc index a53a3f062f..cef424fc86 100644 --- a/src/BtExtendedMessage.cc +++ b/src/BtExtendedMessage.cc @@ -80,7 +80,7 @@ const unsigned char* BtExtendedMessage::getMessage() { return _msg; } -int32_t BtExtendedMessage::getMessageLength() { +size_t BtExtendedMessage::getMessageLength() { getMessage(); return _msgLength; } @@ -102,7 +102,7 @@ BtExtendedMessage::create(const BtContextHandle& btContext, if(dataLength < 2) { throw new DlAbortEx(MSG_TOO_SMALL_PAYLOAD_SIZE, "extended", dataLength); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "extended", ID); } diff --git a/src/BtExtendedMessage.h b/src/BtExtendedMessage.h index 18ad3e28ac..b39db2834f 100644 --- a/src/BtExtendedMessage.h +++ b/src/BtExtendedMessage.h @@ -63,13 +63,13 @@ class BtExtendedMessage:public SimpleBtMessage const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual bool sendPredicate() const; diff --git a/src/BtHandshakeMessage.cc b/src/BtHandshakeMessage.cc index 279a925b1c..3250e4326e 100644 --- a/src/BtHandshakeMessage.cc +++ b/src/BtHandshakeMessage.cc @@ -70,7 +70,7 @@ void BtHandshakeMessage::init() { } SharedHandle -BtHandshakeMessage::create(const unsigned char* data, int32_t dataLength) +BtHandshakeMessage::create(const unsigned char* data, size_t dataLength) { SharedHandle message = new BtHandshakeMessage(); message->pstrlen = data[0]; @@ -93,7 +93,7 @@ const unsigned char* BtHandshakeMessage::getMessage() { return msg; } -int32_t BtHandshakeMessage::getMessageLength() { +size_t BtHandshakeMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtHandshakeMessage.h b/src/BtHandshakeMessage.h index f01d94070a..91447253b4 100644 --- a/src/BtHandshakeMessage.h +++ b/src/BtHandshakeMessage.h @@ -41,12 +41,12 @@ namespace aria2 { class BtHandshakeMessage : public SimpleBtMessage { public: - static const int32_t PSTR_LENGTH = 19; + static const size_t PSTR_LENGTH = 19; static const unsigned char* BT_PSTR; - static const int32_t RESERVED_LENGTH = 8; - static const int32_t MESSAGE_LENGTH = 68; + static const size_t RESERVED_LENGTH = 8; + static const size_t MESSAGE_LENGTH = 68; private: - int8_t pstrlen; + uint8_t pstrlen; unsigned char* pstr; unsigned char* reserved; unsigned char* infoHash; @@ -62,7 +62,7 @@ class BtHandshakeMessage : public SimpleBtMessage { BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId); static SharedHandle - create(const unsigned char* data, int32_t dataLength); + create(const unsigned char* data, size_t dataLength); virtual ~BtHandshakeMessage() { delete [] msg; @@ -72,15 +72,15 @@ class BtHandshakeMessage : public SimpleBtMessage { delete [] peerId; } - static const int8_t ID = INT8_MAX; + static const uint8_t ID = INT8_MAX; - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction() {}; virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; @@ -99,7 +99,7 @@ class BtHandshakeMessage : public SimpleBtMessage { } } - int8_t getPstrlen() const { + uint8_t getPstrlen() const { return pstrlen; } diff --git a/src/BtHaveAllMessage.cc b/src/BtHaveAllMessage.cc index 6933286b88..08dd33270d 100644 --- a/src/BtHaveAllMessage.cc +++ b/src/BtHaveAllMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, int32_t dataLength) { +BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have all", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have all", ID); } @@ -60,7 +60,7 @@ void BtHaveAllMessage::doReceivedAction() { peer->setAllBitfield(); } -int32_t BtHaveAllMessage::MESSAGE_LENGTH = 5; +size_t BtHaveAllMessage::MESSAGE_LENGTH = 5; const unsigned char* BtHaveAllMessage::getMessage() { if(!msg) { @@ -75,7 +75,7 @@ const unsigned char* BtHaveAllMessage::getMessage() { return msg; } -int32_t BtHaveAllMessage::getMessageLength() { +size_t BtHaveAllMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtHaveAllMessage.h b/src/BtHaveAllMessage.h index cfdcd9b7ff..7f9c08f722 100644 --- a/src/BtHaveAllMessage.h +++ b/src/BtHaveAllMessage.h @@ -47,7 +47,7 @@ class BtHaveAllMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtHaveAllMessage():msg(0) {} @@ -55,17 +55,17 @@ class BtHaveAllMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 14; + static const uint8_t ID = 14; - static BtHaveAllMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtHaveAllMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtHaveMessage.cc b/src/BtHaveMessage.cc index aeb9aab8c2..3720f4dc1f 100644 --- a/src/BtHaveMessage.cc +++ b/src/BtHaveMessage.cc @@ -41,11 +41,11 @@ namespace aria2 { -BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, int32_t dataLength) { +BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 5) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have", dataLength, 5); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have", ID); } @@ -58,7 +58,7 @@ void BtHaveMessage::doReceivedAction() { peer->updateBitfield(index, 1); } -int32_t BtHaveMessage::MESSAGE_LENGTH = 9; +size_t BtHaveMessage::MESSAGE_LENGTH = 9; const unsigned char* BtHaveMessage::getMessage() { if(!msg) { @@ -75,7 +75,7 @@ const unsigned char* BtHaveMessage::getMessage() { return msg; } -int32_t BtHaveMessage::getMessageLength() { +size_t BtHaveMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtHaveMessage.h b/src/BtHaveMessage.h index 493873d278..a8d2864581 100644 --- a/src/BtHaveMessage.h +++ b/src/BtHaveMessage.h @@ -45,33 +45,33 @@ typedef SharedHandle BtHaveMessageHandle; class BtHaveMessage : public SimpleBtMessage { private: - int32_t index; + size_t index; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: - BtHaveMessage(int32_t index = 0):index(index), msg(0) {} + BtHaveMessage(size_t index = 0):index(index), msg(0) {} virtual ~BtHaveMessage() { delete [] msg; } - static const int8_t ID = 4; + static const uint8_t ID = 4; - void setIndex(int32_t index) { + void setIndex(size_t index) { this->index = index; } - int32_t getIndex() const { return index; } + size_t getIndex() const { return index; } - static BtHaveMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtHaveMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtHaveMessageValidator.h b/src/BtHaveMessageValidator.h index 9eaf3a1fa7..1fed369c9b 100644 --- a/src/BtHaveMessageValidator.h +++ b/src/BtHaveMessageValidator.h @@ -44,10 +44,10 @@ namespace aria2 { class BtHaveMessageValidator : public BtMessageValidator { private: const BtHaveMessage* message; - int32_t numPiece; + size_t numPiece; public: BtHaveMessageValidator(const BtHaveMessage* message, - int32_t numPiece): + size_t numPiece): message(message), numPiece(numPiece) {} diff --git a/src/BtHaveNoneMessage.cc b/src/BtHaveNoneMessage.cc index ace41fd745..4404e2fb7d 100644 --- a/src/BtHaveNoneMessage.cc +++ b/src/BtHaveNoneMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, int32_t dataLength) { +BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "have none", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have none", ID); } @@ -59,7 +59,7 @@ void BtHaveNoneMessage::doReceivedAction() { } } -int32_t BtHaveNoneMessage::MESSAGE_LENGTH = 5; +size_t BtHaveNoneMessage::MESSAGE_LENGTH = 5; const unsigned char* BtHaveNoneMessage::getMessage() { if(!msg) { @@ -74,7 +74,7 @@ const unsigned char* BtHaveNoneMessage::getMessage() { return msg; } -int32_t BtHaveNoneMessage::getMessageLength() { +size_t BtHaveNoneMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtHaveNoneMessage.h b/src/BtHaveNoneMessage.h index b9f4cf346e..1df2367ae9 100644 --- a/src/BtHaveNoneMessage.h +++ b/src/BtHaveNoneMessage.h @@ -47,7 +47,7 @@ class BtHaveNoneMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtHaveNoneMessage():msg(0) {} @@ -55,17 +55,17 @@ class BtHaveNoneMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 15; + static const uint8_t ID = 15; - static BtHaveNoneMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtHaveNoneMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtInteractive.h b/src/BtInteractive.h index 35f45efd4b..938458dae0 100644 --- a/src/BtInteractive.h +++ b/src/BtInteractive.h @@ -60,7 +60,7 @@ class BtInteractive { virtual void sendPendingMessage() = 0; - virtual int32_t countPendingMessage() = 0; + virtual size_t countPendingMessage() = 0; virtual bool isSendingMessageInProgress() = 0; diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index f6f824a15c..f4292de5ef 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, int32_t dataLength) { +BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "interested", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "interested", ID); } @@ -60,7 +60,7 @@ bool BtInterestedMessage::sendPredicate() const { return !peer->amInterested(); } -int32_t BtInterestedMessage::MESSAGE_LENGTH = 5; +size_t BtInterestedMessage::MESSAGE_LENGTH = 5; const unsigned char* BtInterestedMessage::getMessage() { if(!msg) { @@ -75,7 +75,7 @@ const unsigned char* BtInterestedMessage::getMessage() { return msg; } -int32_t BtInterestedMessage::getMessageLength() { +size_t BtInterestedMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index b3a93dacd3..82e033140d 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -47,7 +47,7 @@ class BtInterestedMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtInterestedMessage():msg(0) {} @@ -55,17 +55,17 @@ class BtInterestedMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 2; + static const uint8_t ID = 2; - static BtInterestedMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtInterestedMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/BtKeepAliveMessage.cc b/src/BtKeepAliveMessage.cc index f7cb1908c4..f32c26c0c5 100644 --- a/src/BtKeepAliveMessage.cc +++ b/src/BtKeepAliveMessage.cc @@ -36,7 +36,7 @@ namespace aria2 { -int32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4; +size_t BtKeepAliveMessage::MESSAGE_LENGTH = 4; const unsigned char* BtKeepAliveMessage::getMessage() { if(!msg) { @@ -50,7 +50,7 @@ const unsigned char* BtKeepAliveMessage::getMessage() { return msg; } -int32_t BtKeepAliveMessage::getMessageLength() { +size_t BtKeepAliveMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtKeepAliveMessage.h b/src/BtKeepAliveMessage.h index 86948bb00d..2876bad2e5 100644 --- a/src/BtKeepAliveMessage.h +++ b/src/BtKeepAliveMessage.h @@ -47,7 +47,7 @@ class BtKeepAliveMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtKeepAliveMessage():msg(0) {} @@ -55,15 +55,15 @@ class BtKeepAliveMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 99; + static const uint8_t ID = 99; - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction() {} virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const { return "keep alive"; diff --git a/src/BtMessage.h b/src/BtMessage.h index 7802b2cf26..4303b8a154 100644 --- a/src/BtMessage.h +++ b/src/BtMessage.h @@ -54,7 +54,7 @@ class BtMessage { virtual bool isUploading() = 0; - virtual int8_t getId() = 0; + virtual uint8_t getId() = 0; virtual void doReceivedAction() = 0; diff --git a/src/BtMessageDispatcher.h b/src/BtMessageDispatcher.h index 8460aedcfc..b083bf9d2b 100644 --- a/src/BtMessageDispatcher.h +++ b/src/BtMessageDispatcher.h @@ -56,7 +56,7 @@ class BtMessageDispatcher { virtual void sendMessages() = 0; - virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) = 0; + virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) = 0; virtual void doCancelSendingPieceAction(const SharedHandle& piece) = 0; @@ -70,13 +70,13 @@ class BtMessageDispatcher { virtual bool isSendingInProgress() = 0; - virtual int32_t countMessageInQueue() = 0; + virtual size_t countMessageInQueue() = 0; - virtual int32_t countOutstandingRequest() = 0; + virtual size_t countOutstandingRequest() = 0; - virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex) = 0; + virtual bool isOutstandingRequest(size_t index, size_t blockIndex) = 0; - virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length) = 0; + virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length) = 0; virtual void removeOutstandingRequest(const RequestSlot& slot) = 0; diff --git a/src/BtMessageFactory.h b/src/BtMessageFactory.h index 6c1ab678f1..cd4715c277 100644 --- a/src/BtMessageFactory.h +++ b/src/BtMessageFactory.h @@ -49,25 +49,25 @@ class BtMessageFactory { virtual ~BtMessageFactory() {} virtual SharedHandle - createBtMessage(const unsigned char* msg, int32_t msgLength) = 0; + createBtMessage(const unsigned char* msg, size_t msgLength) = 0; virtual SharedHandle - createHandshakeMessage(const unsigned char* msg, int32_t msgLength) = 0; + createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0; virtual SharedHandle createHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId) = 0; virtual SharedHandle - createRequestMessage(const SharedHandle& piece, int32_t blockIndex) = 0; + createRequestMessage(const SharedHandle& piece, size_t blockIndex) = 0; virtual SharedHandle - createCancelMessage(int32_t index, int32_t begin, int32_t length) = 0; + createCancelMessage(size_t index, uint32_t begin, size_t length) = 0; virtual SharedHandle - createPieceMessage(int32_t index, int32_t begin, int32_t length) = 0; + createPieceMessage(size_t index, uint32_t begin, size_t length) = 0; - virtual SharedHandle createHaveMessage(int32_t index) = 0; + virtual SharedHandle createHaveMessage(size_t index) = 0; virtual SharedHandle createChokeMessage() = 0; @@ -86,9 +86,9 @@ class BtMessageFactory { virtual SharedHandle createHaveNoneMessage() = 0; virtual SharedHandle - createRejectMessage(int32_t index, int32_t begin, int32_t length) = 0; + createRejectMessage(size_t index, uint32_t begin, size_t length) = 0; - virtual SharedHandle createAllowedFastMessage(int32_t index) = 0; + virtual SharedHandle createAllowedFastMessage(size_t index) = 0; virtual SharedHandle createPortMessage(uint16_t port) = 0; diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index 47794312e6..1c79d1defe 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) { +BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "not interested", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "not interested", ID); } @@ -60,7 +60,7 @@ bool BtNotInterestedMessage::sendPredicate() const { return peer->amInterested(); } -int32_t BtNotInterestedMessage::MESSAGE_LENGTH = 5; +size_t BtNotInterestedMessage::MESSAGE_LENGTH = 5; const unsigned char* BtNotInterestedMessage::getMessage() { if(!msg) { @@ -75,7 +75,7 @@ const unsigned char* BtNotInterestedMessage::getMessage() { return msg; } -int32_t BtNotInterestedMessage::getMessageLength() { +size_t BtNotInterestedMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index f39fcdecec..993422f0b9 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -47,7 +47,7 @@ class BtNotInterestedMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtNotInterestedMessage():msg(0) {} @@ -55,17 +55,17 @@ class BtNotInterestedMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 3; + static const uint8_t ID = 3; - static BtNotInterestedMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtNotInterestedMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index 26755a997b..172ab34048 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -54,18 +54,18 @@ namespace aria2 { -void BtPieceMessage::setBlock(const unsigned char* block, int32_t blockLength) { +void BtPieceMessage::setBlock(const unsigned char* block, size_t blockLength) { delete [] this->block; this->blockLength = blockLength; this->block = new unsigned char[this->blockLength]; memcpy(this->block, block, this->blockLength); } -BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, int32_t dataLength) { +BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength <= 9) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "piece", dataLength, 9); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID); } @@ -85,16 +85,12 @@ void BtPieceMessage::doReceivedAction() { peer->snubbing(false); peer->updateLatency(slot.getLatencyInMillis()); PieceHandle piece = pieceStorage->getPiece(index); - int64_t offset = - ((int64_t)index)*btContext->getPieceLength()+begin; + off_t offset = (off_t)index*btContext->getPieceLength()+begin; logger->debug(MSG_PIECE_RECEIVED, cuid, index, begin, blockLength, offset, slot.getBlockIndex()); - pieceStorage->getDiskAdaptor()->writeData(block, - blockLength, - offset); + pieceStorage->getDiskAdaptor()->writeData(block, blockLength, offset); piece->completeBlock(slot.getBlockIndex()); - logger->debug(MSG_PIECE_BITFIELD, - cuid, + logger->debug(MSG_PIECE_BITFIELD, cuid, Util::toHex(piece->getBitfield(), piece->getBitfieldLength()).c_str()); dispatcher->removeOutstandingRequest(slot); @@ -108,7 +104,7 @@ void BtPieceMessage::doReceivedAction() { } } -int32_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13; +size_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13; const unsigned char* BtPieceMessage::getMessageHeader() { if(!msgHeader) { @@ -128,7 +124,7 @@ const unsigned char* BtPieceMessage::getMessageHeader() { return msgHeader; } -int32_t BtPieceMessage::getMessageHeaderLength() { +size_t BtPieceMessage::getMessageHeaderLength() { return MESSAGE_HEADER_LENGTH; } @@ -145,7 +141,7 @@ void BtPieceMessage::send() { leftDataLength = getMessageHeaderLength(); sendingInProgress = true; } - int32_t writtenLength + size_t writtenLength = peerConnection->sendMessage(msgHeader+getMessageHeaderLength()-leftDataLength, leftDataLength); if(writtenLength == leftDataLength) { @@ -157,10 +153,9 @@ void BtPieceMessage::send() { } if(headerSent) { sendingInProgress = false; - int64_t pieceDataOffset = - ((int64_t)index)*btContext->getPieceLength()+begin+blockLength-leftDataLength; - int32_t writtenLength = - sendPieceData(pieceDataOffset, leftDataLength); + off_t pieceDataOffset = + (off_t)index*btContext->getPieceLength()+begin+blockLength-leftDataLength; + size_t writtenLength = sendPieceData(pieceDataOffset, leftDataLength); peer->updateUploadLength(writtenLength); if(writtenLength < leftDataLength) { sendingInProgress = true; @@ -169,28 +164,26 @@ void BtPieceMessage::send() { } } -int32_t BtPieceMessage::sendPieceData(int64_t offset, int32_t length) const { - int32_t BUF_SIZE = 256; +size_t BtPieceMessage::sendPieceData(off_t offset, size_t length) const { + size_t BUF_SIZE = 256; unsigned char buf[BUF_SIZE]; - int32_t iteration = length/BUF_SIZE; - int32_t writtenLength = 0; - for(int32_t i = 0; i < iteration; i++) { - if(pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) { + div_t res = div(length, BUF_SIZE); + size_t writtenLength = 0; + for(int i = 0; i < res.quot; i++) { + if((size_t)pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) { throw new DlAbortEx(EX_DATA_READ); } - int32_t ws = peerConnection->sendMessage(buf, BUF_SIZE); + size_t ws = peerConnection->sendMessage(buf, BUF_SIZE); writtenLength += ws; if(ws != BUF_SIZE) { return writtenLength; } } - - int32_t rem = length%BUF_SIZE; - if(rem > 0) { - if(pieceStorage->getDiskAdaptor()->readData(buf, rem, offset+iteration*BUF_SIZE) < rem) { + if(res.rem > 0) { + if(pieceStorage->getDiskAdaptor()->readData(buf, res.rem, offset+res.quot*BUF_SIZE) < res.rem) { throw new DlAbortEx(EX_DATA_READ); } - int32_t ws = peerConnection->sendMessage(buf, rem); + size_t ws = peerConnection->sendMessage(buf, res.rem); writtenLength += ws; } return writtenLength; @@ -202,8 +195,7 @@ std::string BtPieceMessage::toString() const { } bool BtPieceMessage::checkPieceHash(const PieceHandle& piece) { - int64_t offset = - ((int64_t)piece->getIndex())*btContext->getPieceLength(); + off_t offset = (off_t)piece->getIndex()*btContext->getPieceLength(); return MessageDigestHelper::staticSHA1Digest(pieceStorage->getDiskAdaptor(), offset, piece->getLength()) == btContext->getPieceHash(piece->getIndex()); diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h index f6c0886419..9c377e29ab 100644 --- a/src/BtPieceMessage.h +++ b/src/BtPieceMessage.h @@ -48,15 +48,15 @@ typedef SharedHandle BtPieceMessageHandle; class BtPieceMessage : public AbstractBtMessage { private: - int32_t index; - int32_t begin; - int32_t blockLength; + size_t index; + uint32_t begin; + uint32_t blockLength; unsigned char* block; - int32_t leftDataLength; + size_t leftDataLength; bool headerSent; unsigned char* msgHeader; - static int32_t MESSAGE_HEADER_LENGTH; + static size_t MESSAGE_HEADER_LENGTH; bool checkPieceHash(const SharedHandle& piece); @@ -66,7 +66,7 @@ class BtPieceMessage : public AbstractBtMessage { void erasePieceOnDisk(const SharedHandle& piece); - int32_t sendPieceData(int64_t offset, int32_t length) const; + size_t sendPieceData(off_t offset, size_t length) const; class BtChokingEventListener : public AbstractBtEventListener { private: @@ -94,7 +94,7 @@ class BtPieceMessage : public AbstractBtMessage { typedef SharedHandle BtCancelSendingPieceEventListenerHandle; public: - BtPieceMessage(int32_t index = 0, int32_t begin = 0, int32_t blockLength = 0) + BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0) :index(index), begin(begin), blockLength(blockLength), @@ -113,33 +113,33 @@ class BtPieceMessage : public AbstractBtMessage { delete [] block; } - static const int8_t ID = 7; + static const uint8_t ID = 7; - int32_t getIndex() const { return index; } + size_t getIndex() const { return index; } - void setIndex(int32_t index) { this->index = index; } + void setIndex(size_t index) { this->index = index; } - int32_t getBegin() const { return begin; } + uint32_t getBegin() const { return begin; } - void setBegin(int32_t begin) { this->begin = begin; } + void setBegin(uint32_t begin) { this->begin = begin; } const unsigned char* getBlock() const { return block; } - void setBlock(const unsigned char* block, int32_t blockLength); + void setBlock(const unsigned char* block, size_t blockLength); - int32_t getBlockLength() const { return blockLength; } + size_t getBlockLength() const { return blockLength; } - void setBlockLength(int32_t blockLength) { this->blockLength = blockLength; } + void setBlockLength(size_t blockLength) { this->blockLength = blockLength; } - static BtPieceMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtPieceMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); const unsigned char* getMessageHeader(); - int32_t getMessageHeaderLength(); + size_t getMessageHeaderLength(); virtual void send(); diff --git a/src/BtPieceMessageValidator.h b/src/BtPieceMessageValidator.h index 91765a7d6a..c21c36f810 100644 --- a/src/BtPieceMessageValidator.h +++ b/src/BtPieceMessageValidator.h @@ -44,12 +44,12 @@ namespace aria2 { class BtPieceMessageValidator : public BtMessageValidator { private: const BtPieceMessage* message; - int32_t numPiece; - int32_t pieceLength; + size_t numPiece; + size_t pieceLength; public: BtPieceMessageValidator(const BtPieceMessage* message, - int32_t numPiece, - int32_t pieceLength): + size_t numPiece, + size_t pieceLength): message(message), numPiece(numPiece), pieceLength(pieceLength) {} diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc index 15a04ce975..c9ef72dc04 100644 --- a/src/BtPortMessage.cc +++ b/src/BtPortMessage.cc @@ -54,12 +54,12 @@ BtPortMessage::~BtPortMessage() delete [] _msg; } -SharedHandle BtPortMessage::create(const unsigned char* data, int32_t dataLength) +SharedHandle BtPortMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 3) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "port", dataLength, 3); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID); } @@ -105,7 +105,7 @@ const unsigned char* BtPortMessage::getMessage() { return _msg; } -int32_t BtPortMessage::getMessageLength() { +size_t BtPortMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtPortMessage.h b/src/BtPortMessage.h index 99ae4e6ff4..d8ad98e1c9 100644 --- a/src/BtPortMessage.h +++ b/src/BtPortMessage.h @@ -62,19 +62,19 @@ class BtPortMessage : public SimpleBtMessage { virtual ~BtPortMessage(); - static const int8_t ID = 9; + static const uint8_t ID = 9; uint16_t getPort() const { return _port; } - static SharedHandle create(const unsigned char* data, int32_t dataLength); + static SharedHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/BtRejectMessage.cc b/src/BtRejectMessage.cc index d9c74d9a20..e69d3c7369 100644 --- a/src/BtRejectMessage.cc +++ b/src/BtRejectMessage.cc @@ -43,11 +43,11 @@ namespace aria2 { -BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, int32_t dataLength) { +BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 13) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "reject", dataLength, 13); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "reject", ID); } @@ -74,7 +74,7 @@ void BtRejectMessage::doReceivedAction() { } -int32_t BtRejectMessage::MESSAGE_LENGTH = 17; +size_t BtRejectMessage::MESSAGE_LENGTH = 17; const unsigned char* BtRejectMessage::getMessage() { if(!msg) { @@ -95,13 +95,13 @@ const unsigned char* BtRejectMessage::getMessage() { return msg; } -int32_t BtRejectMessage::getMessageLength() { +size_t BtRejectMessage::getMessageLength() { return MESSAGE_LENGTH; } std::string BtRejectMessage::toString() const { - return "reject index="+Util::itos(index)+", begin="+Util::itos(begin)+ - ", length="+Util::itos(length); + return "reject index="+Util::uitos(index)+", begin="+Util::uitos(begin)+ + ", length="+Util::uitos(length); } } // namespace aria2 diff --git a/src/BtRejectMessage.h b/src/BtRejectMessage.h index d5b92f5d2e..df215fbf12 100644 --- a/src/BtRejectMessage.h +++ b/src/BtRejectMessage.h @@ -45,13 +45,13 @@ typedef SharedHandle BtRejectMessageHandle; class BtRejectMessage : public SimpleBtMessage { private: - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: - BtRejectMessage(int32_t index = 0, int32_t begin = 0, int32_t length = 0) + BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0) :index(index), begin(begin), length(length), @@ -61,26 +61,26 @@ class BtRejectMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 16; + static const uint8_t ID = 16; - int32_t getIndex() const { return index; } - void setIndex(int32_t index) { this->index = index; } + size_t getIndex() const { return index; } + void setIndex(size_t index) { this->index = index; } - int32_t getBegin() const { return begin; } - void setBegin(int32_t begin) { this->begin = begin; } + uint32_t getBegin() const { return begin; } + void setBegin(uint32_t begin) { this->begin = begin; } - int32_t getLength() const { return length; } - void setLength(int32_t length) { this->length = length; } + size_t getLength() const { return length; } + void setLength(size_t length) { this->length = length; } - static BtRejectMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtRejectMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtRejectMessageValidator.h b/src/BtRejectMessageValidator.h index 49350d1875..a0d5071c44 100644 --- a/src/BtRejectMessageValidator.h +++ b/src/BtRejectMessageValidator.h @@ -44,12 +44,12 @@ namespace aria2 { class BtRejectMessageValidator : public BtMessageValidator { private: const BtRejectMessage* message; - int32_t numPiece; - int32_t pieceLength; + size_t numPiece; + size_t pieceLength; public: BtRejectMessageValidator(const BtRejectMessage* message, - int32_t numPiece, - int32_t pieceLength): + size_t numPiece, + size_t pieceLength): message(message), numPiece(numPiece), pieceLength(pieceLength) {} diff --git a/src/BtRequestFactory.h b/src/BtRequestFactory.h index 89f5c3f302..6d8234193e 100644 --- a/src/BtRequestFactory.h +++ b/src/BtRequestFactory.h @@ -54,7 +54,7 @@ class BtRequestFactory { virtual void removeAllTargetPiece() = 0; - virtual int32_t countTargetPiece() = 0; + virtual size_t countTargetPiece() = 0; virtual void removeCompletedPiece() = 0; diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index e8b2d81042..37fedbc62c 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -47,11 +47,11 @@ namespace aria2 { -BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, int32_t dataLength) { +BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 13) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "request", dataLength, 13); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "request", ID); } @@ -80,7 +80,7 @@ void BtRequestMessage::doReceivedAction() { } } -int32_t BtRequestMessage::MESSAGE_LENGTH = 17; +size_t BtRequestMessage::MESSAGE_LENGTH = 17; const unsigned char* BtRequestMessage::getMessage() { if(!msg) { @@ -101,13 +101,13 @@ const unsigned char* BtRequestMessage::getMessage() { return msg; } -int32_t BtRequestMessage::getMessageLength() { +size_t BtRequestMessage::getMessageLength() { return MESSAGE_LENGTH; } std::string BtRequestMessage::toString() const { - return "request index="+Util::itos(index)+", begin="+Util::itos(begin)+ - ", length="+Util::itos(length); + return "request index="+Util::uitos(index)+", begin="+Util::uitos(begin)+ + ", length="+Util::uitos(length); } void BtRequestMessage::onQueued() { diff --git a/src/BtRequestMessage.h b/src/BtRequestMessage.h index 595a0d1f35..80c204890c 100644 --- a/src/BtRequestMessage.h +++ b/src/BtRequestMessage.h @@ -46,13 +46,13 @@ typedef SharedHandle BtRequestMessageHandle; class BtRequestMessage : public SimpleBtMessage { private: - int32_t index; - int32_t begin; - int32_t length; - int32_t blockIndex; + size_t index; + uint32_t begin; + uint32_t length; + size_t blockIndex; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; class BtAbortOutstandingRequestEventListener : public AbstractBtEventListener { private: @@ -67,10 +67,10 @@ class BtRequestMessage : public SimpleBtMessage { typedef SharedHandle BtAbortOutstandingRequestEventListenerHandle; public: - BtRequestMessage(int32_t index = 0, - int32_t begin = 0, - int32_t length = 0, - int32_t blockIndex = 0) + BtRequestMessage(size_t index = 0, + uint32_t begin = 0, + uint32_t length = 0, + size_t blockIndex = 0) :index(index), begin(begin), length(length), @@ -84,29 +84,29 @@ class BtRequestMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 6; + static const uint8_t ID = 6; - int32_t getIndex() const { return index; } - void setIndex(int32_t index) { this->index = index; } + size_t getIndex() const { return index; } + void setIndex(size_t index) { this->index = index; } - int32_t getBegin() const { return begin; } - void setBegin(int32_t begin) { this->begin = begin; } + uint32_t getBegin() const { return begin; } + void setBegin(uint32_t begin) { this->begin = begin; } - int32_t getLength() const { return length; } - void setLength(int32_t length) { this->length = length; } + uint32_t getLength() const { return length; } + void setLength(uint32_t length) { this->length = length; } - int32_t getBlockIndex() const { return blockIndex; } - void setBlockIndex(int32_t blockIndex) { this->blockIndex = blockIndex; } + size_t getBlockIndex() const { return blockIndex; } + void setBlockIndex(size_t blockIndex) { this->blockIndex = blockIndex; } - static BtRequestMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtRequestMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/BtRequestMessageValidator.h b/src/BtRequestMessageValidator.h index d2e6091a2b..f01b037ab7 100644 --- a/src/BtRequestMessageValidator.h +++ b/src/BtRequestMessageValidator.h @@ -44,12 +44,12 @@ namespace aria2 { class BtRequestMessageValidator : public BtMessageValidator { private: const BtRequestMessage* message; - int32_t numPiece; - int32_t pieceLength; + size_t numPiece; + size_t pieceLength; public: BtRequestMessageValidator(const BtRequestMessage* message, - int32_t numPiece, - int32_t pieceLength): + size_t numPiece, + size_t pieceLength): message(message), numPiece(numPiece), pieceLength(pieceLength) {} diff --git a/src/BtRuntime.h b/src/BtRuntime.h index 5dd44a41db..174557333f 100644 --- a/src/BtRuntime.h +++ b/src/BtRuntime.h @@ -44,10 +44,10 @@ namespace aria2 { class BtRuntime { private: - int64_t uploadLengthAtStartup; - int32_t port; + uint64_t uploadLengthAtStartup; + uint16_t port; bool halt; - int32_t connections; + unsigned int connections; bool _ready; public: BtRuntime(): @@ -60,19 +60,19 @@ class BtRuntime { ~BtRuntime() {} - int64_t getUploadLengthAtStartup() const { + uint64_t getUploadLengthAtStartup() const { return uploadLengthAtStartup; } - void setUploadLengthAtStartup(int64_t length) { + void setUploadLengthAtStartup(uint64_t length) { this->uploadLengthAtStartup = length; } - void setListenPort(int32_t port) { + void setListenPort(uint16_t port) { this->port = port; } - int32_t getListenPort() const { return port; } + uint16_t getListenPort() const { return port; } bool isHalt() const { return halt; } @@ -80,7 +80,7 @@ class BtRuntime { this->halt = halt; } - int32_t getConnections() const { return connections; } + unsigned int getConnections() const { return connections; } void increaseConnections() { connections++; } diff --git a/src/BtSuggestPieceMessage.cc b/src/BtSuggestPieceMessage.cc index 181f3c80e1..34762d4b60 100644 --- a/src/BtSuggestPieceMessage.cc +++ b/src/BtSuggestPieceMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, int32_t dataLength) { +BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 5) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "suggest piece", dataLength, 5); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "suggest piece", ID); } @@ -53,7 +53,7 @@ BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* d return message; } -int32_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9; +size_t BtSuggestPieceMessage::MESSAGE_LENGTH = 9; const unsigned char* BtSuggestPieceMessage::getMessage() { if(!msg) { @@ -70,7 +70,7 @@ const unsigned char* BtSuggestPieceMessage::getMessage() { return msg; } -int32_t BtSuggestPieceMessage::getMessageLength() { +size_t BtSuggestPieceMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtSuggestPieceMessage.h b/src/BtSuggestPieceMessage.h index 3eed578f54..f114b4289c 100644 --- a/src/BtSuggestPieceMessage.h +++ b/src/BtSuggestPieceMessage.h @@ -45,9 +45,9 @@ typedef SharedHandle BtSuggestPieceMessageHandle; class BtSuggestPieceMessage : public SimpleBtMessage { private: - int32_t index; + size_t index; unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtSuggestPieceMessage():index(0), msg(0) {} @@ -55,17 +55,17 @@ class BtSuggestPieceMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 13; + static const uint8_t ID = 13; - void setIndex(int32_t index) { + void setIndex(size_t index) { this->index = index; } - int32_t getIndex() const { return index; } + size_t getIndex() const { return index; } - static BtSuggestPieceMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtSuggestPieceMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction() { // TODO Current implementation ignores this message. @@ -73,7 +73,7 @@ class BtSuggestPieceMessage : public SimpleBtMessage { virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; }; diff --git a/src/BtSuggestPieceMessageValidator.h b/src/BtSuggestPieceMessageValidator.h index 2d710c6d41..dbfeea8713 100644 --- a/src/BtSuggestPieceMessageValidator.h +++ b/src/BtSuggestPieceMessageValidator.h @@ -44,10 +44,10 @@ namespace aria2 { class BtSuggestPieceMessageValidator : public BtMessageValidator { private: const BtSuggestPieceMessage* message; - int32_t numPiece; + size_t numPiece; public: BtSuggestPieceMessageValidator(const BtSuggestPieceMessage* message, - int32_t numPiece): + size_t numPiece): message(message), numPiece(numPiece) {} diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc index 18146fffe8..8b1b2b939c 100644 --- a/src/BtUnchokeMessage.cc +++ b/src/BtUnchokeMessage.cc @@ -40,11 +40,11 @@ namespace aria2 { -BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, int32_t dataLength) { +BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, size_t dataLength) { if(dataLength != 1) { throw new DlAbortEx(EX_INVALID_PAYLOAD_SIZE, "unchoke", dataLength, 1); } - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); if(id != ID) { throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "unchoke", ID); } @@ -60,7 +60,7 @@ bool BtUnchokeMessage::sendPredicate() const { return peer->amChoking(); } -int32_t BtUnchokeMessage::MESSAGE_LENGTH = 5; +size_t BtUnchokeMessage::MESSAGE_LENGTH = 5; const unsigned char* BtUnchokeMessage::getMessage() { if(!msg) { @@ -75,7 +75,7 @@ const unsigned char* BtUnchokeMessage::getMessage() { return msg; } -int32_t BtUnchokeMessage::getMessageLength() { +size_t BtUnchokeMessage::getMessageLength() { return MESSAGE_LENGTH; } diff --git a/src/BtUnchokeMessage.h b/src/BtUnchokeMessage.h index 10b8a70944..2bab378cb0 100644 --- a/src/BtUnchokeMessage.h +++ b/src/BtUnchokeMessage.h @@ -46,7 +46,7 @@ typedef SharedHandle BtUnchokeMessageHandle; class BtUnchokeMessage : public SimpleBtMessage { private: unsigned char* msg; - static int32_t MESSAGE_LENGTH; + static size_t MESSAGE_LENGTH; public: BtUnchokeMessage():msg(0) {} @@ -54,17 +54,17 @@ class BtUnchokeMessage : public SimpleBtMessage { delete [] msg; } - static const int8_t ID = 1; + static const uint8_t ID = 1; - static BtUnchokeMessageHandle create(const unsigned char* data, int32_t dataLength); + static BtUnchokeMessageHandle create(const unsigned char* data, size_t dataLength); - virtual int8_t getId() { return ID; } + virtual uint8_t getId() { return ID; } virtual void doReceivedAction(); virtual const unsigned char* getMessage(); - virtual int32_t getMessageLength(); + virtual size_t getMessageLength(); virtual std::string toString() const; diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc index 81dfe8eb33..ebb5bdfcfa 100644 --- a/src/ByteArrayDiskWriter.cc +++ b/src/ByteArrayDiskWriter.cc @@ -47,27 +47,27 @@ void ByteArrayDiskWriter::clear() } void ByteArrayDiskWriter::initAndOpenFile(const std::string& filename, - int64_t totalLength) + uint64_t totalLength) { clear(); } void ByteArrayDiskWriter::openFile(const std::string& filename, - int64_t totalLength) {} + uint64_t totalLength) {} void ByteArrayDiskWriter::closeFile() {} void ByteArrayDiskWriter::openExistingFile(const std::string& filename, - int64_t totalLength) + uint64_t totalLength) { openFile(filename); } -void ByteArrayDiskWriter::writeData(const unsigned char* data, int32_t dataLength, int64_t position) +void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position) { - if(size() < position) { + if(size() < (uint64_t)position) { buf.seekp(size(), std::ios::beg); - for(int64_t i = size(); i < position; ++i) { + for(uint64_t i = size(); i < (uint64_t)position; ++i) { buf.put('\0'); } } else { @@ -76,7 +76,7 @@ void ByteArrayDiskWriter::writeData(const unsigned char* data, int32_t dataLengt buf.write(reinterpret_cast(data), dataLength); } -int32_t ByteArrayDiskWriter::readData(unsigned char* data, int32_t len, int64_t position) +ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t position) { buf.seekg(position, std::ios::beg); buf.read(reinterpret_cast(data), len); diff --git a/src/ByteArrayDiskWriter.h b/src/ByteArrayDiskWriter.h index c5d24de5d3..313fd04e05 100644 --- a/src/ByteArrayDiskWriter.h +++ b/src/ByteArrayDiskWriter.h @@ -49,21 +49,21 @@ class ByteArrayDiskWriter : public DiskWriter { ByteArrayDiskWriter(); virtual ~ByteArrayDiskWriter(); - virtual void initAndOpenFile(const std::string& filename, int64_t totalLength = 0); + virtual void initAndOpenFile(const std::string& filename, uint64_t totalLength = 0); - virtual void openFile(const std::string& filename, int64_t totalLength = 0); + virtual void openFile(const std::string& filename, uint64_t totalLength = 0); virtual void closeFile(); - virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0); + virtual void openExistingFile(const std::string& filename, uint64_t totalLength = 0); - virtual void writeData(const unsigned char* data, int32_t len, int64_t position); - virtual int32_t readData(unsigned char* data, int32_t len, int64_t position); + 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); // Not implemented yet - virtual void truncate(int64_t length) {} + virtual void truncate(uint64_t length) {} - virtual int64_t size() const + virtual uint64_t size() const { return buf.str().size(); } diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index d2c8f1e9bf..3951a6c833 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -50,7 +50,7 @@ void CheckIntegrityEntry::validateChunk() _validator->validateChunk(); } -int64_t CheckIntegrityEntry::getTotalLength() +uint64_t CheckIntegrityEntry::getTotalLength() { if(_validator.isNull()) { return 0; @@ -59,7 +59,7 @@ int64_t CheckIntegrityEntry::getTotalLength() } } -int64_t CheckIntegrityEntry::getCurrentLength() +off_t CheckIntegrityEntry::getCurrentLength() { if(_validator.isNull()) { return 0; diff --git a/src/CheckIntegrityEntry.h b/src/CheckIntegrityEntry.h index 5aea086789..6305576872 100644 --- a/src/CheckIntegrityEntry.h +++ b/src/CheckIntegrityEntry.h @@ -53,9 +53,9 @@ class CheckIntegrityEntry : public RequestGroupEntry, virtual ~CheckIntegrityEntry(); - virtual int64_t getTotalLength(); + virtual uint64_t getTotalLength(); - virtual int64_t getCurrentLength(); + virtual off_t getCurrentLength(); virtual void validateChunk(); diff --git a/src/CheckIntegrityMan.cc b/src/CheckIntegrityMan.cc index 1c02d62324..3a5f8a1f33 100644 --- a/src/CheckIntegrityMan.cc +++ b/src/CheckIntegrityMan.cc @@ -68,7 +68,7 @@ CheckIntegrityEntryHandle CheckIntegrityMan::getFirstCheckIntegrityEntry() const } } -int32_t CheckIntegrityMan::countCheckIntegrityEntry() const +size_t CheckIntegrityMan::countCheckIntegrityEntry() const { return _checkIntegrityEntries.size(); } diff --git a/src/CheckIntegrityMan.h b/src/CheckIntegrityMan.h index 2d78a57d7c..d47a6aa1ad 100644 --- a/src/CheckIntegrityMan.h +++ b/src/CheckIntegrityMan.h @@ -57,7 +57,7 @@ class CheckIntegrityMan { SharedHandle getFirstCheckIntegrityEntry() const; - int32_t countCheckIntegrityEntry() const; + size_t countCheckIntegrityEntry() const; }; typedef SharedHandle CheckIntegrityManHandle; diff --git a/src/ChunkChecksum.h b/src/ChunkChecksum.h index f5c42a0fbd..ab10bf8b0b 100644 --- a/src/ChunkChecksum.h +++ b/src/ChunkChecksum.h @@ -46,40 +46,40 @@ class ChunkChecksum { private: std::string _algo; std::deque _checksums; - int32_t _checksumLength; + size_t _checksumLength; public: ChunkChecksum():_checksumLength(0) {} ChunkChecksum(const std::string& algo, const std::deque& checksums, - int32_t checksumLength): + size_t checksumLength): _algo(algo), _checksums(checksums), _checksumLength(checksumLength) {} bool validateChunk(const std::string& actualChecksum, - int32_t checksumIndex) const + size_t checksumIndex) const { - if(checksumIndex < (int32_t)_checksums.size()) { + if(checksumIndex < _checksums.size()) { return actualChecksum == getChecksum(checksumIndex); } else { return false; } } - int64_t getEstimatedDataLength() const + uint64_t getEstimatedDataLength() const { - return ((int64_t)_checksumLength)*_checksums.size(); + return ((uint64_t)_checksumLength)*_checksums.size(); } - int32_t countChecksum() const + size_t countChecksum() const { return _checksums.size(); } - std::string getChecksum(int32_t index) const + std::string getChecksum(size_t index) const { - if(index < (int32_t)_checksums.size()) { + if(index < _checksums.size()) { return _checksums[index]; } else { return ""; @@ -91,7 +91,7 @@ class ChunkChecksum { return _checksums; } - int32_t getChecksumLength() const + size_t getChecksumLength() const { return _checksumLength; } @@ -106,7 +106,7 @@ class ChunkChecksum { _algo = algo; } - void setChecksumLength(int32_t length) + void setChecksumLength(size_t length) { _checksumLength = length; } diff --git a/src/ChunkedEncoding.cc b/src/ChunkedEncoding.cc index 27b69c73af..015216b4d9 100644 --- a/src/ChunkedEncoding.cc +++ b/src/ChunkedEncoding.cc @@ -63,11 +63,11 @@ bool ChunkedEncoding::finished() { void ChunkedEncoding::end() {} -void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen, - const unsigned char* inbuf, int32_t inlen) { +void ChunkedEncoding::inflate(unsigned char* outbuf, size_t& outlen, + const unsigned char* inbuf, size_t inlen) { addBuffer(inbuf, inlen); unsigned char* p = strbuf; - int32_t clen = 0; + size_t clen = 0; while(1) { if(state == READ_SIZE) { if(readChunkSize(&p) == 0) { @@ -98,7 +98,7 @@ void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen, strbufTail = strbuf; } else { // copy string between [p, strbufTail] - int32_t unreadSize = strbufTail-p; + size_t unreadSize = strbufTail-p; unsigned char* temp = new unsigned char[strbufSize]; memcpy(temp, p, unreadSize); delete [] strbuf; @@ -108,9 +108,9 @@ void ChunkedEncoding::inflate(unsigned char* outbuf, int32_t& outlen, outlen = clen; } -int32_t ChunkedEncoding::readData(unsigned char** pp, - unsigned char* buf, int32_t& len, - int32_t maxlen) +int ChunkedEncoding::readData(unsigned char** pp, + unsigned char* buf, size_t& len, + size_t maxlen) { if(buf+len == buf+maxlen) { return -1; @@ -118,11 +118,11 @@ int32_t ChunkedEncoding::readData(unsigned char** pp, if(chunkSize == 0) { return readDataEOL(pp); } - int32_t wsize; - if(strbufTail-*pp < chunkSize) { - wsize = strbufTail-*pp <= maxlen-len ? strbufTail-*pp : maxlen-len; + size_t wsize; + if((size_t)(strbufTail-*pp) < chunkSize) { + wsize = std::min((size_t)(strbufTail-*pp), maxlen-len); } else { - wsize = chunkSize <= maxlen-len ? chunkSize : maxlen-len; + wsize = std::min(chunkSize, maxlen-len); } memcpy(buf+len, *pp, wsize); chunkSize -= wsize; @@ -135,7 +135,7 @@ int32_t ChunkedEncoding::readData(unsigned char** pp, } } -int32_t ChunkedEncoding::readDataEOL(unsigned char** pp) { +int ChunkedEncoding::readDataEOL(unsigned char** pp) { unsigned char* np = reinterpret_cast(memchr(*pp, '\n', strbufTail-*pp)); unsigned char* rp = reinterpret_cast(memchr(*pp, '\r', strbufTail-*pp)); if(np != NULL && rp != NULL && np-rp == 1 && *pp == rp) { @@ -148,7 +148,7 @@ int32_t ChunkedEncoding::readDataEOL(unsigned char** pp) { } } -int32_t ChunkedEncoding::readChunkSize(unsigned char** pp) { +int ChunkedEncoding::readChunkSize(unsigned char** pp) { // we read chunk-size from *pp unsigned char* p; unsigned char* np = reinterpret_cast(memchr(*pp, '\n', strbufTail-*pp)); @@ -172,8 +172,8 @@ int32_t ChunkedEncoding::readChunkSize(unsigned char** pp) { return 0; } -void ChunkedEncoding::addBuffer(const unsigned char* inbuf, int32_t inlen) { - int32_t realbufSize = strbufTail-strbuf; +void ChunkedEncoding::addBuffer(const unsigned char* inbuf, size_t inlen) { + size_t realbufSize = strbufTail-strbuf; if(realbufSize+inlen >= strbufSize) { if(realbufSize+inlen > MAX_BUFSIZE) { throw new DlAbortEx(EX_TOO_LARGE_CHUNK, realbufSize+inlen); diff --git a/src/ChunkedEncoding.h b/src/ChunkedEncoding.h index 816376add6..95df857aaf 100644 --- a/src/ChunkedEncoding.h +++ b/src/ChunkedEncoding.h @@ -46,21 +46,21 @@ class ChunkedEncoding:public TransferEncoding { READ_DATA, FINISH }; - int32_t chunkSize; - int32_t state; + size_t chunkSize; + STATE state; unsigned char* strbuf; - int32_t strbufSize; + size_t strbufSize; unsigned char* strbufTail; /** * Returns 0 if the size of chunk is retrieved successfully, * otherwise returns non-zero value. */ - int32_t readChunkSize(unsigned char** pp); - int32_t readData(unsigned char** pp, unsigned char* buf, int32_t& len, - int32_t maxlen); - void addBuffer(const unsigned char* inbuf, int32_t inlen); - int32_t readDataEOL(unsigned char** pp); + int readChunkSize(unsigned char** pp); + int readData(unsigned char** pp, unsigned char* buf, size_t& len, + size_t maxlen); + void addBuffer(const unsigned char* inbuf, size_t inlen); + int readDataEOL(unsigned char** pp); public: @@ -68,8 +68,8 @@ class ChunkedEncoding:public TransferEncoding { ~ChunkedEncoding(); void init(); - void inflate(unsigned char* outbuf, int32_t& outlen, - const unsigned char* inbuf, int32_t inlen); + void inflate(unsigned char* outbuf, size_t& outlen, + const unsigned char* inbuf, size_t inlen); bool finished(); void end(); }; diff --git a/src/CompactPeerListProcessor.cc b/src/CompactPeerListProcessor.cc index f6978f27cc..b9e10c6574 100644 --- a/src/CompactPeerListProcessor.cc +++ b/src/CompactPeerListProcessor.cc @@ -38,9 +38,7 @@ namespace aria2 { -CompactPeerListProcessor::CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength): - pieceLength(pieceLength), - totalLength(totalLength) {} +CompactPeerListProcessor::CompactPeerListProcessor() {} CompactPeerListProcessor::~CompactPeerListProcessor() {} @@ -55,7 +53,7 @@ Peers CompactPeerListProcessor::extractPeer(const MetaEntry* peersEntry) { return peers; } if(peersData->getLen()%6 == 0) { - for(int32_t i = 0; i < peersData->getLen(); i += 6) { + for(size_t i = 0; i < peersData->getLen(); i += 6) { struct in_addr in; in.s_addr = *(uint32_t*)(peersData->getData()+i); std::string ipaddr = inet_ntoa(in); diff --git a/src/CompactPeerListProcessor.h b/src/CompactPeerListProcessor.h index 80a6d770d5..faf92413df 100644 --- a/src/CompactPeerListProcessor.h +++ b/src/CompactPeerListProcessor.h @@ -39,11 +39,8 @@ namespace aria2 { class CompactPeerListProcessor : public PeerListProcessor { -private: - int32_t pieceLength; - int64_t totalLength; public: - CompactPeerListProcessor(int32_t pieceLength, int64_t totalLength); + CompactPeerListProcessor(); virtual ~CompactPeerListProcessor(); diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index b0a5ef8599..39a8c5b914 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -63,7 +63,7 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan, if(requestGroupMan->countRequestGroup() > 0) { RequestGroupHandle firstRequestGroup = requestGroupMan->getRequestGroup(0); TransferStat stat = firstRequestGroup->calculateStat(); - int32_t eta = 0; + unsigned int eta = 0; if(firstRequestGroup->getTotalLength() > 0 && stat.getDownloadSpeed() > 0) { eta = (firstRequestGroup->getTotalLength()-firstRequestGroup->getCompletedLength())/stat.getDownloadSpeed(); } diff --git a/src/CopyDiskAdaptor.cc b/src/CopyDiskAdaptor.cc index 1dcd394037..081be967cb 100644 --- a/src/CopyDiskAdaptor.cc +++ b/src/CopyDiskAdaptor.cc @@ -49,7 +49,7 @@ void CopyDiskAdaptor::onDownloadComplete() void CopyDiskAdaptor::fixFilename() { - int64_t offset = 0; + off_t offset = 0; for(FileEntries::iterator itr = fileEntries.begin(); itr != fileEntries.end(); itr++) { if(!(*itr)->isExtracted() && (*itr)->isRequested()) { diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index 940f719733..e6fe864135 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -51,7 +51,7 @@ namespace aria2 { -DHTAutoSaveCommand::DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval): +DHTAutoSaveCommand::DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval): TimeBasedCommand(cuid, e, interval), _localNode(0), _routingTable(0) {} diff --git a/src/DHTAutoSaveCommand.h b/src/DHTAutoSaveCommand.h index 99fd715590..66b161b0dc 100644 --- a/src/DHTAutoSaveCommand.h +++ b/src/DHTAutoSaveCommand.h @@ -52,7 +52,7 @@ class DHTAutoSaveCommand : public TimeBasedCommand void save(); public: - DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval); + DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval); virtual ~DHTAutoSaveCommand(); diff --git a/src/DHTConnectionImpl.cc b/src/DHTConnectionImpl.cc index d98ede599b..ece6e2ae61 100644 --- a/src/DHTConnectionImpl.cc +++ b/src/DHTConnectionImpl.cc @@ -62,7 +62,7 @@ uint16_t DHTConnectionImpl::bind(uint16_t port) { try { _socket->bind(port); - std::pair svaddr; + std::pair svaddr; _socket->getAddrInfo(svaddr); _logger->info("Bind socket for DHT. port=%u", port); return svaddr.second; diff --git a/src/DHTNode.cc b/src/DHTNode.cc index 294360e817..ee5a6af3e9 100644 --- a/src/DHTNode.cc +++ b/src/DHTNode.cc @@ -113,7 +113,7 @@ std::string DHTNode::toString() const return "DHTNode ID="+Util::toHex(_id, DHT_ID_LENGTH)+ ", Host="+_ipaddr+":"+Util::uitos(_port)+ ", Condition="+Util::uitos(_condition)+ - ", RTT="+Util::itos(_rtt); + ", RTT="+Util::uitos(_rtt); } } // namespace aria2 diff --git a/src/DHTNode.h b/src/DHTNode.h index 0d52a25da2..dcdc4c6855 100644 --- a/src/DHTNode.h +++ b/src/DHTNode.h @@ -52,9 +52,9 @@ class DHTNode { uint16_t _port; // in milli sec - int32_t _rtt; + unsigned int _rtt; - uint32_t _condition; + unsigned int _condition; Time _lastContact; public: @@ -72,7 +72,7 @@ class DHTNode { return _id; } - void updateRTT(int32_t millisec) + void updateRTT(unsigned int millisec) { _rtt = millisec; } diff --git a/src/Data.cc b/src/Data.cc index 45cacc360b..d0bef9d598 100644 --- a/src/Data.cc +++ b/src/Data.cc @@ -38,12 +38,12 @@ namespace aria2 { -Data::Data(const unsigned char* data, int32_t len, bool number):number(number) +Data::Data(const unsigned char* data, size_t len, bool number):number(number) { init(data, len); } -Data::Data(const char* data, int32_t len, bool number):number(number) { +Data::Data(const char* data, size_t len, bool number):number(number) { init(reinterpret_cast(data), len); } @@ -52,7 +52,7 @@ Data::Data(const std::string& data, bool number):number(number) init(reinterpret_cast(data.c_str()), data.size()); } -void Data::init(const unsigned char* src, int32_t slen) +void Data::init(const unsigned char* src, size_t slen) { if(src) { data = new unsigned char[slen]; @@ -80,7 +80,7 @@ const unsigned char* Data::getData() const { } } -int32_t Data::getLen() const { +size_t Data::getLen() const { return len; } diff --git a/src/Data.h b/src/Data.h index 3d34a7bb30..c9af888082 100644 --- a/src/Data.h +++ b/src/Data.h @@ -42,19 +42,19 @@ namespace aria2 { class Data : public MetaEntry { private: - int32_t len; + size_t len; unsigned char* data; bool number; - void init(const unsigned char* data, int32_t len); + void init(const unsigned char* data, size_t len); public: /** * This class stores the copy of data. So caller must take care of freeing * memory of data. */ - Data(const char* data, int32_t len, bool number = false); + Data(const char* data, size_t len, bool number = false); - Data(const unsigned char* data, int32_t len, bool number = false); + Data(const unsigned char* data, size_t len, bool number = false); Data(const std::string& data, bool number = false); @@ -65,7 +65,7 @@ class Data : public MetaEntry { int64_t toLLInt() const; const unsigned char* getData() const; - int32_t getLen() const; + size_t getLen() const; bool isNumber() const; void accept(MetaEntryVisitor* v) const; diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index ed8d2d951b..f1cacb8712 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -129,13 +129,12 @@ std::string DefaultBtAnnounce::getAnnounceUrl() { } else { return ""; } - int32_t numWant = 50; - if(!btRuntime->lessThanEqMinPeer() || - btRuntime->isHalt()) { + unsigned int numWant = 50; + if(!btRuntime->lessThanEqMinPeer() || btRuntime->isHalt()) { numWant = 0; } TransferStat stat = peerStorage->calculateStat(); - int64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength(); + uint64_t left = pieceStorage->getTotalLength()-pieceStorage->getCompletedLength(); if(left < 0) { left = 0; } @@ -143,15 +142,15 @@ std::string DefaultBtAnnounce::getAnnounceUrl() { "info_hash="+Util::torrentUrlencode(btContext->getInfoHash(), btContext->getInfoHashLength())+"&"+ "peer_id="+Util::torrentUrlencode(btContext->getPeerId(), 20)+"&"+ - "uploaded="+Util::itos(stat.getSessionUploadLength())+"&"+ - "downloaded="+Util::itos(stat.getSessionDownloadLength())+"&"+ - "left="+Util::itos(left)+"&"+ + "uploaded="+Util::uitos(stat.getSessionUploadLength())+"&"+ + "downloaded="+Util::uitos(stat.getSessionDownloadLength())+"&"+ + "left="+Util::uitos(left)+"&"+ "compact=1"+"&"+ "key="+key+"&"+ - "numwant="+Util::itos(numWant)+"&"+ + "numwant="+Util::uitos(numWant)+"&"+ "no_peer_id=1"; if(btRuntime->getListenPort() > 0) { - url += std::string("&")+"port="+Util::itos(btRuntime->getListenPort()); + url += std::string("&")+"port="+Util::uitos(btRuntime->getListenPort()); } std::string event = announceList.getEventString(); if(!event.empty()) { @@ -218,7 +217,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, } const Data* intervalData = dynamic_cast(response->get("interval")); if(intervalData) { - int32_t t = intervalData->toInt(); + time_t t = intervalData->toInt(); if(t > 0) { interval = intervalData->toInt(); logger->debug("Interval:%d", interval); @@ -226,7 +225,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, } const Data* minIntervalData = dynamic_cast(response->get("min interval")); if(minIntervalData) { - int32_t t = minIntervalData->toInt(); + time_t t = minIntervalData->toInt(); if(t > 0) { minInterval = minIntervalData->toInt(); logger->debug("Min interval:%d", minInterval); @@ -249,8 +248,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, if(peersEntry && !btRuntime->isHalt() && btRuntime->lessThanMinPeer()) { - DelegatingPeerListProcessor proc(btContext->getPieceLength(), - btContext->getTotalLength()); + DelegatingPeerListProcessor proc; Peers peers = proc.extractPeer(peersEntry); peerStorage->addPeer(peers); } diff --git a/src/DefaultBtAnnounce.h b/src/DefaultBtAnnounce.h index 0c0818c301..488e041ebb 100644 --- a/src/DefaultBtAnnounce.h +++ b/src/DefaultBtAnnounce.h @@ -54,12 +54,12 @@ class Randomizer; class DefaultBtAnnounce : public BtAnnounce { private: SharedHandle btContext; - int32_t trackers; + unsigned int trackers; Time prevAnnounceTime; - int32_t interval; - int32_t minInterval; - int32_t complete; - int32_t incomplete; + time_t interval; + time_t minInterval; + unsigned int complete; + unsigned int incomplete; AnnounceList announceList; std::string trackerId; std::string key; @@ -118,22 +118,22 @@ class DefaultBtAnnounce : public BtAnnounce { void setRandomizer(const SharedHandle& randomizer); - int32_t getInterval() const + time_t getInterval() const { return interval; } - int32_t getMinInterval() const + time_t getMinInterval() const { return minInterval; } - int32_t getComplete() const + unsigned int getComplete() const { return complete; } - int32_t getIncomplete() const + unsigned int getIncomplete() const { return incomplete; } diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index 8ef2c62f51..9d134f2272 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -101,8 +101,8 @@ void DefaultBtContext::clear() { void DefaultBtContext::extractPieceHash(const unsigned char* hashData, size_t hashDataLength, size_t hashLength) { - int32_t numPieces = hashDataLength/hashLength; - for(int32_t i = 0; i < numPieces; i++) { + size_t numPieces = hashDataLength/hashLength; + for(size_t i = 0; i < numPieces; i++) { pieceHashes.push_back(Util::toHex(&hashData[i*hashLength], hashLength)); } diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index 99767a0a4d..a86993cd4b 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -281,7 +281,7 @@ void DefaultBtInteractive::decideInterest() { } } -void DefaultBtInteractive::fillPiece(int maxPieceNum) { +void DefaultBtInteractive::fillPiece(size_t maxPieceNum) { if(pieceStorage->hasMissingPiece(peer)) { if(peer->peerChoking()) { if(peer->isFastExtensionEnabled()) { @@ -308,7 +308,7 @@ void DefaultBtInteractive::fillPiece(int maxPieceNum) { } void DefaultBtInteractive::addRequests() { - int32_t MAX_PENDING_REQUEST; + size_t MAX_PENDING_REQUEST; if(peer->getLatency() < 500) { MAX_PENDING_REQUEST = 24; } else if(peer->getLatency() < 1500) { @@ -316,16 +316,16 @@ void DefaultBtInteractive::addRequests() { } else { MAX_PENDING_REQUEST = 6; } - int32_t pieceNum; + size_t pieceNum; if(pieceStorage->isEndGame()) { pieceNum = 1; } else { - int32_t blocks = DIV_FLOOR(btContext->getPieceLength(), Piece::BLOCK_LENGTH); + size_t blocks = DIV_FLOOR(btContext->getPieceLength(), Piece::BLOCK_LENGTH); pieceNum = DIV_FLOOR(MAX_PENDING_REQUEST, blocks); } fillPiece(pieceNum); - int32_t reqNumToCreate = + size_t reqNumToCreate = MAX_PENDING_REQUEST <= dispatcher->countOutstandingRequest() ? 0 : MAX_PENDING_REQUEST-dispatcher->countOutstandingRequest(); if(reqNumToCreate > 0) { @@ -453,7 +453,7 @@ void DefaultBtInteractive::setLocalNode(const WeakHandle& node) _localNode = node; } -int32_t DefaultBtInteractive::countPendingMessage() +size_t DefaultBtInteractive::countPendingMessage() { return dispatcher->countMessageInQueue(); } diff --git a/src/DefaultBtInteractive.h b/src/DefaultBtInteractive.h index 322445cea4..625fbaa29f 100644 --- a/src/DefaultBtInteractive.h +++ b/src/DefaultBtInteractive.h @@ -38,6 +38,7 @@ #include "BtInteractive.h" #include "BtContextAwareCommand.h" #include "TimeA2.h" +#include namespace aria2 { @@ -53,28 +54,28 @@ class Logger; class FloodingStat { private: - int32_t chokeUnchokeCount; - int32_t keepAliveCount; + unsigned int chokeUnchokeCount; + unsigned int keepAliveCount; public: FloodingStat():chokeUnchokeCount(0), keepAliveCount(0) {} void incChokeUnchokeCount() { - if(chokeUnchokeCount < INT32_MAX) { + if(chokeUnchokeCount < UINT_MAX) { chokeUnchokeCount++; } } void incKeepAliveCount() { - if(keepAliveCount < INT32_MAX) { + if(keepAliveCount < UINT_MAX) { keepAliveCount++; } } - int32_t getChokeUnchokeCount() const { + unsigned int getChokeUnchokeCount() const { return chokeUnchokeCount; } - int32_t getKeepAliveCount() const { + unsigned int getKeepAliveCount() const { return keepAliveCount; } @@ -98,21 +99,21 @@ class DefaultBtInteractive : public BtInteractive, public BtContextAwareCommand WeakHandle _localNode; const Logger* logger; - int32_t allowedFastSetSize; + size_t allowedFastSetSize; Time haveCheckPoint; Time keepAliveCheckPoint; Time floodingCheckPoint; FloodingStat floodingStat; Time inactiveCheckPoint; Time _pexCheckPoint; - int32_t keepAliveInterval; - int32_t maxDownloadSpeedLimit; + time_t keepAliveInterval; + unsigned int maxDownloadSpeedLimit; bool _utPexEnabled; bool _dhtEnabled; size_t _numReceivedMessage; - static const int32_t FLOODING_CHECK_INTERVAL = 5; + static const time_t FLOODING_CHECK_INTERVAL = 5; void addBitfieldMessageToQueue(); void addAllowedFastMessageToQueue(); @@ -121,7 +122,7 @@ class DefaultBtInteractive : public BtInteractive, public BtContextAwareCommand void checkHave(); void sendKeepAlive(); void decideInterest(); - void fillPiece(int maxPieceNum); + void fillPiece(size_t maxPieceNum); void addRequests(); void detectMessageFlooding(); void checkActiveInteraction(); @@ -150,7 +151,7 @@ class DefaultBtInteractive : public BtInteractive, public BtContextAwareCommand size_t receiveMessages(); - virtual int32_t countPendingMessage(); + virtual size_t countPendingMessage(); virtual bool isSendingMessageInProgress(); @@ -174,11 +175,11 @@ class DefaultBtInteractive : public BtInteractive, public BtContextAwareCommand void setBtMessageFactory(const WeakHandle& factory); - void setKeepAliveInterval(int32_t keepAliveInterval) { + void setKeepAliveInterval(time_t keepAliveInterval) { this->keepAliveInterval = keepAliveInterval; } - void setMaxDownloadSpeedLimit(int32_t maxDownloadSpeedLimit) { + void setMaxDownloadSpeedLimit(unsigned int maxDownloadSpeedLimit) { this->maxDownloadSpeedLimit = maxDownloadSpeedLimit; } diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc index 8f5a0b5fd3..0230dca1e1 100644 --- a/src/DefaultBtMessageDispatcher.cc +++ b/src/DefaultBtMessageDispatcher.cc @@ -105,7 +105,7 @@ void DefaultBtMessageDispatcher::sendMessages() { } // Cancel sending piece message to peer. -void DefaultBtMessageDispatcher::doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) +void DefaultBtMessageDispatcher::doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) { BtCancelSendingPieceEventHandle event = new BtCancelSendingPieceEvent(index, begin, length); @@ -222,12 +222,12 @@ bool DefaultBtMessageDispatcher::isSendingInProgress() } } -int32_t DefaultBtMessageDispatcher::countOutstandingRequest() +size_t DefaultBtMessageDispatcher::countOutstandingRequest() { return requestSlots.size(); } -bool DefaultBtMessageDispatcher::isOutstandingRequest(int32_t index, int32_t blockIndex) { +bool DefaultBtMessageDispatcher::isOutstandingRequest(size_t index, size_t blockIndex) { for(RequestSlots::const_iterator itr = requestSlots.begin(); itr != requestSlots.end(); itr++) { const RequestSlot& slot = *itr; @@ -239,7 +239,7 @@ bool DefaultBtMessageDispatcher::isOutstandingRequest(int32_t index, int32_t blo } RequestSlot -DefaultBtMessageDispatcher::getOutstandingRequest(int32_t index, int32_t begin, int32_t length) +DefaultBtMessageDispatcher::getOutstandingRequest(size_t index, uint32_t begin, size_t length) { for(RequestSlots::iterator itr = requestSlots.begin(); itr != requestSlots.end(); itr++) { diff --git a/src/DefaultBtMessageDispatcher.h b/src/DefaultBtMessageDispatcher.h index 4f6cdcfaa9..4f98b043f1 100644 --- a/src/DefaultBtMessageDispatcher.h +++ b/src/DefaultBtMessageDispatcher.h @@ -58,8 +58,8 @@ class DefaultBtMessageDispatcher : public BtMessageDispatcher { SharedHandle pieceStorage; WeakHandle messageFactory; SharedHandle peer; - int32_t maxUploadSpeedLimit; - int32_t requestTimeout; + unsigned int maxUploadSpeedLimit; + time_t requestTimeout; const Logger* logger; public: DefaultBtMessageDispatcher(); @@ -72,7 +72,7 @@ class DefaultBtMessageDispatcher : public BtMessageDispatcher { virtual void sendMessages(); - virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length); + virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length); virtual void doCancelSendingPieceAction(const SharedHandle& piece); @@ -86,15 +86,15 @@ class DefaultBtMessageDispatcher : public BtMessageDispatcher { virtual bool isSendingInProgress(); - virtual int32_t countMessageInQueue() { + virtual size_t countMessageInQueue() { return messageQueue.size(); } - virtual int32_t countOutstandingRequest(); + virtual size_t countOutstandingRequest(); - virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex); + virtual bool isOutstandingRequest(size_t index, size_t blockIndex); - virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length); + virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length); virtual void removeOutstandingRequest(const RequestSlot& slot); @@ -114,11 +114,11 @@ class DefaultBtMessageDispatcher : public BtMessageDispatcher { this->cuid = cuid; } - void setMaxUploadSpeedLimit(int32_t maxUploadSpeedLimit) { + void setMaxUploadSpeedLimit(unsigned int maxUploadSpeedLimit) { this->maxUploadSpeedLimit = maxUploadSpeedLimit; } - void setRequestTimeout(int32_t requestTimeout) { + void setRequestTimeout(time_t requestTimeout) { this->requestTimeout = requestTimeout; } diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc index f50e070a25..75a5e86290 100644 --- a/src/DefaultBtMessageFactory.cc +++ b/src/DefaultBtMessageFactory.cc @@ -81,14 +81,14 @@ DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0), DefaultBtMessageFactory::~DefaultBtMessageFactory() {} BtMessageHandle -DefaultBtMessageFactory::createBtMessage(const unsigned char* data, int32_t dataLength) +DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataLength) { AbstractBtMessageHandle msg(0); if(dataLength == 0) { // keep-alive msg = new BtKeepAliveMessage(); } else { - int8_t id = PeerMessageUtil::getId(data); + uint8_t id = PeerMessageUtil::getId(data); switch(id) { case BtChokeMessage::ID: msg = BtChokeMessage::create(data, dataLength); @@ -194,7 +194,7 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, int32_t data break; } default: - throw new DlAbortEx("Invalid message ID. id=%d", id); + throw new DlAbortEx("Invalid message ID. id=%u", id); } } setCommonProperty(msg); @@ -212,7 +212,7 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m } BtMessageHandle -DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, int32_t dataLength) +DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, size_t dataLength) { SharedHandle msg = BtHandshakeMessage::create(data, dataLength); BtMessageValidatorHandle validator = @@ -238,7 +238,7 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash, } BtMessageHandle -DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, int32_t blockIndex) +DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, size_t blockIndex) { BtRequestMessageHandle msg = new BtRequestMessage(piece->getIndex(), @@ -255,7 +255,7 @@ DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, int32_t } BtMessageHandle -DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, int32_t length) +DefaultBtMessageFactory::createCancelMessage(size_t index, uint32_t begin, size_t length) { BtCancelMessageHandle msg = new BtCancelMessage(index, begin, length); BtMessageValidatorHandle validator = @@ -268,7 +268,7 @@ DefaultBtMessageFactory::createCancelMessage(int32_t index, int32_t begin, int32 } BtMessageHandle -DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, int32_t length) +DefaultBtMessageFactory::createPieceMessage(size_t index, uint32_t begin, size_t length) { BtPieceMessageHandle msg = new BtPieceMessage(index, begin, length); BtMessageValidatorHandle validator = @@ -281,7 +281,7 @@ DefaultBtMessageFactory::createPieceMessage(int32_t index, int32_t begin, int32_ } BtMessageHandle -DefaultBtMessageFactory::createHaveMessage(int32_t index) +DefaultBtMessageFactory::createHaveMessage(size_t index) { BtHaveMessageHandle msg = new BtHaveMessage(index); msg->setBtMessageValidator(new BtHaveMessageValidator(msg.get(), @@ -359,7 +359,7 @@ DefaultBtMessageFactory::createHaveNoneMessage() } BtMessageHandle -DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, int32_t length) +DefaultBtMessageFactory::createRejectMessage(size_t index, uint32_t begin, size_t length) { BtRejectMessageHandle msg = new BtRejectMessage(index, begin, length); BtMessageValidatorHandle validator = @@ -372,7 +372,7 @@ DefaultBtMessageFactory::createRejectMessage(int32_t index, int32_t begin, int32 } BtMessageHandle -DefaultBtMessageFactory::createAllowedFastMessage(int32_t index) +DefaultBtMessageFactory::createAllowedFastMessage(size_t index) { BtAllowedFastMessageHandle msg = new BtAllowedFastMessage(index); BtMessageValidatorHandle validator = diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h index 6231f8333d..657319e7be 100644 --- a/src/DefaultBtMessageFactory.h +++ b/src/DefaultBtMessageFactory.h @@ -81,25 +81,25 @@ class DefaultBtMessageFactory : public BtMessageFactory { virtual ~DefaultBtMessageFactory(); virtual SharedHandle - createBtMessage(const unsigned char* msg, int32_t msgLength); + createBtMessage(const unsigned char* msg, size_t msgLength); virtual SharedHandle - createHandshakeMessage(const unsigned char* msg, int32_t msgLength); + createHandshakeMessage(const unsigned char* msg, size_t msgLength); virtual SharedHandle createHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId); virtual SharedHandle - createRequestMessage(const SharedHandle& piece, int32_t blockIndex); + createRequestMessage(const SharedHandle& piece, size_t blockIndex); virtual SharedHandle - createCancelMessage(int32_t index, int32_t begin, int32_t length); + createCancelMessage(size_t index, uint32_t begin, size_t length); virtual SharedHandle - createPieceMessage(int32_t index, int32_t begin, int32_t length); + createPieceMessage(size_t index, uint32_t begin, size_t length); - virtual SharedHandle createHaveMessage(int32_t index); + virtual SharedHandle createHaveMessage(size_t index); virtual SharedHandle createChokeMessage(); @@ -118,9 +118,9 @@ class DefaultBtMessageFactory : public BtMessageFactory { virtual SharedHandle createHaveNoneMessage(); virtual SharedHandle - createRejectMessage(int32_t index, int32_t begin, int32_t length); + createRejectMessage(size_t index, uint32_t begin, size_t length); - virtual SharedHandle createAllowedFastMessage(int32_t index); + virtual SharedHandle createAllowedFastMessage(size_t index); virtual SharedHandle createPortMessage(uint16_t port); diff --git a/src/DefaultBtMessageReceiver.cc b/src/DefaultBtMessageReceiver.cc index 332886abc2..9dd6550750 100644 --- a/src/DefaultBtMessageReceiver.cc +++ b/src/DefaultBtMessageReceiver.cc @@ -66,7 +66,7 @@ DefaultBtMessageReceiver::~DefaultBtMessageReceiver() BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) { unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH]; - int32_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH; + size_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH; bool retval = peerConnection->receiveHandshake(data, dataLength); // To handle tracker's NAT-checking feature if(!handshakeSent && quickReply && dataLength >= 48) { @@ -99,7 +99,7 @@ void DefaultBtMessageReceiver::sendHandshake() { BtMessageHandle DefaultBtMessageReceiver::receiveMessage() { unsigned char data[MAX_PAYLOAD_LEN]; - int32_t dataLength = 0; + size_t dataLength = 0; if(!peerConnection->receiveMessage(data, dataLength)) { return 0; } diff --git a/src/DefaultBtRequestFactory.h b/src/DefaultBtRequestFactory.h index 665237ff18..0c2976ae30 100644 --- a/src/DefaultBtRequestFactory.h +++ b/src/DefaultBtRequestFactory.h @@ -66,7 +66,7 @@ class DefaultBtRequestFactory : public BtRequestFactory { virtual void removeAllTargetPiece(); - virtual int32_t countTargetPiece() { + virtual size_t countTargetPiece() { return pieces.size(); } diff --git a/src/DefaultDiskWriter.cc b/src/DefaultDiskWriter.cc index ec194e87c5..df4fe1b74b 100644 --- a/src/DefaultDiskWriter.cc +++ b/src/DefaultDiskWriter.cc @@ -41,7 +41,7 @@ DefaultDiskWriter::DefaultDiskWriter():AbstractDiskWriter() {} DefaultDiskWriter::~DefaultDiskWriter() {} void DefaultDiskWriter::initAndOpenFile(const std::string& filename, - int64_t totalLength) + uint64_t totalLength) { createFile(filename); } diff --git a/src/DefaultDiskWriter.h b/src/DefaultDiskWriter.h index 4939f44796..6fd47e3508 100644 --- a/src/DefaultDiskWriter.h +++ b/src/DefaultDiskWriter.h @@ -45,7 +45,7 @@ class DefaultDiskWriter:public AbstractDiskWriter { virtual ~DefaultDiskWriter(); - virtual void initAndOpenFile(const std::string& filename, int64_t totalLength = 0); + virtual void initAndOpenFile(const std::string& filename, uint64_t totalLength = 0); }; typedef SharedHandle DefaultDiskWriterHandle; diff --git a/src/DefaultPeerListProcessor.cc b/src/DefaultPeerListProcessor.cc index d7660e2da6..9446505d66 100644 --- a/src/DefaultPeerListProcessor.cc +++ b/src/DefaultPeerListProcessor.cc @@ -40,9 +40,7 @@ namespace aria2 { -DefaultPeerListProcessor::DefaultPeerListProcessor(int32_t pieceLength, int64_t totalLength): - pieceLength(pieceLength), - totalLength(totalLength) {} +DefaultPeerListProcessor::DefaultPeerListProcessor() {} DefaultPeerListProcessor::~DefaultPeerListProcessor() {} diff --git a/src/DefaultPeerListProcessor.h b/src/DefaultPeerListProcessor.h index 5a17250088..84a02bbdb9 100644 --- a/src/DefaultPeerListProcessor.h +++ b/src/DefaultPeerListProcessor.h @@ -40,11 +40,8 @@ namespace aria2 { class DefaultPeerListProcessor : public PeerListProcessor { -private: - int32_t pieceLength; - int64_t totalLength; public: - DefaultPeerListProcessor(int32_t pieceLength, int64_t totalLength); + DefaultPeerListProcessor(); virtual ~DefaultPeerListProcessor(); diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 34c9a4bc58..3a0a6459d5 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -385,7 +385,7 @@ void DefaultPieceStorage::setFileFilter(IntSequence seq) fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()), fileIndexes.end()); std::deque filePaths; const FileEntries& entries = diskAdaptor->getFileEntries(); - for(int32_t i = 0; i < (int32_t)entries.size(); i++) { + for(size_t i = 0; i < entries.size(); i++) { if(std::find(fileIndexes.begin(), fileIndexes.end(), i+1) != fileIndexes.end()) { logger->debug("index=%d is %s", i+1, entries[i]->getPath().c_str()); filePaths.push_back(entries[i]->getPath()); diff --git a/src/DelegatingPeerListProcessor.cc b/src/DelegatingPeerListProcessor.cc index a0a3a53e5f..c725c8d112 100644 --- a/src/DelegatingPeerListProcessor.cc +++ b/src/DelegatingPeerListProcessor.cc @@ -39,12 +39,10 @@ namespace aria2 { -DelegatingPeerListProcessor::DelegatingPeerListProcessor(int32_t pieceLength, int64_t totalLength): - pieceLength(pieceLength), - totalLength(totalLength) +DelegatingPeerListProcessor::DelegatingPeerListProcessor() { - processors.push_back(new DefaultPeerListProcessor(pieceLength, totalLength)); - processors.push_back(new CompactPeerListProcessor(pieceLength, totalLength)); + processors.push_back(new DefaultPeerListProcessor()); + processors.push_back(new CompactPeerListProcessor()); } DelegatingPeerListProcessor::~DelegatingPeerListProcessor() {} diff --git a/src/DelegatingPeerListProcessor.h b/src/DelegatingPeerListProcessor.h index f5aeae25c7..ed67a72eac 100644 --- a/src/DelegatingPeerListProcessor.h +++ b/src/DelegatingPeerListProcessor.h @@ -40,11 +40,9 @@ namespace aria2 { class DelegatingPeerListProcessor : public PeerListProcessor { private: - int32_t pieceLength; - int64_t totalLength; std::deque > processors; public: - DelegatingPeerListProcessor(int32_t pieceLength, int64_t totalLength); + DelegatingPeerListProcessor(); virtual ~DelegatingPeerListProcessor(); diff --git a/src/DiskAdaptor.cc b/src/DiskAdaptor.cc index 2a9ccec845..590c1d48f8 100644 --- a/src/DiskAdaptor.cc +++ b/src/DiskAdaptor.cc @@ -68,9 +68,9 @@ bool DiskAdaptor::addDownloadEntry(const std::string& fileEntryPath) return false; } -bool DiskAdaptor::addDownloadEntry(int index) +bool DiskAdaptor::addDownloadEntry(size_t index) { - if(fileEntries.size() <= (unsigned int)index) { + if(fileEntries.size() <= index) { return false; } fileEntries[index]->setRequested(true); diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index 11c56c131f..7b5c036b8a 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -68,10 +68,10 @@ class DiskAdaptor:public BinaryStream { virtual std::string getFilePath() = 0; - virtual int64_t size() const = 0; + virtual uint64_t size() const = 0; // optional behavior - virtual void truncate(int64_t length) {} + virtual void truncate(uint64_t length) {} void setFileEntries(const std::deque >& fileEntries); @@ -81,7 +81,7 @@ class DiskAdaptor:public BinaryStream { bool addDownloadEntry(const std::string& fileEntryPath); - bool addDownloadEntry(int index); + bool addDownloadEntry(size_t index); void addAllDownloadEntry(); diff --git a/src/DiskWriter.h b/src/DiskWriter.h index fa6adbaf12..c57e8846dd 100644 --- a/src/DiskWriter.h +++ b/src/DiskWriter.h @@ -56,9 +56,9 @@ class DiskWriter:public BinaryStream { * If the file exists, then it is truncated to 0 length. * @param filename the file name to be opened. */ - virtual void initAndOpenFile(const std::string& filename, int64_t totalLength = 0) = 0; + virtual void initAndOpenFile(const std::string& filename, uint64_t totalLength = 0) = 0; - virtual void openFile(const std::string& filename, int64_t totalLength = 0) = 0; + virtual void openFile(const std::string& filename, uint64_t totalLength = 0) = 0; /** * Closes this output stream. @@ -72,12 +72,12 @@ class DiskWriter:public BinaryStream { * * @param filename the file name to be opened. */ - virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0) = 0; + virtual void openExistingFile(const std::string& filename, uint64_t totalLength = 0) = 0; - virtual void truncate(int64_t length) = 0; + virtual void truncate(uint64_t length) = 0; // Returns file length - virtual int64_t size() const = 0; + virtual uint64_t size() const = 0; virtual void enableDirectIO() = 0; diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 821224c030..4cc32d593e 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -111,7 +111,7 @@ bool DownloadCommand::executeInternal() { size_t BUFSIZE = 16*1024; unsigned char buf[BUFSIZE]; - int32_t bufSize; + size_t bufSize; if(segment->getLength() > 0 && segment->getLength()-segment->getWrittenLength() < BUFSIZE) { bufSize = segment->getLength()-segment->getWrittenLength(); } else { @@ -130,7 +130,7 @@ bool DownloadCommand::executeInternal() { //segment->writtenLength += bufSize; peerStat->updateDownloadLength(bufSize); } else { - int32_t infbufSize = 16*1024; + size_t infbufSize = 16*1024; unsigned char infbuf[infbufSize]; transferDecoder->inflate(infbuf, infbufSize, buf, bufSize); _requestGroup->getPieceStorage()->getDiskAdaptor()->writeData(infbuf, infbufSize, diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 43f52ce2c5..5d6bda084d 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -111,8 +111,8 @@ void DownloadEngine::cleanQueue() { void DownloadEngine::executeCommand(Command::STATUS statusFilter) { - int32_t max = commands.size(); - for(int32_t i = 0; i < max; i++) { + size_t max = commands.size(); + for(size_t i = 0; i < max; i++) { Command* com = commands.front(); commands.pop_front(); if(com->statusMatch(statusFilter)) { @@ -160,7 +160,6 @@ void DownloadEngine::shortSleep() const { void DownloadEngine::waitData() { fd_set rfds; fd_set wfds; - int32_t retval = 0; struct timeval tv; memcpy(&rfds, &rfdset, sizeof(fd_set)); @@ -170,7 +169,7 @@ void DownloadEngine::waitData() { for(NameResolverEntries::iterator itr = nameResolverEntries.begin(); itr != nameResolverEntries.end(); ++itr) { NameResolverEntry& entry = *itr; - int32_t fd = entry.nameResolver->getFds(&rfds, &wfds); + int fd = entry.nameResolver->getFds(&rfds, &wfds); // TODO force error if fd == 0 if(fdmax < fd) { fdmax = fd; @@ -180,7 +179,7 @@ void DownloadEngine::waitData() { tv.tv_sec = noWait ? 0 : 1; tv.tv_usec = 0; - retval = select(fdmax+1, &rfds, &wfds, NULL, &tv); + int retval = select(fdmax+1, &rfds, &wfds, NULL, &tv); if(retval > 0) { for(SocketEntries::iterator itr = socketEntries.begin(); itr != socketEntries.end(); ++itr) { @@ -215,7 +214,7 @@ void DownloadEngine::updateFdSet() { for(SocketEntries::iterator itr = socketEntries.begin(); itr != socketEntries.end(); ++itr) { SocketEntry& entry = *itr; - int32_t fd = entry.socket->getSockfd(); + int fd = entry.socket->getSockfd(); switch(entry.type) { case SocketEntry::TYPE_RD: FD_SET(fd, &rfdset); diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 7ba80c424a..18c9b64601 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -96,7 +96,7 @@ class DownloadEngine { #endif // ENABLE_ASYNC_DNS fd_set rfdset; fd_set wfdset; - int32_t fdmax; + int fdmax; const Logger* logger; diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index fc74fbd591..0c44c9edd2 100644 --- a/src/DownloadEngineFactory.cc +++ b/src/DownloadEngineFactory.cc @@ -64,7 +64,7 @@ DownloadEngineFactory::newDownloadEngine(Option* op, { RequestGroups workingSet; RequestGroups reservedSet; - if(op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS) < (int32_t)requestGroups.size()) { + if((size_t)op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS) < requestGroups.size()) { std::copy(requestGroups.begin(), requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS), std::back_inserter(workingSet)); std::copy(requestGroups.begin()+op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS), requestGroups.end(), std::back_inserter(reservedSet)); @@ -88,7 +88,7 @@ DownloadEngineFactory::newDownloadEngine(Option* op, e->commands.push_back(new AutoSaveCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), op->getAsInt(PREF_AUTO_SAVE_INTERVAL))); e->commands.push_back(new HaveEraseCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), 10)); { - int32_t stopSec = op->getAsInt(PREF_STOP); + time_t stopSec = op->getAsInt(PREF_STOP); if(stopSec > 0) { e->commands.push_back(new TimedHaltCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), stopSec)); } diff --git a/src/DownloadResult.h b/src/DownloadResult.h index 340e69e728..c8fc13d9b1 100644 --- a/src/DownloadResult.h +++ b/src/DownloadResult.h @@ -54,19 +54,19 @@ class DownloadResult std::string filePath; - int64_t totalLength; + uint64_t totalLength; std::string uri; - int32_t numUri; + size_t numUri; RESULT result; DownloadResult(int32_t gid, const std::string& filePath, - int64_t totalLength, + uint64_t totalLength, const std::string& uri, - int32_t numUri, + size_t numUri, RESULT result): gid(gid), filePath(filePath), diff --git a/src/ExpatMetalinkProcessor.cc b/src/ExpatMetalinkProcessor.cc index 7de3c7f0c6..eb3ade4da9 100644 --- a/src/ExpatMetalinkProcessor.cc +++ b/src/ExpatMetalinkProcessor.cc @@ -101,7 +101,7 @@ SharedHandle ExpatMetalinkProcessor::parseFromBinaryStream(const SharedHandle& binaryStream) { _stm = new MetalinkParserStateMachine(); - int32_t bufSize = 4096; + ssize_t bufSize = 4096; unsigned char buf[bufSize]; SharedHandle sessionData = new SessionData(_stm); @@ -111,9 +111,9 @@ ExpatMetalinkProcessor::parseFromBinaryStream(const SharedHandle& XML_SetElementHandler(parser, &mlStartElement, &mlEndElement); XML_SetCharacterDataHandler(parser, &mlCharacters); - int64_t readOffset = 0; + off_t readOffset = 0; while(1) { - int32_t res = binaryStream->readData(buf, bufSize, readOffset); + ssize_t res = binaryStream->readData(buf, bufSize, readOffset); if(res == 0) { break; } diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index cb4e58fc8b..8c71c5a62b 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -52,7 +52,7 @@ FeatureConfig::FeatureConfig() { PortMap::value_type("https", 443), PortMap::value_type("ftp", 21), }; - int32_t portArraySize = sizeof(portArray)/sizeof(PortMap::value_type); + size_t portArraySize = sizeof(portArray)/sizeof(PortMap::value_type); defaultPorts.insert(&portArray[0], &portArray[portArraySize]); @@ -96,11 +96,11 @@ FeatureConfig::FeatureConfig() { ), }; - int32_t featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type); + size_t featureArraySize = sizeof(featureArray)/sizeof(FeatureMap::value_type); supportedFeatures.insert(&featureArray[0], &featureArray[featureArraySize]); - for(int32_t i = 0; i < featureArraySize; i++) { + for(size_t i = 0; i < featureArraySize; i++) { features.push_back(featureArray[i].first); } } diff --git a/src/FeatureConfig.h b/src/FeatureConfig.h index 3d10433a14..2531158aca 100644 --- a/src/FeatureConfig.h +++ b/src/FeatureConfig.h @@ -42,7 +42,7 @@ namespace aria2 { -typedef std::map PortMap; +typedef std::map PortMap; typedef std::map FeatureMap; class FeatureConfig { @@ -68,7 +68,7 @@ class FeatureConfig { featureConfig = 0; } - int32_t getDefaultPort(const std::string& protocol) const { + uint16_t getDefaultPort(const std::string& protocol) const { PortMap::const_iterator itr = defaultPorts.find(protocol); if(itr == defaultPorts.end()) { return 0; diff --git a/src/File.cc b/src/File.cc index 7f8ef2e1c7..7daa3dce2f 100644 --- a/src/File.cc +++ b/src/File.cc @@ -51,7 +51,7 @@ File::File(const std::string& name):name(name) {} File::~File() {} -int32_t File::fillStat(struct stat& fstat) { +int File::fillStat(struct stat& fstat) { return stat(name.c_str(), &fstat); } @@ -86,7 +86,7 @@ bool File::remove() { } } -int64_t File::size() { +uint64_t File::size() { struct stat fstat; if(fillStat(fstat) < 0) { return 0; diff --git a/src/File.h b/src/File.h index 63da704461..b7dac1d18c 100644 --- a/src/File.h +++ b/src/File.h @@ -51,7 +51,7 @@ class File { /** * Returns the return value of stat(...) */ - int32_t fillStat(struct stat& fstat); + int fillStat(struct stat& fstat); public: File(const std::string& name); ~File(); @@ -86,7 +86,7 @@ class File { */ bool mkdirs(); - int64_t size(); + uint64_t size(); mode_t mode(); diff --git a/src/FileAllocationEntry.cc b/src/FileAllocationEntry.cc index a4e36e5620..a0e1df053d 100644 --- a/src/FileAllocationEntry.cc +++ b/src/FileAllocationEntry.cc @@ -53,12 +53,12 @@ FileAllocationEntry:: ~FileAllocationEntry() _requestGroup->getPieceStorage()->getDiskAdaptor()->disableDirectIO(); } -int64_t FileAllocationEntry::getCurrentLength() +off_t FileAllocationEntry::getCurrentLength() { return _fileAllocationIterator->getCurrentLength(); } -int64_t FileAllocationEntry::getTotalLength() +uint64_t FileAllocationEntry::getTotalLength() { return _fileAllocationIterator->getTotalLength(); } diff --git a/src/FileAllocationEntry.h b/src/FileAllocationEntry.h index 84426795c6..f746765c44 100644 --- a/src/FileAllocationEntry.h +++ b/src/FileAllocationEntry.h @@ -53,9 +53,9 @@ class FileAllocationEntry : public RequestGroupEntry, public ProgressAwareEntry ~FileAllocationEntry(); - virtual int64_t getCurrentLength(); + virtual off_t getCurrentLength(); - virtual int64_t getTotalLength(); + virtual uint64_t getTotalLength(); virtual bool finished(); diff --git a/src/FileAllocationIterator.h b/src/FileAllocationIterator.h index 6148b68c5f..474ecc7034 100644 --- a/src/FileAllocationIterator.h +++ b/src/FileAllocationIterator.h @@ -49,9 +49,9 @@ class FileAllocationIterator virtual bool finished() = 0; - virtual int64_t getCurrentLength() = 0; + virtual off_t getCurrentLength() = 0; - virtual int64_t getTotalLength() = 0; + virtual uint64_t getTotalLength() = 0; }; typedef SharedHandle FileAllocationIteratorHandle; diff --git a/src/FileAllocationMan.cc b/src/FileAllocationMan.cc index e95fb58cc8..b62f016464 100644 --- a/src/FileAllocationMan.cc +++ b/src/FileAllocationMan.cc @@ -77,7 +77,7 @@ void FileAllocationMan::pushFileAllocationEntry(const FileAllocationEntryHandle& _fileAllocationEntries.push_back(entry); } -int32_t FileAllocationMan::countFileAllocationEntryInQueue() const +size_t FileAllocationMan::countFileAllocationEntryInQueue() const { return _fileAllocationEntries.size(); } diff --git a/src/FileAllocationMan.h b/src/FileAllocationMan.h index 1484111789..a13b76936a 100644 --- a/src/FileAllocationMan.h +++ b/src/FileAllocationMan.h @@ -64,7 +64,7 @@ class FileAllocationMan { void pushFileAllocationEntry(const SharedHandle& entry); - int32_t countFileAllocationEntryInQueue() const; + size_t countFileAllocationEntryInQueue() const; }; typedef SharedHandle FileAllocationManHandle; diff --git a/src/FileEntry.cc b/src/FileEntry.cc index ef47b94f3f..c10ea02294 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -39,8 +39,8 @@ namespace aria2 { FileEntry::FileEntry(const std::string& path, - int64_t length, - int64_t offset, + uint64_t length, + off_t offset, const std::deque& uris): path(path), _uris(uris), length(length), offset(offset), extracted(false), requested(true) {} diff --git a/src/FileEntry.h b/src/FileEntry.h index 722db7e0dd..849d99632b 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -47,14 +47,14 @@ class FileEntry { private: std::string path; std::deque _uris; - int64_t length; - int64_t offset; + uint64_t length; + off_t offset; bool extracted; bool requested; public: FileEntry():length(0), offset(0), extracted(false), requested(false) {} - FileEntry(const std::string& path, int64_t length, int64_t offset, + FileEntry(const std::string& path, uint64_t length, off_t offset, const std::deque& uris = std::deque()); ~FileEntry(); @@ -75,13 +75,13 @@ class FileEntry { void setPath(const std::string& path) { this->path = path; } - int64_t getLength() const { return length; } + uint64_t getLength() const { return length; } - void setLength(int64_t length) { this->length = length; } + void setLength(uint64_t length) { this->length = length; } - int64_t getOffset() const { return offset; } + off_t getOffset() const { return offset; } - void setOffset(int64_t offset) { this->offset = offset; } + void setOffset(off_t offset) { this->offset = offset; } bool isExtracted() const { return extracted; } diff --git a/src/FileMetalinkParserState.cc b/src/FileMetalinkParserState.cc index f6284f6a5b..99fd843356 100644 --- a/src/FileMetalinkParserState.cc +++ b/src/FileMetalinkParserState.cc @@ -57,7 +57,7 @@ void FileMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, #endif // ENABLE_MESSAGE_DIGEST } else if(name == "resources") { stm->setResourcesState(); - int32_t maxConnections; + int maxConnections; { std::map::const_iterator itr = attrs.find("maxconnections"); if(itr == attrs.end()) { diff --git a/src/FillRequestGroupCommand.cc b/src/FillRequestGroupCommand.cc index 0fa2f8ab93..72b0270a1b 100644 --- a/src/FillRequestGroupCommand.cc +++ b/src/FillRequestGroupCommand.cc @@ -44,7 +44,7 @@ namespace aria2 { FillRequestGroupCommand::FillRequestGroupCommand(int32_t cuid, DownloadEngine* e, - int32_t interval): + time_t interval): Command(cuid), _e(e), _interval(interval) diff --git a/src/FillRequestGroupCommand.h b/src/FillRequestGroupCommand.h index be34f26516..e28f952d8c 100644 --- a/src/FillRequestGroupCommand.h +++ b/src/FillRequestGroupCommand.h @@ -49,16 +49,16 @@ class FillRequestGroupCommand : public Command { private: std::deque > _reservedRequestGroups; DownloadEngine* _e; - int32_t _interval; + time_t _interval; Time _checkPoint; public: - FillRequestGroupCommand(int32_t cuid, DownloadEngine* e, int32_t interval); + FillRequestGroupCommand(int32_t cuid, DownloadEngine* e, time_t interval); virtual ~FillRequestGroupCommand(); virtual bool execute(); - void setInterval(int32_t interval) + void setInterval(time_t interval) { _interval = interval; } diff --git a/src/FixedWidthNumberDecorator.h b/src/FixedWidthNumberDecorator.h index 286d93e9df..fac4bf0d6c 100644 --- a/src/FixedWidthNumberDecorator.h +++ b/src/FixedWidthNumberDecorator.h @@ -43,16 +43,16 @@ namespace aria2 { class FixedWidthNumberDecorator : public NumberDecorator { private: - int32_t _width; + size_t _width; public: - FixedWidthNumberDecorator(int32_t width):_width(width) {} + FixedWidthNumberDecorator(size_t width):_width(width) {} virtual ~FixedWidthNumberDecorator() {} - virtual std::string decorate(int32_t number) + virtual std::string decorate(unsigned int number) { - std::string s = Util::itos(number); - while(s.size() < (size_t)_width) { + std::string s = Util::uitos(number); + while(s.size() < _width) { s.insert(0, "0"); } return s; diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 786c57681f..7875614c50 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -111,16 +111,16 @@ SocketHandle FtpConnection::sendPort() const serverSocket->beginListen(); serverSocket->setNonBlockingMode(); - std::pair addrinfo; + std::pair addrinfo; socket->getAddrInfo(addrinfo); - int32_t ipaddr[4]; - sscanf(addrinfo.first.c_str(), "%d.%d.%d.%d", + unsigned int ipaddr[4]; + sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u", &ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]); serverSocket->getAddrInfo(addrinfo); std::string request = "PORT "+ - Util::itos(ipaddr[0])+","+Util::itos(ipaddr[1])+","+ - Util::itos(ipaddr[2])+","+Util::itos(ipaddr[3])+","+ - Util::itos(addrinfo.second/256)+","+Util::itos(addrinfo.second%256)+"\r\n"; + Util::uitos(ipaddr[0])+","+Util::uitos(ipaddr[1])+","+ + Util::uitos(ipaddr[2])+","+Util::uitos(ipaddr[3])+","+ + Util::uitos(addrinfo.second/256)+","+Util::uitos(addrinfo.second%256)+"\r\n"; logger->info(MSG_SENDING_REQUEST, cuid, request.c_str()); socket->writeData(request); return serverSocket; @@ -140,23 +140,23 @@ void FtpConnection::sendRetr() const socket->writeData(request); } -int32_t FtpConnection::getStatus(const std::string& response) const +unsigned int FtpConnection::getStatus(const std::string& response) const { - int32_t status; - // When the response is not like "%d %*s", + unsigned int status; + // When the response is not like "%u %*s", // we return 0. if(response.find_first_not_of("0123456789") != 3 || !(response.find(" ") == 3 || response.find("-") == 3)) { return 0; } - if(sscanf(response.c_str(), "%d %*s", &status) == 1) { + if(sscanf(response.c_str(), "%u %*s", &status) == 1) { return status; } else { return 0; } } -bool FtpConnection::isEndOfResponse(int32_t status, const std::string& response) const +bool FtpConnection::isEndOfResponse(unsigned int status, const std::string& response) const { if(response.size() <= 4) { return false; @@ -165,7 +165,7 @@ bool FtpConnection::isEndOfResponse(int32_t status, const std::string& response) if(response.at(3) == '-') { // multi line response std::string::size_type p; - p = response.find("\r\n"+Util::itos(status)+" "); + p = response.find("\r\n"+Util::uitos(status)+" "); if(p == std::string::npos) { return false; } @@ -177,11 +177,11 @@ bool FtpConnection::isEndOfResponse(int32_t status, const std::string& response) } } -bool FtpConnection::bulkReceiveResponse(std::pair& response) +bool FtpConnection::bulkReceiveResponse(std::pair& response) { char buf[1024]; while(socket->isReadable(0)) { - int32_t size = sizeof(buf)-1; + size_t size = sizeof(buf)-1; socket->readData(buf, size); if(size == 0) { throw new DlRetryEx(EX_GOT_EOF); @@ -189,7 +189,7 @@ bool FtpConnection::bulkReceiveResponse(std::pair& respons buf[size] = '\0'; strbuf += buf; } - int32_t status; + unsigned int status; if(strbuf.size() >= 4) { status = getStatus(strbuf); if(status == 0) { @@ -210,9 +210,9 @@ bool FtpConnection::bulkReceiveResponse(std::pair& respons } } -int32_t FtpConnection::receiveResponse() +unsigned int FtpConnection::receiveResponse() { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { return response.first; } else { @@ -232,12 +232,12 @@ int32_t FtpConnection::receiveResponse() # define ULONGLONG_SCANF "%Lu" #endif // __MINGW32__ -int32_t FtpConnection::receiveSizeResponse(int64_t& size) +unsigned int FtpConnection::receiveSizeResponse(uint64_t& size) { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { - sscanf(response.second.c_str(), "%*d " LONGLONG_SCANF, &size); + sscanf(response.second.c_str(), "%*u " LONGLONG_SCANF, &size); } return response.first; } else { @@ -245,20 +245,20 @@ int32_t FtpConnection::receiveSizeResponse(int64_t& size) } } -int32_t FtpConnection::receivePasvResponse(std::pair& dest) +unsigned int FtpConnection::receivePasvResponse(std::pair& dest) { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 227) { // we assume the format of response is "227 Entering Passive Mode (h1,h2,h3,h4,p1,p2)." - int32_t h1, h2, h3, h4, p1, p2; + unsigned int h1, h2, h3, h4, p1, p2; std::string::size_type p = response.second.find("("); if(p >= 4) { sscanf(response.second.substr(response.second.find("(")).c_str(), - "(%d,%d,%d,%d,%d,%d).", + "(%u,%u,%u,%u,%u,%u).", &h1, &h2, &h3, &h4, &p1, &p2); // ip address - dest.first = Util::itos(h1)+"."+Util::itos(h2)+"."+Util::itos(h3)+"."+Util::itos(h4); + dest.first = Util::uitos(h1)+"."+Util::uitos(h2)+"."+Util::uitos(h3)+"."+Util::uitos(h4); // port number dest.second = 256*p1+p2; } else { diff --git a/src/FtpConnection.h b/src/FtpConnection.h index edc3b67662..bc0b597bf7 100644 --- a/src/FtpConnection.h +++ b/src/FtpConnection.h @@ -58,9 +58,9 @@ class FtpConnection { std::string strbuf; - int32_t getStatus(const std::string& response) const; - bool isEndOfResponse(int32_t status, const std::string& response) const; - bool bulkReceiveResponse(std::pair& response); + unsigned int getStatus(const std::string& response) const; + bool isEndOfResponse(unsigned int status, const std::string& response) const; + bool bulkReceiveResponse(std::pair& response); public: FtpConnection(int32_t cuid, const SharedHandle& socket, const SharedHandle& req, const Option* op); @@ -75,9 +75,9 @@ class FtpConnection { void sendRest(const SharedHandle& segment) const; void sendRetr() const; - int32_t receiveResponse(); - int32_t receiveSizeResponse(int64_t& size); - int32_t receivePasvResponse(std::pair& dest); + unsigned int receiveResponse(); + unsigned int receiveSizeResponse(uint64_t& size); + unsigned int receivePasvResponse(std::pair& dest); }; } // namespace aria2 diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 522f5700a4..db77598d96 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -110,7 +110,7 @@ bool FtpNegotiationCommand::recvGreeting() { disableWriteCheckSocket(); setReadCheckSocket(socket); - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -129,7 +129,7 @@ bool FtpNegotiationCommand::sendUser() { } bool FtpNegotiationCommand::recvUser() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); switch(status) { case 0: return false; @@ -152,7 +152,7 @@ bool FtpNegotiationCommand::sendPass() { } bool FtpNegotiationCommand::recvPass() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -170,7 +170,7 @@ bool FtpNegotiationCommand::sendType() { } bool FtpNegotiationCommand::recvType() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -188,7 +188,7 @@ bool FtpNegotiationCommand::sendCwd() { } bool FtpNegotiationCommand::recvCwd() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -206,16 +206,16 @@ bool FtpNegotiationCommand::sendSize() { } bool FtpNegotiationCommand::recvSize() { - int64_t size = 0; - int32_t status = ftp->receiveSizeResponse(size); + uint64_t size = 0; + unsigned int status = ftp->receiveSizeResponse(size); if(status == 0) { return false; } if(status != 213) { throw new DlAbortEx(EX_BAD_STATUS, status); } - if(size == INT64_MAX || size < 0) { - throw new DlAbortEx(EX_TOO_LARGE_FILE, Util::itos(size, true).c_str()); + if(size > INT64_MAX) { + throw new DlAbortEx(EX_TOO_LARGE_FILE, Util::uitos(size, true).c_str()); } if(_requestGroup->getPieceStorage().isNull()) { SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext(); @@ -274,7 +274,7 @@ bool FtpNegotiationCommand::sendPort() { } bool FtpNegotiationCommand::recvPort() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -293,8 +293,8 @@ bool FtpNegotiationCommand::sendPasv() { } bool FtpNegotiationCommand::recvPasv() { - std::pair dest; - int32_t status = ftp->receivePasvResponse(dest); + std::pair dest; + unsigned int status = ftp->receivePasvResponse(dest); if(status == 0) { return false; } @@ -328,7 +328,7 @@ bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) { } bool FtpNegotiationCommand::recvRest() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } @@ -347,7 +347,7 @@ bool FtpNegotiationCommand::sendRetr() { } bool FtpNegotiationCommand::recvRetr() { - int32_t status = ftp->receiveResponse(); + unsigned int status = ftp->receiveResponse(); if(status == 0) { return false; } diff --git a/src/FtpNegotiationCommand.h b/src/FtpNegotiationCommand.h index 0851131e3a..da6fe7d326 100644 --- a/src/FtpNegotiationCommand.h +++ b/src/FtpNegotiationCommand.h @@ -99,7 +99,7 @@ class FtpNegotiationCommand : public AbstractCommand { SharedHandle dataSocket; SharedHandle serverSocket; - int32_t sequence; + Seq sequence; FtpConnection* ftp; protected: virtual bool executeInternal(); diff --git a/src/HaveEraseCommand.cc b/src/HaveEraseCommand.cc index 42ba55bb5b..04844615c8 100644 --- a/src/HaveEraseCommand.cc +++ b/src/HaveEraseCommand.cc @@ -40,7 +40,7 @@ namespace aria2 { -HaveEraseCommand::HaveEraseCommand(int32_t cuid, DownloadEngine* e, int32_t interval) +HaveEraseCommand::HaveEraseCommand(int32_t cuid, DownloadEngine* e, time_t interval) :TimeBasedCommand(cuid, e, interval) {} HaveEraseCommand::~HaveEraseCommand() {} @@ -54,7 +54,8 @@ void HaveEraseCommand::preProcess() void HaveEraseCommand::process() { - for(int32_t i = 0; i < _e->_requestGroupMan->countRequestGroup(); ++i) { + size_t numLoop = _e->_requestGroupMan->countRequestGroup(); + for(size_t i = 0; i < numLoop; ++i) { PieceStorageHandle ps = _e->_requestGroupMan->getRequestGroup(i)->getPieceStorage(); if(!ps.isNull()) { ps->removeAdvertisedPiece(5); diff --git a/src/HaveEraseCommand.h b/src/HaveEraseCommand.h index 8d43dfa6c7..e275048685 100644 --- a/src/HaveEraseCommand.h +++ b/src/HaveEraseCommand.h @@ -42,7 +42,7 @@ namespace aria2 { class HaveEraseCommand : public TimeBasedCommand { public: - HaveEraseCommand(int32_t cuid, DownloadEngine* e, int32_t interval); + HaveEraseCommand(int32_t cuid, DownloadEngine* e, time_t interval); virtual ~HaveEraseCommand(); diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index cd00a0572e..52e3bfcbcc 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -118,7 +118,7 @@ HttpResponseHandle HttpConnection::receiveResponse() HttpHeaderProcessorHandle proc = entry->getHttpHeaderProcessor(); unsigned char buf[512]; - int32_t size = sizeof(buf); + size_t size = sizeof(buf); socket->peekData(buf, size); if(size == 0) { throw new DlRetryEx(EX_INVALID_RESPONSE); @@ -128,7 +128,7 @@ HttpResponseHandle HttpConnection::receiveResponse() socket->readData(buf, size); return 0; } - int32_t putbackDataLength = proc->getPutBackDataLength(); + size_t putbackDataLength = proc->getPutBackDataLength(); size -= putbackDataLength; socket->readData(buf, size); diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 571b399b7f..e855f6704a 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -64,16 +64,16 @@ std::deque HttpHeader::get(const std::string& name) const { return v; } -int32_t HttpHeader::getFirstAsInt(const std::string& name) const { - return getFirstAsLLInt(name); +unsigned int HttpHeader::getFirstAsUInt(const std::string& name) const { + return getFirstAsULLInt(name); } -int64_t HttpHeader::getFirstAsLLInt(const std::string& name) const { +uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const { std::string value = getFirst(name); if(value == "") { return 0; } else { - return strtoll(value.c_str(), 0, 10); + return strtoull(value.c_str(), 0, 10); } } @@ -85,8 +85,12 @@ RangeHandle HttpHeader::getRange() const if(contentLengthStr == "") { return new Range(0, 0, 0); } else { - int64_t contentLength = strtoll(contentLengthStr.c_str(), 0, 10); - return new Range(0, contentLength-1, contentLength); + uint64_t contentLength = strtoull(contentLengthStr.c_str(), 0, 10); + if(contentLength == 0) { + return new Range(0, 0, 0); + } else { + return new Range(0, contentLength-1, contentLength); + } } } std::string::size_type rangeSpecIndex = rangeStr.find("bytes "); @@ -98,9 +102,9 @@ RangeHandle HttpHeader::getRange() const std::pair startEndBytePair; Util::split(startEndBytePair, rangePair.first, '-'); - int64_t startByte = STRTOLL(startEndBytePair.first.c_str()); - int64_t endByte = STRTOLL(startEndBytePair.second.c_str()); - int64_t entityLength = STRTOLL(rangePair.second.c_str()); + uint64_t startByte = STRTOULL(startEndBytePair.first.c_str()); + uint64_t endByte = STRTOULL(startEndBytePair.second.c_str()); + uint64_t entityLength = STRTOULL(rangePair.second.c_str()); return new Range(startByte, endByte, entityLength); } diff --git a/src/HttpHeader.h b/src/HttpHeader.h index b235307207..6349a9b705 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -56,8 +56,8 @@ class HttpHeader { bool defined(const std::string& name) const; std::string getFirst(const std::string& name) const; std::deque get(const std::string& name) const; - int32_t getFirstAsInt(const std::string& name) const; - int64_t getFirstAsLLInt(const std::string& name) const; + unsigned int getFirstAsUInt(const std::string& name) const; + uint64_t getFirstAsULLInt(const std::string& name) const; SharedHandle getRange() const; }; diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc index 9cbaa6a85f..c581b65403 100644 --- a/src/HttpHeaderProcessor.cc +++ b/src/HttpHeaderProcessor.cc @@ -45,7 +45,7 @@ HttpHeaderProcessor::HttpHeaderProcessor():_limit(4096) {} HttpHeaderProcessor::~HttpHeaderProcessor() {} -void HttpHeaderProcessor::update(const unsigned char* data, int32_t length) +void HttpHeaderProcessor::update(const unsigned char* data, size_t length) { checkHeaderLimit(length); strm.write(reinterpret_cast(data), length); @@ -57,10 +57,10 @@ void HttpHeaderProcessor::update(const std::string& data) strm << data; } -void HttpHeaderProcessor::checkHeaderLimit(int32_t incomingLength) +void HttpHeaderProcessor::checkHeaderLimit(size_t incomingLength) { strm.seekg(0, std::ios::end); - if((int32_t)strm.tellg()+incomingLength > _limit) { + if((size_t)strm.tellg()+incomingLength > _limit) { throw new DlAbortEx("Too large http header"); } } @@ -75,7 +75,7 @@ bool HttpHeaderProcessor::eoh() const } } -int32_t HttpHeaderProcessor::getPutBackDataLength() const +size_t HttpHeaderProcessor::getPutBackDataLength() const { std::string str = strm.str(); std::string::size_type delimpos = std::string::npos; diff --git a/src/HttpHeaderProcessor.h b/src/HttpHeaderProcessor.h index 84fd14a31c..fc6814d39c 100644 --- a/src/HttpHeaderProcessor.h +++ b/src/HttpHeaderProcessor.h @@ -47,16 +47,16 @@ class HttpHeader; class HttpHeaderProcessor { private: std::stringstream strm; - int32_t _limit; + size_t _limit; - void checkHeaderLimit(int32_t incomingLength); + void checkHeaderLimit(size_t incomingLength); public: HttpHeaderProcessor(); ~HttpHeaderProcessor(); - void update(const unsigned char* data, int32_t length); + void update(const unsigned char* data, size_t length); void update(const std::string& data); @@ -68,7 +68,7 @@ class HttpHeaderProcessor { /** * Retruns the number of bytes beyond the end of header. */ - int32_t getPutBackDataLength() const; + size_t getPutBackDataLength() const; std::pair > getHttpStatusHeader(); @@ -76,7 +76,7 @@ class HttpHeaderProcessor { void clear(); - void setHeaderLimit(int32_t limit) + void setHeaderLimit(size_t limit) { _limit = limit; } diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index f98a0988df..c756cf69c1 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -78,7 +78,7 @@ SharedHandle HttpRequest::getRequest() const return request; } -int64_t HttpRequest::getStartByte() const +off_t HttpRequest::getStartByte() const { if(segment.isNull()) { return 0; @@ -87,7 +87,7 @@ int64_t HttpRequest::getStartByte() const } } -int64_t HttpRequest::getEndByte() const +off_t HttpRequest::getEndByte() const { if(segment.isNull() || request.isNull()) { return 0; @@ -126,9 +126,9 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const } } -std::string HttpRequest::getHostText(const std::string& host, int32_t port) const +std::string HttpRequest::getHostText(const std::string& host, uint16_t port) const { - return host+(port == 80 || port == 443 ? "" : ":"+Util::itos(port)); + return host+(port == 80 || port == 443 ? "" : ":"+Util::uitos(port)); } std::string HttpRequest::createRequest() const @@ -199,10 +199,10 @@ std::string HttpRequest::createRequest() const std::string HttpRequest::createProxyRequest() const { std::string requestLine = - std::string("CONNECT ")+getHost()+":"+Util::itos(getPort())+ + std::string("CONNECT ")+getHost()+":"+Util::uitos(getPort())+ std::string(" HTTP/1.1\r\n")+ "User-Agent: "+userAgent+"\r\n"+ - "Host: "+getHost()+":"+Util::itos(getPort())+"\r\n"; + "Host: "+getHost()+":"+Util::uitos(getPort())+"\r\n"; if(request->isKeepAlive()) { requestLine += "Proxy-Connection: Keep-Alive\r\n"; }else { @@ -239,7 +239,7 @@ std::string HttpRequest::getHost() const return request->getHost(); } -int32_t HttpRequest::getPort() const +uint16_t HttpRequest::getPort() const { return request->getPort(); } diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 20f4915a0d..a47b10a39c 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -56,7 +56,7 @@ class HttpRequest { SharedHandle segment; - int64_t entityLength; + uint64_t entityLength; bool authEnabled; @@ -66,7 +66,7 @@ class HttpRequest { std::string userAgent; - std::string getHostText(const std::string& host, int32_t port) const; + std::string getHostText(const std::string& host, uint16_t port) const; std::string getProxyAuthString() const; @@ -82,19 +82,19 @@ class HttpRequest { /** * entityLength is used in isRangeSatisfied() method. */ - void setEntityLength(int64_t entityLength) + void setEntityLength(uint64_t entityLength) { this->entityLength = entityLength; } - int64_t getEntityLength() const + uint64_t getEntityLength() const { return entityLength; } std::string getHost() const; - int32_t getPort() const; + uint16_t getPort() const; std::string getMethod() const; @@ -118,9 +118,9 @@ class HttpRequest { SharedHandle getRequest() const; - int64_t getStartByte() const; + off_t getStartByte() const; - int64_t getEndByte() const; + off_t getEndByte() const; /** * Returns string representation of http request. diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 55a12f6795..32e5a934f6 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -82,10 +82,10 @@ void HttpResponse::validateResponse() const throw new DlAbortEx(EX_INVALID_RANGE_HEADER, Util::itos(httpRequest->getStartByte(), true).c_str(), Util::itos(httpRequest->getEndByte(), true).c_str(), - Util::itos(httpRequest->getEntityLength(), true).c_str(), + Util::uitos(httpRequest->getEntityLength(), true).c_str(), Util::itos(responseRange->getStartByte(), true).c_str(), Util::itos(responseRange->getEndByte(), true).c_str(), - Util::itos(responseRange->getEntityLength(), true).c_str()); + Util::uitos(responseRange->getEntityLength(), true).c_str()); } } } @@ -150,7 +150,7 @@ TransferEncodingHandle HttpResponse::getTransferDecoder() const return 0; } -int64_t HttpResponse::getContentLength() const +uint64_t HttpResponse::getContentLength() const { if(httpHeader.isNull()) { return 0; @@ -159,7 +159,7 @@ int64_t HttpResponse::getContentLength() const } } -int64_t HttpResponse::getEntityLength() const +uint64_t HttpResponse::getEntityLength() const { if(httpHeader.isNull()) { return 0; diff --git a/src/HttpResponse.h b/src/HttpResponse.h index cc467b8d17..57cfdd8301 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -49,7 +49,7 @@ class Logger; class HttpResponse { private: int32_t cuid; - int32_t status; + unsigned int status; SharedHandle httpRequest; SharedHandle httpHeader; const Logger* logger; @@ -85,9 +85,9 @@ class HttpResponse { SharedHandle getTransferDecoder() const; - int64_t getContentLength() const; + uint64_t getContentLength() const; - int64_t getEntityLength() const; + uint64_t getEntityLength() const; std::string getContentType() const; @@ -95,12 +95,12 @@ class HttpResponse { SharedHandle getHttpHeader() const; - void setStatus(int32_t status) + void setStatus(unsigned int status) { this->status = status; } - int32_t getStatus() const + unsigned int getStatus() const { return status; } diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index bcacbf2459..b4bb653a64 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -98,7 +98,7 @@ bool HttpResponseCommand::executeInternal() _requestGroup->removeURIWhoseHostnameIs(_requestGroup->searchServerHost(cuid)->getHostname()); } if(_requestGroup->getPieceStorage().isNull()) { - int64_t totalLength = httpResponse->getEntityLength(); + uint64_t totalLength = httpResponse->getEntityLength(); SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext(); dctx->setTotalLength(totalLength); dctx->setFilename(httpResponse->determinFilename()); diff --git a/src/InitiatorMSEHandshakeCommand.cc b/src/InitiatorMSEHandshakeCommand.cc index beb3dfaea9..38f3d6595a 100644 --- a/src/InitiatorMSEHandshakeCommand.cc +++ b/src/InitiatorMSEHandshakeCommand.cc @@ -143,7 +143,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() { return false; } -bool InitiatorMSEHandshakeCommand::prepareForNextPeer(int32_t wait) +bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait) { if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) { logger->info("CUID#%d - Establishing connection using legacy BitTorrent handshake is disabled by preference.", cuid); diff --git a/src/InitiatorMSEHandshakeCommand.h b/src/InitiatorMSEHandshakeCommand.h index a24e04e362..366e615d41 100644 --- a/src/InitiatorMSEHandshakeCommand.h +++ b/src/InitiatorMSEHandshakeCommand.h @@ -60,7 +60,7 @@ class InitiatorMSEHandshakeCommand : public PeerAbstractCommand, MSEHandshake* _mseHandshake; protected: virtual bool executeInternal(); - virtual bool prepareForNextPeer(int32_t wait); + virtual bool prepareForNextPeer(time_t wait); virtual void onAbort(Exception* ex); virtual bool exitBeforeExecute(); public: diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc index d5fdd1e5ca..c56ef4441e 100644 --- a/src/MSEHandshake.cc +++ b/src/MSEHandshake.cc @@ -91,7 +91,7 @@ MSEHandshake::HANDSHAKE_TYPE MSEHandshake::identifyHandshakeType() if(!_socket->isReadable(0)) { return HANDSHAKE_NOT_YET; } - int32_t r = 20-_rbufLength; + size_t r = 20-_rbufLength; _socket->readData(_rbuf+_rbufLength, r); if(r == 0) { throw new DlAbortEx(EX_EOF_FROM_PEER); @@ -134,7 +134,7 @@ void MSEHandshake::sendPublicKey() bool MSEHandshake::receivePublicKey() { - int32_t r = KEY_LENGTH-_rbufLength; + size_t r = KEY_LENGTH-_rbufLength; if(r > receiveNBytes(r)) { return false; } @@ -281,7 +281,7 @@ void MSEHandshake::sendInitiatorStep2() bool MSEHandshake::findInitiatorVCMarker() { // 616 is synchronization point of initiator - int32_t r = 616-KEY_LENGTH-_rbufLength; + size_t r = 616-KEY_LENGTH-_rbufLength; if(!_socket->isReadable(0)) { return false; } @@ -303,8 +303,8 @@ bool MSEHandshake::findInitiatorVCMarker() } } } - assert(_markerIndex+VC_LENGTH-_rbufLength <= (size_t)r); - int32_t toRead = _markerIndex+VC_LENGTH-_rbufLength; + assert(_markerIndex+VC_LENGTH-_rbufLength <= r); + size_t toRead = _markerIndex+VC_LENGTH-_rbufLength; _socket->readData(_rbuf+_rbufLength, toRead); _rbufLength += toRead; @@ -317,7 +317,7 @@ bool MSEHandshake::findInitiatorVCMarker() bool MSEHandshake::receiveInitiatorCryptoSelectAndPadDLength() { - int32_t r = CRYPTO_BITFIELD_LENGTH+2/* PadD length*/-_rbufLength; + size_t r = CRYPTO_BITFIELD_LENGTH+2/* PadD length*/-_rbufLength; if(r > receiveNBytes(r)) { return false; } @@ -353,7 +353,7 @@ bool MSEHandshake::receivePad() if(_padLength == 0) { return true; } - int32_t r = _padLength-_rbufLength; + size_t r = _padLength-_rbufLength; if(r > receiveNBytes(r)) { return false; } @@ -367,7 +367,7 @@ bool MSEHandshake::receivePad() bool MSEHandshake::findReceiverHashMarker() { // 628 is synchronization limit of receiver. - int32_t r = 628-KEY_LENGTH-_rbufLength; + size_t r = 628-KEY_LENGTH-_rbufLength; if(!_socket->isReadable(0)) { return false; } @@ -391,8 +391,8 @@ bool MSEHandshake::findReceiverHashMarker() } } } - assert(_markerIndex+20-_rbufLength <= (size_t)r); - int32_t toRead = _markerIndex+20-_rbufLength; + assert(_markerIndex+20-_rbufLength <= r); + size_t toRead = _markerIndex+20-_rbufLength; _socket->readData(_rbuf+_rbufLength, toRead); _rbufLength += toRead; @@ -405,7 +405,7 @@ bool MSEHandshake::findReceiverHashMarker() bool MSEHandshake::receiveReceiverHashAndPadCLength() { - int32_t r = 20+VC_LENGTH+CRYPTO_BITFIELD_LENGTH+2/*PadC length*/-_rbufLength; + size_t r = 20+VC_LENGTH+CRYPTO_BITFIELD_LENGTH+2/*PadC length*/-_rbufLength; if(r > receiveNBytes(r)) { return false; } @@ -462,7 +462,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength() bool MSEHandshake::receiveReceiverIALength() { - int32_t r = 2-_rbufLength; + size_t r = 2-_rbufLength; assert(r > 0); if(r > receiveNBytes(r)) { return false; @@ -479,7 +479,7 @@ bool MSEHandshake::receiveReceiverIA() if(_iaLength == 0) { return true; } - int32_t r = _iaLength-_rbufLength; + size_t r = _iaLength-_rbufLength; if(r > receiveNBytes(r)) { return false; } @@ -545,9 +545,9 @@ void MSEHandshake::verifyReq1Hash(const unsigned char* req1buf) } } -ssize_t MSEHandshake::receiveNBytes(size_t bytes) +size_t MSEHandshake::receiveNBytes(size_t bytes) { - int32_t r = bytes; + size_t r = bytes; if(r > 0) { if(!_socket->isReadable(0)) { return 0; diff --git a/src/MSEHandshake.h b/src/MSEHandshake.h index 8a416d342a..bb192a4304 100644 --- a/src/MSEHandshake.h +++ b/src/MSEHandshake.h @@ -122,7 +122,7 @@ class MSEHandshake { void verifyReq1Hash(const unsigned char* req1buf); - ssize_t receiveNBytes(size_t bytes); + size_t receiveNBytes(size_t bytes); public: MSEHandshake(int32_t cuid, const SharedHandle& socket, diff --git a/src/MessageDigestHelper.cc b/src/MessageDigestHelper.cc index 8d5eab5632..5e0d074505 100644 --- a/src/MessageDigestHelper.cc +++ b/src/MessageDigestHelper.cc @@ -58,8 +58,8 @@ void MessageDigestHelper::staticSHA1DigestFree() } std::string MessageDigestHelper::staticSHA1Digest(const BinaryStreamHandle& bs, - int64_t offset, - int64_t length) + off_t offset, + uint64_t length) { _sha1Ctx->digestReset(); return digest(_sha1Ctx, bs, offset, length); @@ -67,8 +67,8 @@ std::string MessageDigestHelper::staticSHA1Digest(const BinaryStreamHandle& bs, std::string MessageDigestHelper::digest(const std::string& algo, const BinaryStreamHandle& bs, - int64_t offset, - int64_t length) + off_t offset, + uint64_t length) { MessageDigestContext ctx; ctx.trySetAlgo(algo); @@ -78,23 +78,24 @@ std::string MessageDigestHelper::digest(const std::string& algo, std::string MessageDigestHelper::digest(MessageDigestContext* ctx, const SharedHandle& bs, - int64_t offset, int64_t length) + off_t offset, uint64_t length) { - int32_t BUFSIZE = 4096; + size_t BUFSIZE = 4096; unsigned char BUF[BUFSIZE]; - int64_t iteration = length/BUFSIZE; - int32_t tail = length%BUFSIZE; - for(int64_t i = 0; i < iteration; ++i) { - int32_t readLength = bs->readData(BUF, BUFSIZE, offset); - if(readLength != BUFSIZE) { + lldiv_t res = lldiv(length, BUFSIZE); + uint64_t iteration = res.quot; + size_t tail = res.rem; + for(uint64_t i = 0; i < iteration; ++i) { + ssize_t readLength = bs->readData(BUF, BUFSIZE, offset); + if((size_t)readLength != BUFSIZE) { throw new DlAbortEx(EX_FILE_READ, "n/a", strerror(errno)); } ctx->digestUpdate(BUF, readLength); offset += readLength; } if(tail) { - int32_t readLength = bs->readData(BUF, tail, offset); - if(readLength != tail) { + ssize_t readLength = bs->readData(BUF, tail, offset); + if((size_t)readLength != tail) { throw new DlAbortEx(EX_FILE_READ, "n/a", strerror(errno)); } ctx->digestUpdate(BUF, readLength); @@ -110,7 +111,7 @@ std::string MessageDigestHelper::digest(const std::string& algo, const std::stri return digest(algo, writer, 0, writer->size()); } -std::string MessageDigestHelper::digest(const std::string& algo, const void* data, int32_t length) +std::string MessageDigestHelper::digest(const std::string& algo, const void* data, size_t length) { MessageDigestContext ctx; ctx.trySetAlgo(algo); @@ -120,8 +121,8 @@ std::string MessageDigestHelper::digest(const std::string& algo, const void* dat return Util::toHex((const unsigned char*)rawMD.c_str(), rawMD.size()); } -void MessageDigestHelper::digest(unsigned char* md, int32_t mdLength, - const std::string& algo, const void* data, int32_t length) +void MessageDigestHelper::digest(unsigned char* md, size_t mdLength, + const std::string& algo, const void* data, size_t length) { if(mdLength < MessageDigestContext::digestLength(algo)) { throw new DlAbortEx("Insufficient space for storing message digest: %d required, but only %d is allocated", MessageDigestContext::digestLength(algo), mdLength); diff --git a/src/MessageDigestHelper.h b/src/MessageDigestHelper.h index 54cfa02804..4bf81ac68e 100644 --- a/src/MessageDigestHelper.h +++ b/src/MessageDigestHelper.h @@ -52,9 +52,9 @@ class MessageDigestHelper { * Returns message digest in hexadecimal representation. * Digest algorithm is specified by algo. */ - static std::string digest(const std::string& algo, const SharedHandle& bs, int64_t offset, int64_t length); + static std::string digest(const std::string& algo, const SharedHandle& bs, off_t offset, uint64_t length); - static std::string digest(const std::string& algo, const void* data, int32_t length); + static std::string digest(const std::string& algo, const void* data, size_t length); static std::string digestString(const std::string& algo, const std::string& data) { @@ -76,14 +76,14 @@ class MessageDigestHelper { static void staticSHA1DigestFree(); static std::string staticSHA1Digest(const SharedHandle& bs, - int64_t offset, int64_t length); + off_t offset, uint64_t length); /** * ctx must be initialized or reseted before calling this function. */ static std::string digest(MessageDigestContext* ctx, const SharedHandle& bs, - int64_t offset, int64_t length); + off_t offset, uint64_t length); /** * Calculates message digest of file denoted by filename. @@ -96,8 +96,8 @@ class MessageDigestHelper { * Stores *raw* message digest into md. * Throws exception when mdLength is less than the size of message digest. */ - static void digest(unsigned char* md, int32_t mdLength, - const std::string& algo, const void* data, int32_t length); + static void digest(unsigned char* md, size_t mdLength, + const std::string& algo, const void* data, size_t length); }; } // namespace aria2 diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 10536fd405..922a92becf 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -129,7 +129,7 @@ Metalink2RequestGroup::createRequestGroup(std::deque useIndex = false; } std::deque > groups; - int32_t count = 0; + unsigned int count = 0; for(std::deque >::iterator itr = entries.begin(); itr != entries.end(); itr++, ++count) { SharedHandle& entry = *itr; @@ -183,7 +183,7 @@ Metalink2RequestGroup::createRequestGroup(std::deque SharedHandle rg = new RequestGroup(_option, uris); // If piece hash is specified in the metalink, // make segment size equal to piece hash size. - int32_t pieceLength; + size_t pieceLength; #ifdef ENABLE_MESSAGE_DIGEST if(entry->chunkChecksum.isNull()) { pieceLength = _option->getAsInt(PREF_SEGMENT_SIZE); @@ -213,7 +213,7 @@ Metalink2RequestGroup::createRequestGroup(std::deque rg->setDownloadContext(dctx); rg->setNumConcurrentCommand(entry->maxConnections < 0 ? _option->getAsInt(PREF_METALINK_SERVERS) : - std::min(_option->getAsInt(PREF_METALINK_SERVERS), entry->maxConnections)); + std::min(_option->getAsInt(PREF_METALINK_SERVERS), entry->maxConnections)); // In metalink, multi connection to a single host is not allowed by default. rg->setSingleHostMultiConnectionEnabled(!_option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)); diff --git a/src/MetalinkEntry.cc b/src/MetalinkEntry.cc index 810681c71f..a7be88a01c 100644 --- a/src/MetalinkEntry.cc +++ b/src/MetalinkEntry.cc @@ -60,9 +60,9 @@ MetalinkEntry::~MetalinkEntry() {} class AddLocationPreference { private: std::deque _locations; - int32_t _preferenceToAdd; + int _preferenceToAdd; public: - AddLocationPreference(const std::deque& locations, int32_t preferenceToAdd): + AddLocationPreference(const std::deque& locations, int preferenceToAdd): _locations(locations), _preferenceToAdd(preferenceToAdd) { std::transform(_locations.begin(), _locations.end(), _locations.begin(), Util::toUpper); @@ -97,13 +97,13 @@ std::string MetalinkEntry::getPath() const return file->getPath(); } -int64_t MetalinkEntry::getLength() const +uint64_t MetalinkEntry::getLength() const { return file->getLength(); } void MetalinkEntry::setLocationPreference(const std::deque& locations, - int32_t preferenceToAdd) + int preferenceToAdd) { std::for_each(resources.begin(), resources.end(), AddLocationPreference(locations, preferenceToAdd)); @@ -112,9 +112,9 @@ void MetalinkEntry::setLocationPreference(const std::deque& locatio class AddProtocolPreference { private: const std::string& _protocol; - int32_t _preferenceToAdd; + int _preferenceToAdd; public: - AddProtocolPreference(const std::string& protocol, int32_t prefToAdd): + AddProtocolPreference(const std::string& protocol, int prefToAdd): _protocol(protocol), _preferenceToAdd(prefToAdd) {} void operator()(const SharedHandle& res) const @@ -126,7 +126,7 @@ class AddProtocolPreference { }; void MetalinkEntry::setProtocolPreference(const std::string& protocol, - int32_t preferenceToAdd) + int preferenceToAdd) { std::for_each(resources.begin(), resources.end(), AddProtocolPreference(protocol, preferenceToAdd)); diff --git a/src/MetalinkEntry.h b/src/MetalinkEntry.h index c182e4b707..c73174e874 100644 --- a/src/MetalinkEntry.h +++ b/src/MetalinkEntry.h @@ -56,7 +56,7 @@ class MetalinkEntry { std::string language; std::string os; std::deque > resources; - int32_t maxConnections; + int maxConnections; #ifdef ENABLE_MESSAGE_DIGEST SharedHandle checksum; SharedHandle chunkChecksum; @@ -70,7 +70,7 @@ class MetalinkEntry { std::string getPath() const; - int64_t getLength() const; + uint64_t getLength() const; SharedHandle getFile() const; @@ -78,8 +78,8 @@ class MetalinkEntry { void reorderResourcesByPreference(); - void setLocationPreference(const std::deque& locations, int32_t preferenceToAdd); - void setProtocolPreference(const std::string& protocol, int32_t preferenceToAdd); + void setLocationPreference(const std::deque& locations, int preferenceToAdd); + void setProtocolPreference(const std::string& protocol, int preferenceToAdd); static std::deque > toFileEntry(const std::deque >& metalinkEntries); diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc index 50c1d7eae0..2f9ed33545 100644 --- a/src/MetalinkParserController.cc +++ b/src/MetalinkParserController.cc @@ -87,7 +87,7 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename) } } -void MetalinkParserController::setFileLengthOfEntry(int64_t length) +void MetalinkParserController::setFileLengthOfEntry(uint64_t length) { if(_tEntry.isNull()) { return; @@ -123,7 +123,7 @@ void MetalinkParserController::setOSOfEntry(const std::string& os) _tEntry->os = os; } -void MetalinkParserController::setMaxConnectionsOfEntry(int32_t maxConnections) +void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections) { if(_tEntry.isNull()) { return; @@ -193,7 +193,7 @@ void MetalinkParserController::setLocationOfResource(const std::string& location _tResource->location = location; } -void MetalinkParserController::setPreferenceOfResource(int32_t preference) +void MetalinkParserController::setPreferenceOfResource(int preference) { if(_tResource.isNull()) { return; @@ -201,7 +201,7 @@ void MetalinkParserController::setPreferenceOfResource(int32_t preference) _tResource->preference = preference; } -void MetalinkParserController::setMaxConnectionsOfResource(int32_t maxConnections) +void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections) { if(_tResource.isNull()) { return; @@ -302,7 +302,7 @@ void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type) #endif // ENABLE_MESSAGE_DIGEST } -void MetalinkParserController::setLengthOfChunkChecksum(int32_t length) +void MetalinkParserController::setLengthOfChunkChecksum(size_t length) { #ifdef ENABLE_MESSAGE_DIGEST if(_tChunkChecksum.isNull()) { @@ -316,17 +316,17 @@ void MetalinkParserController::setLengthOfChunkChecksum(int32_t length) #endif // ENABLE_MESSAGE_DIGEST } -void MetalinkParserController::addHashOfChunkChecksum(int32_t order, const std::string& md) +void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::string& md) { #ifdef ENABLE_MESSAGE_DIGEST if(_tChunkChecksum.isNull()) { return; } - _tempChunkChecksums.push_back(std::pair(order, md)); + _tempChunkChecksums.push_back(std::pair(order, md)); #endif // ENABLE_MESSAGE_DIGEST } -void MetalinkParserController::createNewHashOfChunkChecksum(int32_t order) +void MetalinkParserController::createNewHashOfChunkChecksum(size_t order) { #ifdef ENABLE_MESSAGE_DIGEST if(_tChunkChecksum.isNull()) { @@ -363,10 +363,10 @@ void MetalinkParserController::commitChunkChecksumTransaction() return; } if(_tEntry->chunkChecksum.isNull() || _tEntry->chunkChecksum->getAlgo() != "sha1") { - std::sort(_tempChunkChecksums.begin(), _tempChunkChecksums.end(), Ascend1st >()); + std::sort(_tempChunkChecksums.begin(), _tempChunkChecksums.end(), Ascend1st >()); std::deque checksums; std::transform(_tempChunkChecksums.begin(), _tempChunkChecksums.end(), - std::back_inserter(checksums), select2nd >()); + std::back_inserter(checksums), select2nd >()); _tChunkChecksum->setChecksums(checksums); _tEntry->chunkChecksum = _tChunkChecksum; } diff --git a/src/MetalinkParserController.h b/src/MetalinkParserController.h index ab2a595214..6371d2df0c 100644 --- a/src/MetalinkParserController.h +++ b/src/MetalinkParserController.h @@ -65,9 +65,9 @@ class MetalinkParserController { SharedHandle _tChunkChecksum; - std::deque > _tempChunkChecksums; + std::deque > _tempChunkChecksums; - std::pair _tempHashPair; + std::pair _tempHashPair; #endif // ENABLE_MESSAGE_DIGEST public: @@ -81,7 +81,7 @@ class MetalinkParserController { void setFileNameOfEntry(const std::string& filename); - void setFileLengthOfEntry(int64_t length); + void setFileLengthOfEntry(uint64_t length); void setVersionOfEntry(const std::string& version); @@ -89,7 +89,7 @@ class MetalinkParserController { void setOSOfEntry(const std::string& os); - void setMaxConnectionsOfEntry(int32_t maxConnections); + void setMaxConnectionsOfEntry(int maxConnections); void commitEntryTransaction(); @@ -103,9 +103,9 @@ class MetalinkParserController { void setLocationOfResource(const std::string& location); - void setPreferenceOfResource(int32_t preference); + void setPreferenceOfResource(int preference); - void setMaxConnectionsOfResource(int32_t maxConnections); + void setMaxConnectionsOfResource(int maxConnections); void commitResourceTransaction(); @@ -125,11 +125,11 @@ class MetalinkParserController { void setTypeOfChunkChecksum(const std::string& type); - void setLengthOfChunkChecksum(int32_t length); + void setLengthOfChunkChecksum(size_t length); - void addHashOfChunkChecksum(int32_t order, const std::string& md); + void addHashOfChunkChecksum(size_t order, const std::string& md); - void createNewHashOfChunkChecksum(int32_t order); + void createNewHashOfChunkChecksum(size_t order); void setMessageDigestOfChunkChecksum(const std::string& md); diff --git a/src/MetalinkParserStateMachine.cc b/src/MetalinkParserStateMachine.cc index 990f14369f..c623b4d509 100644 --- a/src/MetalinkParserStateMachine.cc +++ b/src/MetalinkParserStateMachine.cc @@ -178,7 +178,7 @@ void MetalinkParserStateMachine::setFileNameOfEntry(const std::string& filename) _ctrl->setFileNameOfEntry(filename); } -void MetalinkParserStateMachine::setFileLengthOfEntry(int64_t length) +void MetalinkParserStateMachine::setFileLengthOfEntry(uint64_t length) { _ctrl->setFileLengthOfEntry(length); } @@ -198,7 +198,7 @@ void MetalinkParserStateMachine::setOSOfEntry(const std::string& os) _ctrl->setOSOfEntry(os); } -void MetalinkParserStateMachine::setMaxConnectionsOfEntry(int32_t maxConnections) +void MetalinkParserStateMachine::setMaxConnectionsOfEntry(int maxConnections) { _ctrl->setMaxConnectionsOfEntry(maxConnections); } @@ -228,12 +228,12 @@ void MetalinkParserStateMachine::setLocationOfResource(const std::string& locati _ctrl->setLocationOfResource(location); } -void MetalinkParserStateMachine::setPreferenceOfResource(int32_t preference) +void MetalinkParserStateMachine::setPreferenceOfResource(int preference) { _ctrl->setPreferenceOfResource(preference); } -void MetalinkParserStateMachine::setMaxConnectionsOfResource(int32_t maxConnections) +void MetalinkParserStateMachine::setMaxConnectionsOfResource(int maxConnections) { _ctrl->setMaxConnectionsOfResource(maxConnections); } @@ -278,7 +278,7 @@ void MetalinkParserStateMachine::newChunkChecksumTransaction() _ctrl->newChunkChecksumTransaction(); } -void MetalinkParserStateMachine::setLengthOfChunkChecksum(int32_t length) +void MetalinkParserStateMachine::setLengthOfChunkChecksum(size_t length) { _ctrl->setLengthOfChunkChecksum(length); } @@ -288,7 +288,7 @@ void MetalinkParserStateMachine::setTypeOfChunkChecksum(const std::string& type) _ctrl->setTypeOfChunkChecksum(type); } -void MetalinkParserStateMachine::createNewHashOfChunkChecksum(int32_t order) +void MetalinkParserStateMachine::createNewHashOfChunkChecksum(size_t order) { _ctrl->createNewHashOfChunkChecksum(order); } diff --git a/src/MetalinkParserStateMachine.h b/src/MetalinkParserStateMachine.h index 501de16d35..174774f455 100644 --- a/src/MetalinkParserStateMachine.h +++ b/src/MetalinkParserStateMachine.h @@ -119,7 +119,7 @@ class MetalinkParserStateMachine { void setFileNameOfEntry(const std::string& filename); - void setFileLengthOfEntry(int64_t length); + void setFileLengthOfEntry(uint64_t length); void setVersionOfEntry(const std::string& version); @@ -127,7 +127,7 @@ class MetalinkParserStateMachine { void setOSOfEntry(const std::string& os); - void setMaxConnectionsOfEntry(int32_t maxConnections); + void setMaxConnectionsOfEntry(int maxConnections); void commitEntryTransaction(); @@ -139,9 +139,9 @@ class MetalinkParserStateMachine { void setLocationOfResource(const std::string& location); - void setPreferenceOfResource(int32_t preference); + void setPreferenceOfResource(int preference); - void setMaxConnectionsOfResource(int32_t maxConnections); + void setMaxConnectionsOfResource(int maxConnections); void commitResourceTransaction(); @@ -159,11 +159,11 @@ class MetalinkParserStateMachine { void newChunkChecksumTransaction(); - void setLengthOfChunkChecksum(int32_t length); + void setLengthOfChunkChecksum(size_t length); void setTypeOfChunkChecksum(const std::string& type); - void createNewHashOfChunkChecksum(int32_t order); + void createNewHashOfChunkChecksum(size_t order); void setMessageDigestOfChunkChecksum(const std::string& md); diff --git a/src/MetalinkResource.h b/src/MetalinkResource.h index f3e1d2b730..b2afdb4eee 100644 --- a/src/MetalinkResource.h +++ b/src/MetalinkResource.h @@ -55,8 +55,8 @@ class MetalinkResource { std::string url; TYPE type; std::string location; - int32_t preference; - int32_t maxConnections; + int preference; + int maxConnections; public: MetalinkResource(); ~MetalinkResource(); diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 223c33dff1..3f0f043d0a 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -80,7 +80,7 @@ bool DiskWriterEntry::fileExists(const std::string& topDir) return File(getFilePath(topDir)).exists(); } -int64_t DiskWriterEntry::size() const +uint64_t DiskWriterEntry::size() const { return diskWriter->size(); } @@ -182,16 +182,16 @@ void MultiDiskAdaptor::onDownloadComplete() openFile(); } -void MultiDiskAdaptor::writeData(const unsigned char* data, int32_t len, - int64_t offset) +void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len, + off_t offset) { - int64_t fileOffset = offset; + off_t fileOffset = offset; bool writing = false; - int32_t rem = len; + size_t rem = len; for(DiskWriterEntries::iterator itr = diskWriterEntries.begin(); itr != diskWriterEntries.end() && rem != 0; itr++) { if(isInRange(*itr, offset) || writing) { - int32_t writeLength = calculateLength(*itr, fileOffset, rem); + size_t writeLength = calculateLength(*itr, fileOffset, rem); (*itr)->getDiskWriter()->writeData(data+(len-rem), writeLength, fileOffset); rem -= writeLength; writing = true; @@ -206,18 +206,18 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, int32_t len, } bool MultiDiskAdaptor::isInRange(const DiskWriterEntryHandle entry, - int64_t offset) const + off_t offset) const { return entry->getFileEntry()->getOffset() <= offset && - offset < entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength(); + (uint64_t)offset < entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength(); } -int32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry, - int64_t fileOffset, - int32_t rem) const +size_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry, + off_t fileOffset, + size_t rem) const { - int32_t length; - if(entry->getFileEntry()->getLength() < fileOffset+rem) { + size_t length; + if(entry->getFileEntry()->getLength() < (uint64_t)fileOffset+rem) { length = entry->getFileEntry()->getLength()-fileOffset; } else { length = rem; @@ -225,16 +225,16 @@ int32_t MultiDiskAdaptor::calculateLength(const DiskWriterEntryHandle entry, return length; } -int32_t MultiDiskAdaptor::readData(unsigned char* data, int32_t len, int64_t offset) +ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset) { - int64_t fileOffset = offset; + off_t fileOffset = offset; bool reading = false; - int32_t rem = len; - int32_t totalReadLength = 0; + size_t rem = len; + size_t totalReadLength = 0; for(DiskWriterEntries::iterator itr = diskWriterEntries.begin(); itr != diskWriterEntries.end() && rem != 0; itr++) { if(isInRange(*itr, offset) || reading) { - int32_t readLength = calculateLength((*itr), fileOffset, rem); + size_t readLength = calculateLength((*itr), fileOffset, rem); totalReadLength += (*itr)->getDiskWriter()->readData(data+(len-rem), readLength, fileOffset); rem -= readLength; reading = true; @@ -264,9 +264,9 @@ bool MultiDiskAdaptor::fileExists() } // TODO call DiskWriter::openFile() before calling this function. -int64_t MultiDiskAdaptor::size() const +uint64_t MultiDiskAdaptor::size() const { - int64_t size = 0; + uint64_t size = 0; for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(); itr != diskWriterEntries.end(); itr++) { size += (*itr)->size(); diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index 713a47512d..c4f298bab9 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -64,7 +64,7 @@ class DiskWriterEntry { bool fileExists(const std::string& topDir); - int64_t size() const; + uint64_t size() const; SharedHandle getFileEntry() const; @@ -83,7 +83,7 @@ class MultiDiskAdaptor : public DiskAdaptor { friend class MultiFileAllocationIterator; private: std::string topDir; - int32_t pieceLength; + size_t pieceLength; DiskWriterEntries diskWriterEntries; bool _directIOAllowed; @@ -92,11 +92,11 @@ class MultiDiskAdaptor : public DiskAdaptor { void mkdir() const; - bool isInRange(const DiskWriterEntryHandle entry, int64_t offset) const; + bool isInRange(const DiskWriterEntryHandle entry, off_t offset) const; - int32_t calculateLength(const DiskWriterEntryHandle entry, - int64_t fileOffset, - int32_t rem) const; + size_t calculateLength(const DiskWriterEntryHandle entry, + off_t fileOffset, + size_t rem) const; std::string getTopDirPath() const; public: @@ -114,10 +114,10 @@ class MultiDiskAdaptor : public DiskAdaptor { virtual void onDownloadComplete(); - virtual void writeData(const unsigned char* data, int32_t len, - int64_t offset); + virtual void writeData(const unsigned char* data, size_t len, + off_t offset); - virtual int32_t readData(unsigned char* data, int32_t len, int64_t offset); + virtual ssize_t readData(unsigned char* data, size_t len, off_t offset); virtual bool fileExists(); @@ -126,7 +126,7 @@ class MultiDiskAdaptor : public DiskAdaptor { return getTopDirPath(); } - virtual int64_t size() const; + virtual uint64_t size() const; virtual SharedHandle fileAllocationIterator(); @@ -142,11 +142,11 @@ class MultiDiskAdaptor : public DiskAdaptor { return topDir; } - void setPieceLength(int32_t pieceLength) { + void setPieceLength(size_t pieceLength) { this->pieceLength = pieceLength; } - int32_t getPieceLength() const { + size_t getPieceLength() const { return pieceLength; } diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc index 6828a2c453..e4125b35f2 100644 --- a/src/MultiFileAllocationIterator.cc +++ b/src/MultiFileAllocationIterator.cc @@ -79,7 +79,7 @@ bool MultiFileAllocationIterator::finished() return _entries.empty() && (_fileAllocationIterator.isNull() || _fileAllocationIterator->finished()); } -int64_t MultiFileAllocationIterator::getCurrentLength() +off_t MultiFileAllocationIterator::getCurrentLength() { if(_fileAllocationIterator.isNull()) { return 0; @@ -88,7 +88,7 @@ int64_t MultiFileAllocationIterator::getCurrentLength() } } -int64_t MultiFileAllocationIterator::getTotalLength() +uint64_t MultiFileAllocationIterator::getTotalLength() { if(_fileAllocationIterator.isNull()) { return 0; @@ -102,7 +102,7 @@ const DiskWriterEntries& MultiFileAllocationIterator::getDiskWriterEntries() con return _entries; } -DiskWriterEntries MultiFileAllocationIterator::makeDiskWriterEntries(const DiskWriterEntries& srcEntries, int32_t pieceLength) const +DiskWriterEntries MultiFileAllocationIterator::makeDiskWriterEntries(const DiskWriterEntries& srcEntries, size_t pieceLength) const { if(pieceLength == 0) { DiskWriterEntries entries; @@ -122,9 +122,9 @@ DiskWriterEntries MultiFileAllocationIterator::makeDiskWriterEntries(const DiskW if(!fileEntry->isRequested()) { continue; } - int64_t pieceStartOffset = (fileEntry->getOffset()/pieceLength)*pieceLength; + off_t pieceStartOffset = (fileEntry->getOffset()/pieceLength)*pieceLength; for(DiskWriterEntries::const_iterator i = itr-1; i != done; --i) { - if(pieceStartOffset < (*i)->getFileEntry()->getOffset()+(*i)->getFileEntry()->getLength()) { + if((uint64_t)pieceStartOffset < (*i)->getFileEntry()->getOffset()+(*i)->getFileEntry()->getLength()) { entries.push_back(*i); } else { break; diff --git a/src/MultiFileAllocationIterator.h b/src/MultiFileAllocationIterator.h index 4e79b599e0..339067f651 100644 --- a/src/MultiFileAllocationIterator.h +++ b/src/MultiFileAllocationIterator.h @@ -50,11 +50,11 @@ class MultiFileAllocationIterator:public FileAllocationIterator MultiDiskAdaptor* _diskAdaptor; std::deque > _entries; SharedHandle _fileAllocationIterator; - int64_t _offset; + off_t _offset; std::deque > makeDiskWriterEntries(const std::deque >& srcEntries, - int32_t pieceLength) const; + size_t pieceLength) const; public: MultiFileAllocationIterator(MultiDiskAdaptor* diskAdaptor); @@ -64,9 +64,9 @@ class MultiFileAllocationIterator:public FileAllocationIterator virtual bool finished(); - virtual int64_t getCurrentLength(); + virtual off_t getCurrentLength(); - virtual int64_t getTotalLength(); + virtual uint64_t getTotalLength(); const std::deque >& getDiskWriterEntries() const; }; diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index f31b0730a2..794fa7d054 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -81,13 +81,13 @@ void MultiUrlRequestInfo::printMessageForContinue() << "\n"; } -int32_t MultiUrlRequestInfo::execute() +int MultiUrlRequestInfo::execute() { { DNSCacheHandle dnsCache = new SimpleDNSCache(); DNSCacheSingletonHolder::instance(dnsCache); } - int32_t returnValue = 0; + int returnValue = 0; try { DownloadEngineHandle e = DownloadEngineFactory().newDownloadEngine(_option, _requestGroups); diff --git a/src/MultiUrlRequestInfo.h b/src/MultiUrlRequestInfo.h index 07ed6176c3..fdc44d201d 100644 --- a/src/MultiUrlRequestInfo.h +++ b/src/MultiUrlRequestInfo.h @@ -63,7 +63,7 @@ class MultiUrlRequestInfo { /** * Returns 0 if all downloads have completed, otherwise returns 1. */ - int32_t execute(); + int execute(); }; typedef SharedHandle MultiUrlRequestInfoHandle; diff --git a/src/NameResolver.h b/src/NameResolver.h index 9b42fc199c..203496babf 100644 --- a/src/NameResolver.h +++ b/src/NameResolver.h @@ -109,7 +109,7 @@ class NameResolver { return status; } - int32_t getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const { + int getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const { return ares_fds(channel, rfdsPtr, wfdsPtr); } diff --git a/src/NumberDecorator.h b/src/NumberDecorator.h index 4b70851c68..937a207793 100644 --- a/src/NumberDecorator.h +++ b/src/NumberDecorator.h @@ -45,7 +45,7 @@ class NumberDecorator { public: virtual ~NumberDecorator() {} - virtual std::string decorate(int32_t number) = 0; + virtual std::string decorate(unsigned int number) = 0; }; typedef SharedHandle NumberDecoratorHandle; diff --git a/src/Option.h b/src/Option.h index 78cdccbb16..aa4ca1e825 100644 --- a/src/Option.h +++ b/src/Option.h @@ -51,7 +51,7 @@ class Option { void put(const std::string& name, const std::string& value); bool defined(const std::string& name) const; std::string get(const std::string& name) const; - int32_t getAsInt(const std::string& name) const; + int getAsInt(const std::string& name) const; int64_t getAsLLInt(const std::string& name) const; bool getAsBool(const std::string& name) const; double getAsDouble(const std::string& name) const; diff --git a/src/PStringNumLoop.h b/src/PStringNumLoop.h index b8c0d0cb0e..3aa29254d5 100644 --- a/src/PStringNumLoop.h +++ b/src/PStringNumLoop.h @@ -45,18 +45,18 @@ class PStringNumLoop : public PStringDatum { private: - int32_t _startValue; + int _startValue; - int32_t _endValue; + int _endValue; - int32_t _step; + unsigned int _step; NumberDecoratorHandle _numberDecorator; PStringDatumHandle _next; public: - PStringNumLoop(int32_t startValue, int32_t endValue, int32_t step, + PStringNumLoop(int startValue, int endValue, unsigned int step, const NumberDecoratorHandle& nd, const PStringDatumHandle& next = 0): _startValue(startValue), @@ -69,7 +69,7 @@ class PStringNumLoop : public PStringDatum virtual void accept(PStringVisitor* visitor) { - for(int32_t i = _startValue; i <= _endValue; i += _step) { + for(int i = _startValue; i <= _endValue; i += _step) { PStringSegment(_numberDecorator->decorate(i), _next).accept(visitor); } } @@ -79,17 +79,17 @@ class PStringNumLoop : public PStringDatum return _next; } - int32_t getStartValue() const + int getStartValue() const { return _startValue; } - int32_t getEndValue() const + int getEndValue() const { return _endValue; } - int32_t getStep() const + unsigned int getStep() const { return _step; } diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc index d04eecbc8d..6d46ef6656 100644 --- a/src/ParameterizedStringParser.cc +++ b/src/ParameterizedStringParser.cc @@ -52,7 +52,7 @@ PStringDatumHandle ParameterizedStringParser::parse(const std::string& src) } PStringDatumHandle ParameterizedStringParser::diggPString(const std::string& src, - int32_t& offset) + int& offset) { if(src.size() == (size_t)offset) { return 0; @@ -68,7 +68,7 @@ PStringDatumHandle ParameterizedStringParser::diggPString(const std::string& src } PStringDatumHandle ParameterizedStringParser::createSegment(const std::string& src, - int32_t& offset) + int& offset) { std::string::size_type nextDelimiterIndex = src.find_first_of("[{", offset); if(nextDelimiterIndex == std::string::npos) { @@ -81,7 +81,7 @@ PStringDatumHandle ParameterizedStringParser::createSegment(const std::string& s } PStringDatumHandle ParameterizedStringParser::createSelect(const std::string& src, - int32_t& offset) + int& offset) { ++offset; std::string::size_type rightParenIndex = src.find("}", offset); @@ -99,7 +99,7 @@ PStringDatumHandle ParameterizedStringParser::createSelect(const std::string& sr } PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src, - int32_t& offset) + int& offset) { ++offset; std::string::size_type rightParenIndex = src.find("]", offset); @@ -109,7 +109,7 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src, std::string loopStr = src.substr(offset, rightParenIndex-offset); offset = rightParenIndex+1; - int32_t step = 1; + unsigned int step = 1; std::string::size_type colonIndex = loopStr.find(":"); if(colonIndex != std::string::npos) { std::string stepStr = loopStr.substr(colonIndex+1); @@ -125,8 +125,8 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src, throw new FatalException("Loop range missing."); } NumberDecoratorHandle nd = 0; - int32_t start; - int32_t end; + int start; + int end; if(Util::isNumber(range.first) && Util::isNumber(range.second)) { nd = new FixedWidthNumberDecorator(range.first.size()); start = Util::parseInt(range.first); diff --git a/src/ParameterizedStringParser.h b/src/ParameterizedStringParser.h index 07aa98d5e4..77dd6804c6 100644 --- a/src/ParameterizedStringParser.h +++ b/src/ParameterizedStringParser.h @@ -42,13 +42,13 @@ namespace aria2 { class ParameterizedStringParser { private: - SharedHandle diggPString(const std::string& src, int32_t& offset); + SharedHandle diggPString(const std::string& src, int& offset); - SharedHandle createSegment(const std::string& src, int32_t& offset); + SharedHandle createSegment(const std::string& src, int& offset); - SharedHandle createLoop(const std::string& src, int32_t& offset); + SharedHandle createLoop(const std::string& src, int& offset); - SharedHandle createSelect(const std::string& src, int32_t& offset); + SharedHandle createSelect(const std::string& src, int& offset); public: diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index a379384387..0595954db0 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -102,7 +102,7 @@ bool PeerAbstractCommand::execute() { } // TODO this method removed when PeerBalancerCommand is implemented -bool PeerAbstractCommand::prepareForNextPeer(int32_t wait) { +bool PeerAbstractCommand::prepareForNextPeer(time_t wait) { return true; } @@ -158,7 +158,7 @@ void PeerAbstractCommand::setWriteCheckSocket(const SocketHandle& socket) { } } -void PeerAbstractCommand::setUploadLimit(int32_t uploadLimit) { +void PeerAbstractCommand::setUploadLimit(unsigned int uploadLimit) { this->uploadLimit = uploadLimit; } diff --git a/src/PeerAbstractCommand.h b/src/PeerAbstractCommand.h index 4e532ada5e..2edbc6a36f 100644 --- a/src/PeerAbstractCommand.h +++ b/src/PeerAbstractCommand.h @@ -49,14 +49,14 @@ class SocketCore; class PeerAbstractCommand : public Command { private: Time checkPoint; - int32_t timeout; + time_t timeout; protected: DownloadEngine* e; SharedHandle socket; SharedHandle peer; - void setTimeout(int32_t timeout) { this->timeout = timeout; } - virtual bool prepareForNextPeer(int32_t wait); + void setTimeout(time_t timeout) { this->timeout = timeout; } + virtual bool prepareForNextPeer(time_t wait); virtual void onAbort(Exception* ex) {}; virtual bool exitBeforeExecute() = 0; virtual bool executeInternal() = 0; @@ -64,7 +64,7 @@ class PeerAbstractCommand : public Command { void setWriteCheckSocket(const SharedHandle& socket); void disableReadCheckSocket(); void disableWriteCheckSocket(); - void setUploadLimit(int32_t uploadLimit); + void setUploadLimit(unsigned int uploadLimit); void setUploadLimitCheck(bool check); void setNoCheck(bool check); void updateKeepAlive(); @@ -74,7 +74,7 @@ class PeerAbstractCommand : public Command { SharedHandle readCheckTarget; SharedHandle writeCheckTarget; bool uploadLimitCheck; - int32_t uploadLimit; + unsigned int uploadLimit; bool noCheck; public: PeerAbstractCommand(int32_t cuid, diff --git a/src/PeerChokeCommand.cc b/src/PeerChokeCommand.cc index 2575a43aeb..a175e79ed8 100644 --- a/src/PeerChokeCommand.cc +++ b/src/PeerChokeCommand.cc @@ -49,7 +49,7 @@ PeerChokeCommand::PeerChokeCommand(int32_t cuid, RequestGroup* requestGroup, DownloadEngine* e, const BtContextHandle& btContext, - int32_t interval): + time_t interval): Command(cuid), BtContextAwareCommand(btContext), RequestGroupAware(requestGroup), @@ -73,7 +73,7 @@ void PeerChokeCommand::optUnchokingPeer(Peers& peers) const { return; } std::random_shuffle(peers.begin(), peers.end()); - int32_t optUnchokCount = 1; + unsigned int optUnchokCount = 1; for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) { Peers::value_type peer = *itr; if(optUnchokCount > 0 && !peer->snubbing()) { @@ -122,7 +122,7 @@ bool PeerChokeCommand::execute() { } else { orderByDownloadRate(peers); } - int32_t unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size(); + unsigned int unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size(); for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) { PeerHandle peer = *itr; if(peer->peerInterested() && !peer->snubbing()) { diff --git a/src/PeerChokeCommand.h b/src/PeerChokeCommand.h index c51df91af8..467f88b8ee 100644 --- a/src/PeerChokeCommand.h +++ b/src/PeerChokeCommand.h @@ -50,9 +50,9 @@ class PeerChokeCommand : public Command, public RequestGroupAware { private: - int32_t interval; + time_t interval; DownloadEngine* e; - int32_t rotate; + unsigned int rotate; Time checkPoint; void orderByUploadRate(std::deque >& peers) const; @@ -64,7 +64,7 @@ class PeerChokeCommand : public Command, RequestGroup* requestGroup, DownloadEngine* e, const SharedHandle& btContext, - int32_t interval); + time_t interval); virtual ~PeerChokeCommand(); diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc index aaffe8dab5..fcc62c37b0 100644 --- a/src/PeerConnection.cc +++ b/src/PeerConnection.cc @@ -65,28 +65,28 @@ PeerConnection::PeerConnection(int32_t cuid, PeerConnection::~PeerConnection() {} -int32_t PeerConnection::sendMessage(const unsigned char* data, int32_t dataLength) { - int32_t writtenLength = 0; +ssize_t PeerConnection::sendMessage(const unsigned char* data, size_t dataLength) { if(socket->isWritable(0)) { // TODO fix this sendData(data, dataLength, _encryptionEnabled); - writtenLength += dataLength; + return dataLength; + } else { + return 0; } - return writtenLength; } -bool PeerConnection::receiveMessage(unsigned char* data, int32_t& dataLength) { +bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) { if(resbufLength == 0 && 4 > lenbufLength) { if(!socket->isReadable(0)) { return false; } // read payload size, 32bit unsigned integer - int32_t remaining = 4-lenbufLength; - int32_t temp = remaining; + size_t remaining = 4-lenbufLength; + size_t temp = remaining; readData(lenbuf+lenbufLength, remaining, _encryptionEnabled); if(remaining == 0) { // we got EOF - logger->debug("CUID#%d - In PeerConnection::receiveMessage(), remain=%d", + logger->debug("CUID#%d - In PeerConnection::receiveMessage(), remain=%zu", cuid, temp); throw new DlAbortEx(EX_EOF_FROM_PEER); } @@ -105,13 +105,13 @@ bool PeerConnection::receiveMessage(unsigned char* data, int32_t& dataLength) { return false; } // we have currentPayloadLen-resbufLen bytes to read - int32_t remaining = currentPayloadLength-resbufLength; - int32_t temp = remaining; + size_t remaining = currentPayloadLength-resbufLength; + size_t temp = remaining; if(remaining > 0) { readData(resbuf+resbufLength, remaining, _encryptionEnabled); if(remaining == 0) { // we got EOF - logger->debug("CUID#%d - In PeerConnection::receiveMessage(), payloadlen=%d, remaining=%d", + logger->debug("CUID#%d - In PeerConnection::receiveMessage(), payloadlen=%zu, remaining=%zu", cuid, currentPayloadLength, temp); throw new DlAbortEx(EX_EOF_FROM_PEER); } @@ -129,20 +129,20 @@ bool PeerConnection::receiveMessage(unsigned char* data, int32_t& dataLength) { return true; } -bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength, +bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength, bool peek) { - int32_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength; + size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength; if(remaining > 0 && !socket->isReadable(0)) { dataLength = 0; return false; } bool retval = true; if(remaining > 0) { - int32_t temp = remaining; + size_t temp = remaining; readData(resbuf+resbufLength, remaining, _encryptionEnabled); if(remaining == 0) { // we got EOF - logger->debug("CUID#%d - In PeerConnection::receiveHandshake(), remain=%d", + logger->debug("CUID#%d - In PeerConnection::receiveHandshake(), remain=%zu", cuid, temp); throw new DlAbortEx(EX_EOF_FROM_PEER); } @@ -151,7 +151,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength, retval = false; } } - int32_t writeLength = resbufLength > dataLength ? dataLength : resbufLength; + size_t writeLength = std::min(resbufLength, dataLength); memcpy(data, resbuf, writeLength); dataLength = writeLength; if(retval && !peek) { @@ -160,7 +160,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength, return retval; } -void PeerConnection::readData(unsigned char* data, int32_t& length, bool encryption) +void PeerConnection::readData(unsigned char* data, size_t& length, bool encryption) { if(encryption) { unsigned char temp[MAX_PAYLOAD_LEN]; diff --git a/src/PeerConnection.h b/src/PeerConnection.h index 346a2e8e58..664291f466 100644 --- a/src/PeerConnection.h +++ b/src/PeerConnection.h @@ -58,16 +58,16 @@ class PeerConnection { const Logger* logger; unsigned char resbuf[MAX_PAYLOAD_LEN]; - int32_t resbufLength; - int32_t currentPayloadLength; + size_t resbufLength; + size_t currentPayloadLength; unsigned char lenbuf[4]; - int32_t lenbufLength; + size_t lenbufLength; bool _encryptionEnabled; SharedHandle _encryptor; SharedHandle _decryptor; - void readData(unsigned char* data, int32_t& length, bool encryption); + void readData(unsigned char* data, size_t& length, bool encryption); void sendData(const unsigned char* data, size_t length, bool encryption); @@ -77,9 +77,9 @@ class PeerConnection { ~PeerConnection(); // Returns the number of bytes written - int32_t sendMessage(const unsigned char* data, int32_t dataLength); + ssize_t sendMessage(const unsigned char* data, size_t dataLength); - bool receiveMessage(unsigned char* data, int32_t& dataLength); + bool receiveMessage(unsigned char* data, size_t& dataLength); /** * Returns true if a handshake message is fully received, otherwise returns @@ -87,7 +87,7 @@ class PeerConnection { * In both cases, 'msg' is filled with received bytes and the filled length * is assigned to 'length'. */ - bool receiveHandshake(unsigned char* data, int32_t& dataLength, bool peek = false); + bool receiveHandshake(unsigned char* data, size_t& dataLength, bool peek = false); void enableEncryption(const SharedHandle& encryptor, const SharedHandle& decryptor); diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index 498af65e98..ac3282dcdc 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/src/PeerInitiateConnectionCommand.cc @@ -91,7 +91,7 @@ bool PeerInitiateConnectionCommand::executeInternal() { } // TODO this method removed when PeerBalancerCommand is implemented -bool PeerInitiateConnectionCommand::prepareForNextPeer(int wait) { +bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { PeerHandle peer = peerStorage->getUnusedPeer(); peer->usedBy(CUIDCounterSingletonHolder::instance()->newID()); diff --git a/src/PeerInitiateConnectionCommand.h b/src/PeerInitiateConnectionCommand.h index 413d2273e4..ca72bb04cd 100644 --- a/src/PeerInitiateConnectionCommand.h +++ b/src/PeerInitiateConnectionCommand.h @@ -49,7 +49,7 @@ class PeerInitiateConnectionCommand : public PeerAbstractCommand, bool _mseHandshakeEnabled; protected: virtual bool executeInternal(); - virtual bool prepareForNextPeer(int wait); + virtual bool prepareForNextPeer(time_t wait); virtual void onAbort(Exception* ex); virtual bool exitBeforeExecute(); diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 3e7a3927ba..8c7e3514ac 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -244,7 +244,7 @@ bool PeerInteractionCommand::executeInternal() { } // TODO this method removed when PeerBalancerCommand is implemented -bool PeerInteractionCommand::prepareForNextPeer(int32_t wait) { +bool PeerInteractionCommand::prepareForNextPeer(time_t wait) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { PeerHandle peer = peerStorage->getUnusedPeer(); peer->usedBy(CUIDCounterSingletonHolder::instance()->newID()); diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h index 15bb4d4255..ced42d6a8d 100644 --- a/src/PeerInteractionCommand.h +++ b/src/PeerInteractionCommand.h @@ -57,10 +57,10 @@ class PeerInteractionCommand : public PeerAbstractCommand, private: Seq sequence; SharedHandle btInteractive; - int32_t maxDownloadSpeedLimit; + unsigned int maxDownloadSpeedLimit; protected: virtual bool executeInternal(); - virtual bool prepareForNextPeer(int32_t wait); + virtual bool prepareForNextPeer(time_t wait); virtual void onAbort(Exception* ex); virtual bool exitBeforeExecute(); public: diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index 6c160b9798..da666c8b0f 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -46,7 +46,7 @@ namespace aria2 { -int32_t PeerListenCommand::__numInstance = 0; +unsigned int PeerListenCommand::__numInstance = 0; PeerListenCommand* PeerListenCommand::__instance = 0; @@ -88,13 +88,13 @@ bool PeerListenCommand::execute() { if(e->isHaltRequested() || e->_requestGroupMan->downloadFinished()) { return true; } - for(int32_t i = 0; i < 3 && socket->isReadable(0); i++) { + for(int i = 0; i < 3 && socket->isReadable(0); i++) { SocketHandle peerSocket; try { peerSocket = socket->acceptConnection(); - std::pair peerInfo; + std::pair peerInfo; peerSocket->getPeerInfo(peerInfo); - std::pair localInfo; + std::pair localInfo; peerSocket->getAddrInfo(localInfo); if(peerInfo.first == localInfo.first) { diff --git a/src/PeerListenCommand.h b/src/PeerListenCommand.h index 1271f59d33..ff83a52c10 100644 --- a/src/PeerListenCommand.h +++ b/src/PeerListenCommand.h @@ -48,9 +48,9 @@ class PeerListenCommand : public Command { private: DownloadEngine* e; SharedHandle socket; - int32_t _lowestSpeedLimit; + unsigned int _lowestSpeedLimit; - static int32_t __numInstance; + static unsigned int __numInstance; static PeerListenCommand* __instance; @@ -63,14 +63,14 @@ class PeerListenCommand : public Command { int32_t bindPort(IntSequence& seq); - void setLowestSpeedLimit(int32_t speed) + void setLowestSpeedLimit(unsigned int speed) { _lowestSpeedLimit = speed; } static PeerListenCommand* getInstance(DownloadEngine* e); - static int32_t getNumInstance() + static unsigned int getNumInstance() { return __numInstance; } diff --git a/src/PeerMessageUtil.cc b/src/PeerMessageUtil.cc index a6329da291..c71c94bf62 100644 --- a/src/PeerMessageUtil.cc +++ b/src/PeerMessageUtil.cc @@ -40,85 +40,86 @@ namespace aria2 { -int8_t PeerMessageUtil::getId(const unsigned char* msg) { +uint8_t PeerMessageUtil::getId(const unsigned char* msg) { return msg[0]; } -int32_t PeerMessageUtil::getIntParam(const unsigned char* msg, int32_t offset) { - int32_t nParam; - memcpy(&nParam, msg+offset, sizeof(int32_t)); +uint32_t PeerMessageUtil::getIntParam(const unsigned char* msg, size_t pos) +{ + uint32_t nParam; + memcpy(&nParam, msg+pos, sizeof(nParam)); return ntohl(nParam); } -int16_t PeerMessageUtil::getShortIntParam(const unsigned char* msg, int32_t offset) { - int16_t nParam; - memcpy(&nParam, msg+offset, sizeof(int16_t)); +uint16_t PeerMessageUtil::getShortIntParam(const unsigned char* msg, size_t pos) { + uint16_t nParam; + memcpy(&nParam, msg+pos, sizeof(nParam)); return ntohs(nParam); } -void PeerMessageUtil::checkIndex(int32_t index, int32_t pieces) { - if(!(0 <= index && index < (int32_t)pieces)) { - throw new DlAbortEx("Invalid index: %d", index); +void PeerMessageUtil::checkIndex(size_t index, size_t pieces) { + if(!(index < pieces)) { + throw new DlAbortEx("Invalid index: %zu", index); } } -void PeerMessageUtil::checkBegin(int32_t begin, int32_t pieceLength) { - if(!(0 <= begin && begin < (int32_t)pieceLength)) { - throw new DlAbortEx("Invalid begin: %d", begin); +void PeerMessageUtil::checkBegin(uint32_t begin, size_t pieceLength) { + if(!(begin < pieceLength)) { + throw new DlAbortEx("Invalid begin: %u", begin); } } -void PeerMessageUtil::checkLength(int32_t length) { +void PeerMessageUtil::checkLength(size_t length) { if(length > MAX_BLOCK_LENGTH) { - throw new DlAbortEx("Length too long: %d > %dKB", length, + throw new DlAbortEx("Length too long: %zu > %uKB", length, MAX_BLOCK_LENGTH/1024); } - if(length <= 0) { - throw new DlAbortEx("Invalid length: %d", length); + if(length == 0) { + throw new DlAbortEx("Invalid length: %zu", length); } } -void PeerMessageUtil::checkRange(int32_t begin, int32_t length, int32_t pieceLength) { - if(!(0 <= begin && 0 < length)) { - throw new DlAbortEx("Invalid range: begin=%d, length=%d", +void PeerMessageUtil::checkRange(uint32_t begin, size_t length, size_t pieceLength) { + if(!(0 < length)) { + throw new DlAbortEx("Invalid range: begin=%u, length=%zu", begin, length); } - int32_t end = begin+length; - if(!(0 < end && end <= pieceLength)) { - throw new DlAbortEx("Invalid range: begin=%d, length=%d", + uint32_t end = begin+length; + if(!(end <= pieceLength)) { + throw new DlAbortEx("Invalid range: begin=%u, length=%zu", begin, length); } } void PeerMessageUtil::checkBitfield(const unsigned char* bitfield, - int32_t bitfieldLength, - int32_t pieces) { + size_t bitfieldLength, + size_t pieces) { if(!(bitfieldLength == (pieces+7)/8)) { - throw new DlAbortEx("Invalid bitfield length: %d", + throw new DlAbortEx("Invalid bitfield length: %zu", bitfieldLength); } char lastbyte = bitfield[bitfieldLength-1]; - for(int32_t i = 0; i < 8-pieces%8 && pieces%8 != 0; ++i) { + for(size_t i = 0; i < 8-pieces%8 && pieces%8 != 0; ++i) { if(!(((lastbyte >> i) & 1) == 0)) { throw new DlAbortEx("Invalid bitfield"); } } } -void PeerMessageUtil::setIntParam(unsigned char* dest, int32_t param) { - int32_t nParam = htonl(param); - memcpy(dest, &nParam, sizeof(int32_t)); +void PeerMessageUtil::setIntParam(unsigned char* dest, uint32_t param) { + uint32_t nParam = htonl(param); + memcpy(dest, &nParam, sizeof(nParam)); } -void PeerMessageUtil::setShortIntParam(unsigned char* dest, int16_t param) { - int16_t nParam = htons(param); - memcpy(dest, &nParam, sizeof(int16_t)); +void PeerMessageUtil::setShortIntParam(unsigned char* dest, uint16_t param) { + uint16_t nParam = htons(param); + memcpy(dest, &nParam, sizeof(nParam)); } void PeerMessageUtil::createPeerMessageString(unsigned char* msg, - int32_t msgLength, - int32_t payloadLength, - int8_t messageId) { + size_t msgLength, + size_t payloadLength, + uint8_t messageId) { assert(msgLength >= 5); memset(msg, 0, msgLength); setIntParam(msg, payloadLength); diff --git a/src/PeerMessageUtil.h b/src/PeerMessageUtil.h index cdb8984b86..d01214257f 100644 --- a/src/PeerMessageUtil.h +++ b/src/PeerMessageUtil.h @@ -47,28 +47,28 @@ class PeerMessageUtil { private: PeerMessageUtil() {} public: - static int32_t getIntParam(const unsigned char* msg, int32_t offset); + static uint32_t getIntParam(const unsigned char* msg, size_t pos); - static int16_t getShortIntParam(const unsigned char* msg, int32_t offset); + static uint16_t getShortIntParam(const unsigned char* msg, size_t pos); - static void setIntParam(unsigned char* dest, int32_t param); + static void setIntParam(unsigned char* dest, uint32_t param); - static void setShortIntParam(unsigned char* dest, int16_t param); + static void setShortIntParam(unsigned char* dest, uint16_t param); - static int8_t getId(const unsigned char* msg); + static uint8_t getId(const unsigned char* msg); - static void checkIndex(int32_t index, int32_t pieces); - static void checkBegin(int32_t begin, int32_t pieceLength); - static void checkLength(int32_t length); - static void checkRange(int32_t begin, int32_t length, int32_t pieceLength); + static void checkIndex(size_t index, size_t pieces); + static void checkBegin(uint32_t begin, size_t pieceLength); + static void checkLength(size_t length); + static void checkRange(uint32_t begin, size_t length, size_t pieceLength); static void checkBitfield(const unsigned char* bitfield, - int32_t bitfieldLength, - int32_t pieces); + size_t bitfieldLength, + size_t pieces); static void createPeerMessageString(unsigned char* msg, - int32_t msgLength, - int32_t payloadLength, - int8_t messageId); + size_t msgLength, + size_t payloadLength, + uint8_t messageId); /** * Creates compact tracker format(6bytes for ipv4 address and port) diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc index 55efe66d9e..b37e5aa1e1 100644 --- a/src/PeerReceiveHandshakeCommand.cc +++ b/src/PeerReceiveHandshakeCommand.cc @@ -67,7 +67,7 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand(int32_t cuid, if(_peerConnection.isNull()) { _peerConnection = new PeerConnection(cuid, socket, e->option); } - int32_t maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); + unsigned int maxDownloadSpeed = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT); if(maxDownloadSpeed > 0) { _thresholdSpeed = std::min(maxDownloadSpeed, _thresholdSpeed); } @@ -83,7 +83,7 @@ bool PeerReceiveHandshakeCommand::exitBeforeExecute() bool PeerReceiveHandshakeCommand::executeInternal() { unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH]; - int32_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH; + size_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH; // ignore return value. The received data is kept in PeerConnection object // because of peek = true. _peerConnection->receiveHandshake(data, dataLength, true); diff --git a/src/PeerReceiveHandshakeCommand.h b/src/PeerReceiveHandshakeCommand.h index 87f5c46a16..620b2e90ea 100644 --- a/src/PeerReceiveHandshakeCommand.h +++ b/src/PeerReceiveHandshakeCommand.h @@ -48,14 +48,10 @@ class PeerReceiveHandshakeCommand:public PeerAbstractCommand private: SharedHandle _peerConnection; - int32_t _thresholdSpeed; + unsigned int _thresholdSpeed; protected: virtual bool executeInternal(); - /* - virtual bool prepareForRetry(int32_t wait); - virtual bool prepareForNextPeer(int32_t wait); - */ virtual bool exitBeforeExecute(); public: PeerReceiveHandshakeCommand(int32_t cuid, diff --git a/src/PeerStat.h b/src/PeerStat.h index 7e830f9138..ce2860f814 100644 --- a/src/PeerStat.h +++ b/src/PeerStat.h @@ -63,43 +63,43 @@ class PeerStat { /** * Returns current download speed in byte per sec. */ - int32_t calculateDownloadSpeed() { + unsigned int calculateDownloadSpeed() { return downloadSpeed.calculateSpeed(); } - int32_t calculateDownloadSpeed(const struct timeval& now) { + unsigned int calculateDownloadSpeed(const struct timeval& now) { return downloadSpeed.calculateSpeed(now); } - int32_t calculateUploadSpeed() { + unsigned int calculateUploadSpeed() { return uploadSpeed.calculateSpeed(); } - int32_t calculateUploadSpeed(const struct timeval& now) { + unsigned int calculateUploadSpeed(const struct timeval& now) { return uploadSpeed.calculateSpeed(now); } - void updateDownloadLength(int32_t bytes) { + void updateDownloadLength(size_t bytes) { downloadSpeed.update(bytes); } - void updateUploadLength(int32_t bytes) { + void updateUploadLength(size_t bytes) { uploadSpeed.update(bytes); } - int32_t getMaxDownloadSpeed() const { + unsigned int getMaxDownloadSpeed() const { return downloadSpeed.getMaxSpeed(); } - int32_t getMaxUploadSpeed() const { + unsigned int getMaxUploadSpeed() const { return uploadSpeed.getMaxSpeed(); } - int32_t getAvgDownloadSpeed() const { + unsigned int getAvgDownloadSpeed() const { return downloadSpeed.getAvgSpeed(); } - int32_t getAvgUploadSpeed() const { + unsigned int getAvgUploadSpeed() const { return uploadSpeed.getAvgSpeed(); } diff --git a/src/PieceHashCheckIntegrityEntry.cc b/src/PieceHashCheckIntegrityEntry.cc index 466eb8d257..0bedd95cde 100644 --- a/src/PieceHashCheckIntegrityEntry.cc +++ b/src/PieceHashCheckIntegrityEntry.cc @@ -50,7 +50,7 @@ bool PieceHashCheckIntegrityEntry::isValidationReady() { DownloadContextHandle dctx = _requestGroup->getDownloadContext(); return dctx->getPieceHashes().size() > 0 && - dctx->getPieceHashes().size() == (uint32_t)dctx->getNumPieces(); + dctx->getPieceHashes().size() == dctx->getNumPieces(); } void PieceHashCheckIntegrityEntry::initValidator() diff --git a/src/ProgressAwareEntry.h b/src/ProgressAwareEntry.h index ea2d257e7b..94383ef584 100644 --- a/src/ProgressAwareEntry.h +++ b/src/ProgressAwareEntry.h @@ -45,9 +45,9 @@ class ProgressAwareEntry { public: virtual ~ProgressAwareEntry() {} - virtual int64_t getCurrentLength() = 0; + virtual off_t getCurrentLength() = 0; - virtual int64_t getTotalLength() = 0; + virtual uint64_t getTotalLength() = 0; virtual bool finished() = 0; }; diff --git a/src/Range.h b/src/Range.h index 5c828834a0..92c44f1612 100644 --- a/src/Range.h +++ b/src/Range.h @@ -43,13 +43,13 @@ namespace aria2 { class Range { private: - int64_t startByte; - int64_t endByte; - int64_t entityLength; + off_t startByte; + off_t endByte; + uint64_t entityLength; public: Range():startByte(0), endByte(0), entityLength(0) {} - Range(int64_t startByte, int64_t endByte, int64_t entityLength): + Range(off_t startByte, off_t endByte, uint64_t entityLength): startByte(startByte), endByte(endByte), entityLength(entityLength) {} bool operator==(const Range& range) const @@ -64,22 +64,22 @@ class Range { return !(*this == range); } - int64_t getStartByte() const + off_t getStartByte() const { return startByte; } - int64_t getEndByte() const + off_t getEndByte() const { return endByte; } - int64_t getEntityLength() const + uint64_t getEntityLength() const { return entityLength; } - int64_t getContentLength() const + uint64_t getContentLength() const { if(endByte >= startByte) { return endByte-startByte+1; diff --git a/src/Request.cc b/src/Request.cc index eb07b8f8b7..0ad8674d0d 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -93,7 +93,7 @@ bool Request::parseUrl(const std::string& url) { std::string::size_type hp = tempUrl.find("://"); if(hp == std::string::npos) return false; protocol = tempUrl.substr(0, hp); - int32_t defPort; + uint16_t defPort; if((defPort = FeatureConfig::getInstance()->getDefaultPort(protocol)) == 0) { return false; } @@ -120,9 +120,6 @@ bool Request::parseUrl(const std::string& url) { if(hostAndPort.second != "") { try { port = Util::parseInt(hostAndPort.second); - if(!(0 < port && port <= 65535)) { - return false; - } } catch(RecoverableException* e) { delete e; return false; @@ -162,9 +159,13 @@ bool Request::isHexNumber(const char c) const std::string Request::urlencode(const std::string& src) const { - int32_t lastIndex = src.size()-1; + if(src.empty()) { + return ""; + } + size_t lastIndex = src.size()-1; std::string result = src+" "; - for(int32_t index = lastIndex; index >= 0; --index) { + size_t index = lastIndex; + while(index-- > 0) { const char c = result[index]; // '/' is not urlencoded because src is expected to be a path. if(Util::shouldUrlencode(c)) { diff --git a/src/Request.h b/src/Request.h index 2576420a99..544babd4da 100644 --- a/src/Request.h +++ b/src/Request.h @@ -74,10 +74,10 @@ class Request { std::string referer; std::string protocol; std::string host; - int32_t port; + uint16_t port; std::string dir; std::string file; - int32_t tryCount; + unsigned int tryCount; TRACKER_EVENT trackerEvent; bool keepAlive; std::string method; @@ -108,7 +108,7 @@ class Request { bool resetUrl(); void resetTryCount() { tryCount = 0; } void addTryCount() { tryCount++; } - int32_t getTryCount() const { return tryCount; } + unsigned int getTryCount() const { return tryCount; } //bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; } std::string getUrl() const { return url; } @@ -118,7 +118,7 @@ class Request { void setReferer(const std::string& url) { referer = previousUrl = url; } std::string getProtocol() const { return protocol; } std::string getHost() const { return host; } - int32_t getPort() const { return port; } + uint16_t getPort() const { return port; } std::string getDir() const { return dir; } std::string getFile() const { return file;} bool isKeepAlive() const { return keepAlive; } diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index d3a44aaf92..9ea0e28405 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -413,8 +413,8 @@ bool RequestGroup::tryAutoFileRenaming() if(filepath.empty()) { return false; } - for(int32_t i = 1; i < 10000; ++i) { - File newfile(filepath+"."+Util::itos(i)); + for(unsigned int i = 1; i < 10000; ++i) { + File newfile(filepath+"."+Util::uitos(i)); if(!newfile.exists()) { SingleFileDownloadContextHandle(_downloadContext)->setUFilename(newfile.getBasename()); return true; @@ -423,13 +423,23 @@ bool RequestGroup::tryAutoFileRenaming() return false; } -Commands RequestGroup::createNextCommandWithAdj(DownloadEngine* e, int32_t numAdj) +Commands RequestGroup::createNextCommandWithAdj(DownloadEngine* e, int numAdj) { - int32_t numCommand = _numConcurrentCommand == 0 ? _uris.size() : _numConcurrentCommand+numAdj; + unsigned int numCommand; + if(_numConcurrentCommand == 0) { + numCommand = _uris.size(); + } else { + int n = _numConcurrentCommand+numAdj; + if(n <= 0) { + return Commands(); + } else { + numCommand = n; + } + } return createNextCommand(e, numCommand, "GET"); } -Commands RequestGroup::createNextCommand(DownloadEngine* e, int32_t numCommand, const std::string& method) +Commands RequestGroup::createNextCommand(DownloadEngine* e, unsigned int numCommand, const std::string& method) { Commands commands; std::deque pendingURIs; @@ -467,7 +477,7 @@ std::string RequestGroup::getFilePath() const } } -int64_t RequestGroup::getTotalLength() const +uint64_t RequestGroup::getTotalLength() const { if(_pieceStorage.isNull()) { return 0; @@ -480,7 +490,7 @@ int64_t RequestGroup::getTotalLength() const } } -int64_t RequestGroup::getCompletedLength() const +uint64_t RequestGroup::getCompletedLength() const { if(_pieceStorage.isNull()) { return 0; @@ -506,8 +516,8 @@ void RequestGroup::validateFilename(const std::string& expectedFilename, } } -void RequestGroup::validateTotalLength(int64_t expectedTotalLength, - int64_t actualTotalLength) const +void RequestGroup::validateTotalLength(uint64_t expectedTotalLength, + uint64_t actualTotalLength) const { if(expectedTotalLength <= 0) { return; @@ -524,7 +534,7 @@ void RequestGroup::validateFilename(const std::string& actualFilename) const validateFilename(_downloadContext->getFileEntries().front()->getBasename(), actualFilename); } -void RequestGroup::validateTotalLength(int64_t actualTotalLength) const +void RequestGroup::validateTotalLength(uint64_t actualTotalLength) const { validateTotalLength(getTotalLength(), actualTotalLength); } @@ -539,9 +549,9 @@ void RequestGroup::decreaseStreamConnection() --_numStreamConnection; } -int32_t RequestGroup::getNumConnection() const +unsigned int RequestGroup::getNumConnection() const { - int32_t numConnection = _numStreamConnection; + unsigned int numConnection = _numStreamConnection; #ifdef ENABLE_BITTORRENT { BtContextHandle btContext = _downloadContext; @@ -792,7 +802,7 @@ void RequestGroup::setProgressInfoFile(const BtProgressInfoFileHandle& progressI bool RequestGroup::needsFileAllocation() const { return isFileAllocationEnabled() && - _option->getAsLLInt(PREF_NO_FILE_ALLOCATION_LIMIT) <= getTotalLength() && + (uint64_t)_option->getAsLLInt(PREF_NO_FILE_ALLOCATION_LIMIT) <= getTotalLength() && !_pieceStorage->getDiskAdaptor()->fileAllocationIterator()->finished(); } diff --git a/src/RequestGroup.h b/src/RequestGroup.h index 72f3e5ed26..eac026ad7a 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -70,14 +70,14 @@ class RequestGroup { std::deque _uris; std::deque _spentUris; - int32_t _numConcurrentCommand; + unsigned int _numConcurrentCommand; /** * This is the number of connections used in streaming protocol(http/ftp) */ - int32_t _numStreamConnection; + unsigned int _numStreamConnection; - int32_t _numCommand; + unsigned int _numCommand; SharedHandle _segmentMan; SharedHandle _segmentManFactory; @@ -115,8 +115,8 @@ class RequestGroup { void validateFilename(const std::string& expectedFilename, const std::string& actualFilename) const; - void validateTotalLength(int64_t expectedTotalLength, - int64_t actualTotalLength) const; + void validateTotalLength(uint64_t expectedTotalLength, + uint64_t actualTotalLength) const; void initializePreDownloadHandler(); @@ -138,9 +138,9 @@ class RequestGroup { std::deque createInitialCommand(DownloadEngine* e); - std::deque createNextCommandWithAdj(DownloadEngine* e, int32_t numAdj); + std::deque createNextCommandWithAdj(DownloadEngine* e, int numAdj); - std::deque createNextCommand(DownloadEngine* e, int32_t numCommand, const std::string& method = "GET"); + std::deque createNextCommand(DownloadEngine* e, unsigned int numCommand, const std::string& method = "GET"); void addURI(const std::string& uri) { @@ -157,9 +157,9 @@ class RequestGroup { std::string getDir() const; - int64_t getTotalLength() const; + uint64_t getTotalLength() const; - int64_t getCompletedLength() const; + uint64_t getCompletedLength() const; const std::deque& getRemainingUris() const { @@ -180,11 +180,11 @@ class RequestGroup { */ void validateFilename(const std::string& actualFilename) const; - void validateTotalLength(int64_t actualTotalLength) const; + void validateTotalLength(uint64_t actualTotalLength) const; void setSegmentManFactory(const SharedHandle& segmentManFactory); - void setNumConcurrentCommand(int32_t num) + void setNumConcurrentCommand(unsigned int num) { _numConcurrentCommand = num; } @@ -212,13 +212,13 @@ class RequestGroup { void decreaseStreamConnection(); - int32_t getNumConnection() const; + unsigned int getNumConnection() const; void increaseNumCommand(); void decreaseNumCommand(); - int32_t getNumCommand() const + unsigned int getNumCommand() const { return _numCommand; } diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index a21a4f274e..01ad37c2d8 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -50,7 +50,7 @@ namespace aria2 { RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups, - int32_t maxSimultaneousDownloads): + unsigned int maxSimultaneousDownloads): _requestGroups(requestGroups), _logger(LogFactory::getInstance()), _maxSimultaneousDownloads(maxSimultaneousDownloads), @@ -85,14 +85,14 @@ void RequestGroupMan::addReservedGroup(const RequestGroupHandle& group) _reservedGroups.push_back(group); } -int32_t RequestGroupMan::countRequestGroup() const +size_t RequestGroupMan::countRequestGroup() const { return _requestGroups.size(); } -RequestGroupHandle RequestGroupMan::getRequestGroup(int32_t index) const +RequestGroupHandle RequestGroupMan::getRequestGroup(size_t index) const { - if(index < (int32_t)_requestGroups.size()) { + if(index < _requestGroups.size()) { return _requestGroups[index]; } else { return 0; @@ -101,7 +101,7 @@ RequestGroupHandle RequestGroupMan::getRequestGroup(int32_t index) const void RequestGroupMan::removeStoppedGroup() { - int32_t count = 0; + unsigned int count = 0; RequestGroups temp; for(RequestGroups::iterator itr = _requestGroups.begin(); itr != _requestGroups.end(); ++itr) { @@ -119,7 +119,7 @@ void RequestGroupMan::removeStoppedGroup() } RequestGroups nextGroups = (*itr)->postDownloadProcessing(); if(nextGroups.size() > 0) { - _logger->debug("Adding %d RequestGroups as a result of PostDownloadHandler.", (int32_t)nextGroups.size()); + _logger->debug("Adding %u RequestGroups as a result of PostDownloadHandler.", nextGroups.size()); std::copy(nextGroups.rbegin(), nextGroups.rend(), std::front_inserter(_reservedGroups)); } } else { @@ -136,7 +136,7 @@ void RequestGroupMan::removeStoppedGroup() } _requestGroups = temp; if(count > 0) { - _logger->debug("%d RequestGroup(s) deleted.", count); + _logger->debug("%u RequestGroup(s) deleted.", count); } } @@ -144,8 +144,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) { RequestGroups temp; removeStoppedGroup(); - int32_t count = 0; - for(int32_t num = _maxSimultaneousDownloads-_requestGroups.size(); + unsigned int count = 0; + for(int num = _maxSimultaneousDownloads-_requestGroups.size(); num > 0 && _reservedGroups.size() > 0; --num) { RequestGroupHandle groupToAdd = _reservedGroups.front(); _reservedGroups.pop_front(); diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h index c80545a580..4208165045 100644 --- a/src/RequestGroupMan.h +++ b/src/RequestGroupMan.h @@ -56,7 +56,7 @@ class RequestGroupMan { std::deque > _reservedGroups; std::deque > _downloadResults; const Logger* _logger; - int32_t _maxSimultaneousDownloads; + unsigned int _maxSimultaneousDownloads; int32_t _gidCounter; std::string @@ -65,7 +65,7 @@ class RequestGroupMan { public: RequestGroupMan(const std::deque >& requestGroups, - int32_t maxSimultaneousDownloads = 1); + unsigned int maxSimultaneousDownloads = 1); bool downloadFinished(); @@ -89,9 +89,9 @@ class RequestGroupMan { void addReservedGroup(const SharedHandle& group); - int32_t countRequestGroup() const; + size_t countRequestGroup() const; - SharedHandle getRequestGroup(int32_t index) const; + SharedHandle getRequestGroup(size_t index) const; void showDownloadResults(std::ostream& o) const; diff --git a/src/RequestSlot.cc b/src/RequestSlot.cc index 2ec1437bcb..c8d2611865 100644 --- a/src/RequestSlot.cc +++ b/src/RequestSlot.cc @@ -39,7 +39,7 @@ namespace aria2 { RequestSlot RequestSlot::nullSlot(0, 0, 0, 0); -RequestSlot::RequestSlot(int32_t index, int32_t begin, int32_t length, int32_t blockIndex) +RequestSlot::RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex) :index(index), begin(begin), length(length), blockIndex(blockIndex) {} RequestSlot::RequestSlot(const RequestSlot& requestSlot) { @@ -81,7 +81,7 @@ bool RequestSlot::isTimeout(time_t timeoutSec) const { return dispatchedTime.elapsed(timeoutSec); } -int32_t RequestSlot::getLatencyInMillis() const { +unsigned int RequestSlot::getLatencyInMillis() const { return dispatchedTime.differenceInMillis(); } diff --git a/src/RequestSlot.h b/src/RequestSlot.h index 5a3b6a0edb..65dd03f1d2 100644 --- a/src/RequestSlot.h +++ b/src/RequestSlot.h @@ -44,13 +44,13 @@ namespace aria2 { class RequestSlot { private: Time dispatchedTime; - int32_t index; - int32_t begin; - int32_t length; - int32_t blockIndex; + size_t index; + uint32_t begin; + size_t length; + size_t blockIndex; void copy(const RequestSlot& requestSlot); public: - RequestSlot(int32_t index, int32_t begin, int32_t length, int32_t blockIndex); + RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex); RequestSlot(const RequestSlot& requestSlot); ~RequestSlot() {} @@ -63,19 +63,19 @@ class RequestSlot { void setDispatchedTime(time_t secFromEpoch); bool isTimeout(time_t timeoutSec) const; - int32_t getLatencyInMillis() const; + unsigned int getLatencyInMillis() const; - int32_t getIndex() const { return index; } - void setIndex(int32_t index) { this->index = index; } + size_t getIndex() const { return index; } + void setIndex(size_t index) { this->index = index; } - int32_t getBegin() const { return begin; } - void setBegin(int32_t begin) { this->begin = begin; } + uint32_t getBegin() const { return begin; } + void setBegin(uint32_t begin) { this->begin = begin; } - int32_t getLength() const { return length; } - void setLength(int32_t length) { this->length = length; } + size_t getLength() const { return length; } + void setLength(size_t length) { this->length = length; } - int32_t getBlockIndex() const { return blockIndex; } - void setBlockIndex(int32_t blockIndex) { this->blockIndex = blockIndex; } + size_t getBlockIndex() const { return blockIndex; } + void setBlockIndex(size_t blockIndex) { this->blockIndex = blockIndex; } static RequestSlot nullSlot; diff --git a/src/ResourcesMetalinkParserState.cc b/src/ResourcesMetalinkParserState.cc index 05e78eac4d..2cbd624bdd 100644 --- a/src/ResourcesMetalinkParserState.cc +++ b/src/ResourcesMetalinkParserState.cc @@ -61,7 +61,7 @@ void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, location = Util::toUpper((*itr).second); } } - int32_t preference; + int preference; { std::map::const_iterator itr = attrs.find("preference"); if(itr == attrs.end()) { @@ -75,7 +75,7 @@ void ResourcesMetalinkParserState::beginElement(MetalinkParserStateMachine* stm, } } } - int32_t maxConnections; + int maxConnections; { std::map::const_iterator itr = attrs.find("maxconnections"); if(itr == attrs.end()) { diff --git a/src/ShareRatioSeedCriteria.h b/src/ShareRatioSeedCriteria.h index 5fd5d196db..8a6b4115e5 100644 --- a/src/ShareRatioSeedCriteria.h +++ b/src/ShareRatioSeedCriteria.h @@ -68,7 +68,7 @@ class ShareRatioSeedCriteria : public SeedCriteria { return false; } TransferStat stat = peerStorage->calculateStat(); - int64_t allTimeUploadLength = + uint64_t allTimeUploadLength = btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength(); return ratio <= ((double)allTimeUploadLength)/pieceStorage->getCompletedLength(); diff --git a/src/SharedHandle.h b/src/SharedHandle.h index fa875ebe19..a5669ed0a0 100644 --- a/src/SharedHandle.h +++ b/src/SharedHandle.h @@ -43,11 +43,11 @@ class RefCount { public: RefCount():totalRefCount(0), strongRefCount(0) {} - RefCount(int32_t totalRefCount, int32_t strongRefCount) + RefCount(unsigned int totalRefCount, unsigned int strongRefCount) :totalRefCount(totalRefCount), strongRefCount(strongRefCount) {} - int32_t totalRefCount; - int32_t strongRefCount; + unsigned int totalRefCount; + unsigned int strongRefCount; }; template diff --git a/src/SimpleBtMessage.cc b/src/SimpleBtMessage.cc index 3a8b989f81..930d9c33ef 100644 --- a/src/SimpleBtMessage.cc +++ b/src/SimpleBtMessage.cc @@ -51,14 +51,14 @@ void SimpleBtMessage::send() { } if(sendPredicate() || sendingInProgress) { const unsigned char* msg = getMessage(); - int32_t msgLength = getMessageLength(); + size_t msgLength = getMessageLength(); if(!sendingInProgress) { logger->info(MSG_SEND_PEER_MESSAGE, cuid, peer->ipaddr.c_str(), peer->port, toString().c_str()); leftDataLength = getMessageLength(); } sendingInProgress = false; - int32_t writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength); + size_t writtenLength = peerConnection->sendMessage(msg+msgLength-leftDataLength, leftDataLength); if(writtenLength == leftDataLength) { onSendComplete(); } else { diff --git a/src/SimpleBtMessage.h b/src/SimpleBtMessage.h index 60f8a7ea19..6a38cd8872 100644 --- a/src/SimpleBtMessage.h +++ b/src/SimpleBtMessage.h @@ -41,7 +41,7 @@ namespace aria2 { class SimpleBtMessage : public AbstractBtMessage { private: - int32_t leftDataLength; + size_t leftDataLength; public: SimpleBtMessage(); @@ -51,7 +51,7 @@ class SimpleBtMessage : public AbstractBtMessage { virtual const unsigned char* getMessage() = 0; - virtual int32_t getMessageLength() = 0; + virtual size_t getMessageLength() = 0; virtual void onSendComplete() {}; diff --git a/src/SimpleLogger.h b/src/SimpleLogger.h index 6063939e64..4f693430f4 100644 --- a/src/SimpleLogger.h +++ b/src/SimpleLogger.h @@ -50,7 +50,7 @@ class SimpleLogger:public Logger { const char* msg, va_list ap, Exception* e = 0, bool printHeader = true) const; FILE* file; - int32_t stdoutField; + int stdoutField; public: SimpleLogger(FILE* logfile = 0); ~SimpleLogger(); diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc index 53030b1666..c6660bd845 100644 --- a/src/SingleFileAllocationIterator.cc +++ b/src/SingleFileAllocationIterator.cc @@ -42,7 +42,7 @@ namespace aria2 { #define BUFSIZE (256*1024) #define ALIGNMENT 512 -SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0) +SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, off_t offset, uint64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0) { if(_offset%ALIGNMENT != 0) { _stream->disableDirectIO(); @@ -69,7 +69,7 @@ void SingleFileAllocationIterator::allocateChunk() _stream->writeData(_buffer, BUFSIZE, _offset); _offset += BUFSIZE; - if(_totalLength < _offset) { + if(_totalLength < (uint64_t)_offset) { _stream->truncate(_totalLength); _offset = _totalLength; } @@ -77,7 +77,7 @@ void SingleFileAllocationIterator::allocateChunk() bool SingleFileAllocationIterator::finished() { - return _offset >= _totalLength; + return (uint64_t)_offset >= _totalLength; } } // namespace aria2 diff --git a/src/SingleFileAllocationIterator.h b/src/SingleFileAllocationIterator.h index 624ab11d4a..60e56105f6 100644 --- a/src/SingleFileAllocationIterator.h +++ b/src/SingleFileAllocationIterator.h @@ -46,13 +46,13 @@ class SingleFileAllocationIterator:public FileAllocationIterator private: BinaryStream* _stream; - int64_t _offset; + off_t _offset; - int64_t _totalLength; + uint64_t _totalLength; unsigned char* _buffer; public: - SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength); + SingleFileAllocationIterator(BinaryStream* stream, off_t offset, uint64_t totalLength); virtual ~SingleFileAllocationIterator(); @@ -60,12 +60,12 @@ class SingleFileAllocationIterator:public FileAllocationIterator virtual bool finished(); - virtual int64_t getCurrentLength() + virtual off_t getCurrentLength() { return _offset; } - virtual int64_t getTotalLength() + virtual uint64_t getTotalLength() { return _totalLength; } diff --git a/src/SkipTagMetalinkParserState.h b/src/SkipTagMetalinkParserState.h index 3c9d74c0bb..fe547a683d 100644 --- a/src/SkipTagMetalinkParserState.h +++ b/src/SkipTagMetalinkParserState.h @@ -43,7 +43,7 @@ class SkipTagMetalinkParserState:public MetalinkParserState { private: MetalinkParserState* _prevState; - int32_t _depth; + unsigned int _depth; public: SkipTagMetalinkParserState(MetalinkParserState* prevState); diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc index 1a710b720c..15a4341b55 100644 --- a/src/SleepCommand.cc +++ b/src/SleepCommand.cc @@ -39,7 +39,7 @@ namespace aria2 { -SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait): +SleepCommand::SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, time_t wait): Command(cuid), engine(e), nextCommand(nextCommand), wait(wait) {} SleepCommand::~SleepCommand() { diff --git a/src/SleepCommand.h b/src/SleepCommand.h index 3bbf4d1eef..4da85a88b5 100644 --- a/src/SleepCommand.h +++ b/src/SleepCommand.h @@ -46,13 +46,13 @@ class SleepCommand:public Command { private: DownloadEngine* engine; Command* nextCommand; - int32_t wait; + time_t wait; Time checkPoint; bool isHaltRequested() const; public: - SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, int32_t wait); + SleepCommand(int32_t cuid, DownloadEngine* e, Command* nextCommand, time_t wait); virtual ~SleepCommand(); bool execute(); }; diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 57bd3ab778..e0e54104b4 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -65,13 +65,12 @@ SocketCore::SocketCore(int sockType):_sockType(sockType), sockfd(-1) { init(); } -SocketCore::SocketCore(int32_t sockfd, int sockType):_sockType(sockType), sockfd(sockfd) { +SocketCore::SocketCore(int sockfd, int sockType):_sockType(sockType), sockfd(sockfd) { init(); } void SocketCore::init() { - use = 1; blocking = true; secure = false; #ifdef HAVE_LIBSSL @@ -103,9 +102,7 @@ std::string uitos(T value) str = "0"; return str; } - int32_t count = 0; while(value) { - ++count; char digit = value%10+'0'; str.insert(str.begin(), digit); value /= 10; @@ -186,7 +183,7 @@ SocketCore::getNameInfoInNumeric(const struct sockaddr* sockaddr, socklen_t len) return std::pair(host, atoi(service)); // TODO } -void SocketCore::getAddrInfo(std::pair& addrinfo) const +void SocketCore::getAddrInfo(std::pair& addrinfo) const { struct sockaddr_storage sockaddr; socklen_t len = sizeof(sockaddr); @@ -197,7 +194,7 @@ void SocketCore::getAddrInfo(std::pair& addrinfo) const addrinfo = SocketCore::getNameInfoInNumeric(addrp, len); } -void SocketCore::getPeerInfo(std::pair& peerinfo) const +void SocketCore::getPeerInfo(std::pair& peerinfo) const { struct sockaddr_storage sockaddr; socklen_t len = sizeof(sockaddr); @@ -208,7 +205,7 @@ void SocketCore::getPeerInfo(std::pair& peerinfo) const peerinfo = SocketCore::getNameInfoInNumeric(addrp, len); } -void SocketCore::establishConnection(const std::string& host, int32_t port) +void SocketCore::establishConnection(const std::string& host, uint16_t port) { closeConnection(); @@ -262,7 +259,7 @@ void SocketCore::setNonBlockingMode() throw new DlAbortEx(EX_SOCKET_NONBLOCKING, errorMsg()); } #else - int32_t flags; + int flags; while((flags = fcntl(sockfd, F_GETFL, 0)) == -1 && errno == EINTR); // TODO add error handling while(fcntl(sockfd, F_SETFL, flags|O_NONBLOCK) == -1 && errno == EINTR); @@ -278,7 +275,7 @@ void SocketCore::setBlockingMode() throw new DlAbortEx(EX_SOCKET_BLOCKING, errorMsg()); } #else - int32_t flags; + int flags; while((flags = fcntl(sockfd, F_GETFL, 0)) == -1 && errno == EINTR); // TODO add error handling while(fcntl(sockfd, F_SETFL, flags&(~O_NONBLOCK)) == -1 && errno == EINTR); @@ -318,7 +315,7 @@ void SocketCore::closeConnection() #endif // HAVE_LIBGNUTLS } -bool SocketCore::isWritable(int32_t timeout) const +bool SocketCore::isWritable(time_t timeout) const { fd_set fds; FD_ZERO(&fds); @@ -328,7 +325,7 @@ bool SocketCore::isWritable(int32_t timeout) const tv.tv_sec = timeout; tv.tv_usec = 0; - int32_t r = select(sockfd+1, NULL, &fds, NULL, &tv); + int r = select(sockfd+1, NULL, &fds, NULL, &tv); if(r == 1) { return true; } else if(r == 0) { @@ -343,7 +340,7 @@ bool SocketCore::isWritable(int32_t timeout) const } } -bool SocketCore::isReadable(int32_t timeout) const +bool SocketCore::isReadable(time_t timeout) const { #ifdef HAVE_LIBGNUTLS if(secure && peekBufLength > 0) { @@ -358,7 +355,7 @@ bool SocketCore::isReadable(int32_t timeout) const tv.tv_sec = timeout; tv.tv_usec = 0; - int32_t r = select(sockfd+1, &fds, NULL, NULL, &tv); + int r = select(sockfd+1, &fds, NULL, NULL, &tv); if(r == 1) { return true; } else if(r == 0) { @@ -373,38 +370,40 @@ bool SocketCore::isReadable(int32_t timeout) const } } -void SocketCore::writeData(const char* data, int32_t len) +void SocketCore::writeData(const char* data, size_t len) { - int32_t ret = 0; + ssize_t ret = 0; if(!secure) { - while((ret = send(sockfd, data, (size_t)len, 0)) == -1 && errno == EINTR); + while((ret = send(sockfd, data, len, 0)) == -1 && errno == EINTR); // TODO assuming Blocking mode. - if(ret != len) { + if(ret == -1 || (size_t)ret != len) { throw new DlRetryEx(EX_SOCKET_SEND, errorMsg()); } } else { #ifdef HAVE_LIBSSL // for SSL // TODO handling len == 0 case required - if((ret = SSL_write(ssl, data, len)) != len) { + ret = SSL_write(ssl, data, len); + if(ret <= 0 || (size_t)ret != len) { throw new DlRetryEx(EX_SOCKET_SEND, ERR_error_string(ERR_get_error(), NULL)); } #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS - if((ret = gnutls_record_send(sslSession, data, len)) != len) { + ret = gnutls_record_send(sslSession, data, len); + if(ret < 0 || (size_t)ret != len) { throw new DlRetryEx(EX_SOCKET_SEND, gnutls_strerror(ret)); } #endif // HAVE_LIBGNUTLS } } -void SocketCore::readData(char* data, int32_t& len) +void SocketCore::readData(char* data, size_t& len) { - int32_t ret = 0; + ssize_t ret = 0; if(!secure) { - while((ret = recv(sockfd, data, (size_t)len, 0)) == -1 && errno == EINTR); + while((ret = recv(sockfd, data, len, 0)) == -1 && errno == EINTR); if(ret == -1) { throw new DlRetryEx(EX_SOCKET_RECV, errorMsg()); } @@ -412,7 +411,7 @@ void SocketCore::readData(char* data, int32_t& len) #ifdef HAVE_LIBSSL // for SSL // TODO handling len == 0 case required - if ((ret = SSL_read(ssl, data, len)) < 0) { + if ((ret = SSL_read(ssl, data, len)) <= 0) { throw new DlRetryEx(EX_SOCKET_RECV, ERR_error_string(ERR_get_error(), NULL)); } #endif // HAVE_LIBSSL @@ -426,12 +425,12 @@ void SocketCore::readData(char* data, int32_t& len) len = ret; } -void SocketCore::peekData(char* data, int32_t& len) +void SocketCore::peekData(char* data, size_t& len) { - int32_t ret = 0; + ssize_t ret = 0; if(!secure) { - while((ret = recv(sockfd, data, (size_t)len, MSG_PEEK)) == -1 && errno == EINTR); + while((ret = recv(sockfd, data, len, MSG_PEEK)) == -1 && errno == EINTR); if(ret == -1) { throw new DlRetryEx(EX_SOCKET_PEEK, errorMsg()); } @@ -454,11 +453,11 @@ void SocketCore::peekData(char* data, int32_t& len) } #ifdef HAVE_LIBGNUTLS -int32_t SocketCore::shiftPeekData(char* data, int32_t len) +size_t SocketCore::shiftPeekData(char* data, size_t len) { if(peekBufLength <= len) { memcpy(data, peekBuf, peekBufLength); - int32_t ret = peekBufLength; + size_t ret = peekBufLength; peekBufLength = 0; return ret; } else { @@ -473,7 +472,7 @@ int32_t SocketCore::shiftPeekData(char* data, int32_t len) } -void SocketCore::addPeekData(char* data, int32_t len) +void SocketCore::addPeekData(char* data, size_t len) { if(peekBufLength+len > peekBufMax) { char* temp = new char[peekBufMax+len]; @@ -486,11 +485,11 @@ void SocketCore::addPeekData(char* data, int32_t len) peekBufLength += len; } -int32_t SocketCore::gnutlsRecv(char* data, int32_t len) +ssize_t SocketCore::gnutlsRecv(char* data, size_t len) { - int32_t plen = shiftPeekData(data, len); + size_t plen = shiftPeekData(data, len); if(plen < len) { - int32_t ret = gnutls_record_recv(sslSession, data+plen, len-plen); + ssize_t ret = gnutls_record_recv(sslSession, data+plen, len-plen); if(ret < 0) { throw new DlRetryEx(EX_SOCKET_RECV, gnutls_strerror(ret)); } @@ -500,14 +499,14 @@ int32_t SocketCore::gnutlsRecv(char* data, int32_t len) } } -int32_t SocketCore::gnutlsPeek(char* data, int32_t len) +ssize_t SocketCore::gnutlsPeek(char* data, size_t len) { if(peekBufLength >= len) { memcpy(data, peekBuf, len); return len; } else { memcpy(data, peekBuf, peekBufLength); - int32_t ret = gnutls_record_recv(sslSession, data+peekBufLength, len-peekBufLength); + ssize_t ret = gnutls_record_recv(sslSession, data+peekBufLength, len-peekBufLength); if(ret < 0) { throw new DlRetryEx(EX_SOCKET_PEEK, gnutls_strerror(ret)); } @@ -566,8 +565,8 @@ void SocketCore::initiateSecureConnection() #endif // HAVE_LIBSSL #ifdef HAVE_LIBGNUTLS if(!secure) { - const int32_t cert_type_priority[3] = { GNUTLS_CRT_X509, - GNUTLS_CRT_OPENPGP, 0 + const int cert_type_priority[3] = { GNUTLS_CRT_X509, + GNUTLS_CRT_OPENPGP, 0 }; // while we do not support X509 certificate, most web servers require // X509 stuff. @@ -578,7 +577,7 @@ void SocketCore::initiateSecureConnection() // put the x509 credentials to the current session gnutls_credentials_set(sslSession, GNUTLS_CRD_CERTIFICATE, sslXcred); gnutls_transport_set_ptr(sslSession, (gnutls_transport_ptr_t)sockfd); - int32_t ret = gnutls_handshake(sslSession); + int ret = gnutls_handshake(sslSession); if(ret < 0) { throw new DlAbortEx(EX_SSL_INIT_FAILURE, gnutls_strerror(ret)); } diff --git a/src/SocketCore.h b/src/SocketCore.h index a7a54bcd2c..cc4d54a93f 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -59,9 +59,7 @@ class SocketCore { // socket type defined in int _sockType; // socket endpoint descriptor - int32_t sockfd; - // reference counter for this object. - int32_t use; + int sockfd; bool blocking; bool secure; #ifdef HAVE_LIBSSL @@ -73,17 +71,17 @@ class SocketCore { gnutls_session_t sslSession; gnutls_certificate_credentials_t sslXcred; char* peekBuf; - int32_t peekBufLength; - int32_t peekBufMax; + size_t peekBufLength; + size_t peekBufMax; - int32_t shiftPeekData(char* data, int32_t len); - void addPeekData(char* data, int32_t len); - int32_t gnutlsRecv(char* data, int32_t len); - int32_t gnutlsPeek(char* data, int32_t len); + size_t shiftPeekData(char* data, size_t len); + void addPeekData(char* data, size_t len); + ssize_t gnutlsRecv(char* data, size_t len); + ssize_t gnutlsPeek(char* data, size_t len); #endif // HAVE_LIBGNUTLS void init(); - SocketCore(int32_t sockfd, int sockType); + SocketCore(int sockfd, int sockType); static int error(); static const char *errorMsg(); static const char *errorMsg(const int err); @@ -94,7 +92,7 @@ class SocketCore { SocketCore(int sockType = SOCK_STREAM); ~SocketCore(); - int32_t getSockfd() const { return sockfd; } + int getSockfd() const { return sockfd; } bool isOpen() const { return sockfd != -1; } @@ -115,13 +113,13 @@ class SocketCore { * Stores host address and port of this socket to addrinfo. * @param addrinfo placeholder to store host address and port. */ - void getAddrInfo(std::pair& addrinfo) const; + void getAddrInfo(std::pair& addrinfo) const; /** * Stores peer's address and port to peerinfo. * @param peerinfo placeholder to store peer's address and port. */ - void getPeerInfo(std::pair& peerinfo) const; + void getPeerInfo(std::pair& peerinfo) const; /** * Accepts incoming connection on this socket. @@ -138,7 +136,7 @@ class SocketCore { * @param host hostname or ip address to connect to * @param port service port number to connect to */ - void establishConnection(const std::string& host, int32_t port); + void establishConnection(const std::string& host, uint16_t port); void setNonBlockingMode(); @@ -159,7 +157,7 @@ class SocketCore { * @return true if the socket is available for writing, * otherwise returns false. */ - bool isWritable(int32_t timeout) const; + bool isWritable(time_t timeout) const; /** * Checks whether this socket is available for reading. @@ -168,7 +166,7 @@ class SocketCore { * @return true if the socket is available for reading, * otherwise returns false. */ - bool isReadable(int32_t timeout) const; + bool isReadable(time_t timeout) const; /** * Writes characters into this socket. data is a pointer pointing the first @@ -178,12 +176,12 @@ class SocketCore { * @param data data to write * @param len length of data */ - void writeData(const char* data, int32_t len); + void writeData(const char* data, size_t len); void writeData(const std::string& msg) { writeData(msg.c_str(), msg.size()); } - void writeData(const unsigned char* data, int32_t len) + void writeData(const unsigned char* data, size_t len) { writeData(reinterpret_cast(data), len); } @@ -208,9 +206,9 @@ class SocketCore { * @param len the maximum size data can store. This method assigns * the number of bytes read to len. */ - void readData(char* data, int32_t& len); + void readData(char* data, size_t& len); - void readData(unsigned char* data, int32_t& len) + void readData(unsigned char* data, size_t& len) { readData(reinterpret_cast(data), len); } @@ -235,9 +233,9 @@ class SocketCore { * @param len the maximum size data can store. This method assigns * the number of bytes read to len. */ - void peekData(char* data, int32_t& len); + void peekData(char* data, size_t& len); - void peekData(unsigned char* data, int32_t& len) + void peekData(unsigned char* data, size_t& len) { peekData(reinterpret_cast(data), len); } diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc index 9bdb92b5b8..df0d0f9284 100644 --- a/src/SpeedCalc.cc +++ b/src/SpeedCalc.cc @@ -34,6 +34,7 @@ /* copyright --> */ #include "SpeedCalc.h" #include +#include namespace aria2 { @@ -57,10 +58,10 @@ void SpeedCalc::reset() { nextInterval = CHANGE_INTERVAL_SEC; } -int32_t SpeedCalc::calculateSpeed() { - int32_t milliElapsed = cpArray[sw].differenceInMillis(); +unsigned int SpeedCalc::calculateSpeed() { + uint64_t milliElapsed = cpArray[sw].differenceInMillis(); if(milliElapsed) { - int32_t speed = lengthArray[sw]*1000/milliElapsed; + unsigned int speed = lengthArray[sw]*1000/milliElapsed; prevSpeed = speed; maxSpeed = std::max(speed, maxSpeed); return speed; @@ -69,10 +70,10 @@ int32_t SpeedCalc::calculateSpeed() { } } -int32_t SpeedCalc::calculateSpeed(const struct timeval& now) { - int64_t milliElapsed = cpArray[sw].differenceInMillis(now); +unsigned int SpeedCalc::calculateSpeed(const struct timeval& now) { + uint64_t milliElapsed = cpArray[sw].differenceInMillis(now); if(milliElapsed) { - int32_t speed = lengthArray[sw]*1000/milliElapsed; + unsigned int speed = lengthArray[sw]*1000/milliElapsed; prevSpeed = speed; maxSpeed = std::max(speed, maxSpeed); return speed; @@ -81,20 +82,10 @@ int32_t SpeedCalc::calculateSpeed(const struct timeval& now) { } } -class Plus { -private: - int32_t d; -public: - Plus(int32_t d):d(d) {} - - void operator()(int64_t& length) { - length += d; - } -}; - -void SpeedCalc::update(int bytes) { +void SpeedCalc::update(size_t bytes) { accumulatedLength += bytes; - std::for_each(&lengthArray[0], &lengthArray[2], Plus(bytes)); + std::transform(&lengthArray[0], &lengthArray[2], &lengthArray[0], + std::bind1st(std::plus(), (uint64_t)bytes)); if(isIntervalOver()) { changeSw(); } @@ -111,10 +102,10 @@ void SpeedCalc::changeSw() { nextInterval = cpArray[sw].difference()+CHANGE_INTERVAL_SEC; } -int32_t SpeedCalc::getAvgSpeed() const { - int32_t milliElapsed = start.differenceInMillis(); +unsigned int SpeedCalc::getAvgSpeed() const { + uint64_t milliElapsed = start.differenceInMillis(); if(milliElapsed) { - int32_t speed = accumulatedLength*1000/milliElapsed; + unsigned int speed = accumulatedLength*1000/milliElapsed; return speed; } else { return 0; diff --git a/src/SpeedCalc.h b/src/SpeedCalc.h index 28e6c59a09..c9677ee178 100644 --- a/src/SpeedCalc.h +++ b/src/SpeedCalc.h @@ -42,14 +42,14 @@ namespace aria2 { class SpeedCalc { private: - int64_t lengthArray[2]; - int32_t sw; + uint64_t lengthArray[2]; + int sw; Time cpArray[2]; - int32_t maxSpeed; - int32_t prevSpeed; + unsigned int maxSpeed; + unsigned int prevSpeed; Time start; - int64_t accumulatedLength; - int32_t nextInterval; + uint64_t accumulatedLength; + time_t nextInterval; bool isIntervalOver() const; void changeSw(); @@ -63,17 +63,17 @@ class SpeedCalc { /** * Returns download/upload speed in byte per sec */ - int32_t calculateSpeed(); + unsigned int calculateSpeed(); - int32_t calculateSpeed(const struct timeval& now); + unsigned int calculateSpeed(const struct timeval& now); - int32_t getMaxSpeed() const { + unsigned int getMaxSpeed() const { return maxSpeed; } - int32_t getAvgSpeed() const; + unsigned int getAvgSpeed() const; - void update(int bytes); + void update(size_t bytes); void reset(); }; diff --git a/src/TimeBasedCommand.cc b/src/TimeBasedCommand.cc index e2669e5d6b..5628aa74ee 100644 --- a/src/TimeBasedCommand.cc +++ b/src/TimeBasedCommand.cc @@ -37,7 +37,7 @@ namespace aria2 { -TimeBasedCommand::TimeBasedCommand(int32_t cuid, DownloadEngine* e, int32_t interval): +TimeBasedCommand::TimeBasedCommand(int32_t cuid, DownloadEngine* e, time_t interval): Command(cuid), _e(e),_exit(false), _interval(interval) {} TimeBasedCommand::~TimeBasedCommand() {} diff --git a/src/TimeBasedCommand.h b/src/TimeBasedCommand.h index ab0d53c12e..ad105e4b91 100644 --- a/src/TimeBasedCommand.h +++ b/src/TimeBasedCommand.h @@ -56,7 +56,7 @@ class TimeBasedCommand : public Command */ bool _exit; - int32_t _interval; // unit: sec + time_t _interval; // unit: sec private: Time _checkPoint; public: @@ -77,7 +77,7 @@ class TimeBasedCommand : public Command virtual void postProcess() {}; public: - TimeBasedCommand(int32_t cuid, DownloadEngine* e, int32_t interval); + TimeBasedCommand(int32_t cuid, DownloadEngine* e, time_t interval); virtual ~TimeBasedCommand(); diff --git a/src/TimeSeedCriteria.h b/src/TimeSeedCriteria.h index b8561a3ac3..55e74c2f49 100644 --- a/src/TimeSeedCriteria.h +++ b/src/TimeSeedCriteria.h @@ -43,10 +43,10 @@ namespace aria2 { class TimeSeedCriteria : public SeedCriteria { private: // How much time the client does seeding in seconds. - int32_t duration; + time_t duration; Time watch; public: - TimeSeedCriteria(int32_t duration):duration(duration) {} + TimeSeedCriteria(time_t duration):duration(duration) {} virtual ~TimeSeedCriteria() {} virtual void reset() { @@ -57,11 +57,11 @@ class TimeSeedCriteria : public SeedCriteria { return watch.elapsed(duration); } - void setDuration(int32_t duration) { + void setDuration(time_t duration) { this->duration = duration; } - int32_t getDuration() const { + time_t getDuration() const { return duration; } }; diff --git a/src/TimedHaltCommand.cc b/src/TimedHaltCommand.cc index 75ac3b6758..1d35766ebb 100644 --- a/src/TimedHaltCommand.cc +++ b/src/TimedHaltCommand.cc @@ -41,7 +41,7 @@ namespace aria2 { TimedHaltCommand::TimedHaltCommand(int32_t cuid, DownloadEngine* e, - int32_t secondsToHalt): + time_t secondsToHalt): TimeBasedCommand(cuid, e, secondsToHalt) {} TimedHaltCommand::~TimedHaltCommand() {} diff --git a/src/TimedHaltCommand.h b/src/TimedHaltCommand.h index 099e6d7351..4e29b500d8 100644 --- a/src/TimedHaltCommand.h +++ b/src/TimedHaltCommand.h @@ -41,7 +41,7 @@ namespace aria2 { class TimedHaltCommand:public TimeBasedCommand { public: - TimedHaltCommand(int32_t cuid, DownloadEngine* e, int32_t secondsToHalt); + TimedHaltCommand(int32_t cuid, DownloadEngine* e, time_t secondsToHalt); virtual ~TimedHaltCommand(); diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index c367fa5e20..9180c272aa 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -128,11 +128,11 @@ std::string TrackerWatcherCommand::getTrackerResponse(const RequestGroupHandle& unsigned char data[2048]; requestGroup->getPieceStorage()->getDiskAdaptor()->openFile(); while(1) { - int32_t dataLength = requestGroup->getPieceStorage()->getDiskAdaptor()->readData(data, sizeof(data), strm.tellp()); - strm.write(reinterpret_cast(data), dataLength); + ssize_t dataLength = requestGroup->getPieceStorage()->getDiskAdaptor()->readData(data, sizeof(data), strm.tellp()); if(dataLength == 0) { break; } + strm.write(reinterpret_cast(data), dataLength); } return strm.str(); } diff --git a/src/TransferEncoding.h b/src/TransferEncoding.h index 406f17246c..8f80edd613 100644 --- a/src/TransferEncoding.h +++ b/src/TransferEncoding.h @@ -45,8 +45,8 @@ class TransferEncoding { public: virtual ~TransferEncoding() {} virtual void init() = 0; - virtual void inflate(unsigned char* outbuf, int32_t& outlen, - const unsigned char* inbuf, int32_t inlen) = 0; + virtual void inflate(unsigned char* outbuf, size_t& outlen, + const unsigned char* inbuf, size_t inlen) = 0; virtual bool finished() = 0; virtual void end() = 0; }; diff --git a/src/TransferStat.h b/src/TransferStat.h index 5761eaab62..ce153e86af 100644 --- a/src/TransferStat.h +++ b/src/TransferStat.h @@ -42,11 +42,11 @@ namespace aria2 { class TransferStat { public: - int32_t downloadSpeed; - int32_t uploadSpeed; - int64_t sessionDownloadLength; - int64_t sessionUploadLength; - int64_t allTimeUploadLength; + unsigned int downloadSpeed; + unsigned int uploadSpeed; + uint64_t sessionDownloadLength; + uint64_t sessionUploadLength; + uint64_t allTimeUploadLength; void copy(const TransferStat& stat) { @@ -76,44 +76,44 @@ class TransferStat { friend TransferStat operator+(const TransferStat& a, const TransferStat& b); - int32_t getDownloadSpeed() const { + unsigned int getDownloadSpeed() const { return downloadSpeed; } - void setDownloadSpeed(int32_t s) { downloadSpeed = s; } + void setDownloadSpeed(unsigned int s) { downloadSpeed = s; } - int32_t getUploadSpeed() const { + unsigned int getUploadSpeed() const { return uploadSpeed; } - void setUploadSpeed(int32_t s) { uploadSpeed = s; } + void setUploadSpeed(unsigned int s) { uploadSpeed = s; } /** * Returns the number of bytes downloaded since the program started. * This is not the total number of bytes downloaded. */ - int64_t getSessionDownloadLength() const { + uint64_t getSessionDownloadLength() const { return sessionDownloadLength; } - void setSessionDownloadLength(int64_t s) { sessionDownloadLength = s; } + void setSessionDownloadLength(uint64_t s) { sessionDownloadLength = s; } /** * Returns the number of bytes uploaded since the program started. * This is not the total number of bytes uploaded. */ - int64_t getSessionUploadLength() const { + uint64_t getSessionUploadLength() const { return sessionUploadLength; } - void setSessionUploadLength(int64_t s) { sessionUploadLength = s; } + void setSessionUploadLength(uint64_t s) { sessionUploadLength = s; } - void setAllTimeUploadLength(int64_t s) + void setAllTimeUploadLength(uint64_t s) { allTimeUploadLength = s; } - int64_t getAllTimeUploadLength() const + uint64_t getAllTimeUploadLength() const { return allTimeUploadLength; } diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc index c94d455463..603b38d652 100644 --- a/src/UTPexExtensionMessage.cc +++ b/src/UTPexExtensionMessage.cc @@ -136,8 +136,7 @@ UTPexExtensionMessage::create(const BtContextHandle& btContext, } const Dictionary* d = dynamic_cast(root.get()); if(d) { - CompactPeerListProcessor proc(btContext->getPieceLength(), - btContext->getTotalLength()); + CompactPeerListProcessor proc; const Data* added = dynamic_cast(d->get("added")); if(added) { msg->_freshPeers = proc.extractPeer(added); diff --git a/src/Util.cc b/src/Util.cc index 0d9b0429f9..e00844a946 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -201,9 +201,9 @@ bool Util::shouldUrlencode(const char c) '@' == c || '&' == c || '=' == c || '+' == c); } -std::string Util::urlencode(const unsigned char* target, int32_t len) { +std::string Util::urlencode(const unsigned char* target, size_t len) { std::string dest; - for(int32_t i = 0; i < len; i++) { + for(size_t i = 0; i < len; i++) { if(shouldUrlencode(target[i])) { char temp[4]; sprintf(temp, "%%%02x", target[i]); @@ -216,9 +216,9 @@ std::string Util::urlencode(const unsigned char* target, int32_t len) { return dest; } -std::string Util::torrentUrlencode(const unsigned char* target, int32_t len) { +std::string Util::torrentUrlencode(const unsigned char* target, size_t len) { std::string dest; - for(int32_t i = 0; i < len; i++) { + for(size_t i = 0; i < len; i++) { if('0' <= target[i] && target[i] <= '9' || 'A' <= target[i] && target[i] <= 'Z' || 'a' <= target[i] && target[i] <= 'z') { @@ -252,9 +252,9 @@ std::string Util::urldecode(const std::string& target) { return result; } -std::string Util::toHex(const unsigned char* src, int32_t len) { +std::string Util::toHex(const unsigned char* src, size_t len) { char* temp = new char[len*2+1]; - for(int32_t i = 0; i < len; i++) { + for(size_t i = 0; i < len; i++) { sprintf(temp+i*2, "%02x", src[i]); } temp[len*2] = '\0'; @@ -273,9 +273,9 @@ void Util::fileCopy(const std::string& dest, const std::string& src) { rangedFileCopy(dest, src, 0, file.size()); } -void Util::rangedFileCopy(const std::string& dest, const std::string& src, int64_t srcOffset, int64_t length) +void Util::rangedFileCopy(const std::string& dest, const std::string& src, off_t srcOffset, uint64_t length) { - int32_t bufSize = 4096; + size_t bufSize = 4096; unsigned char buf[bufSize]; DefaultDiskWriter srcdw; DefaultDiskWriter destdw; @@ -283,23 +283,24 @@ void Util::rangedFileCopy(const std::string& dest, const std::string& src, int64 srcdw.openExistingFile(src); destdw.initAndOpenFile(dest); - int32_t x = length/bufSize; - int32_t r = length%bufSize; + lldiv_t res = lldiv(length, bufSize); + unsigned int x = res.quot; + unsigned int r = res.rem; - int64_t initialOffset = srcOffset; - for(int32_t i = 0; i < x; ++i) { - int32_t readLength = 0; + off_t initialOffset = srcOffset; + for(unsigned int i = 0; i < x; ++i) { + size_t readLength = 0; while(readLength < bufSize) { - int32_t ret = srcdw.readData(buf, bufSize-readLength, srcOffset); + ssize_t ret = srcdw.readData(buf, bufSize-readLength, srcOffset); destdw.writeData(buf, ret, srcOffset-initialOffset); srcOffset += ret; readLength += ret; } } if(r > 0) { - int32_t readLength = 0; + size_t readLength = 0; while(readLength < r) { - int32_t ret = srcdw.readData(buf, r-readLength, srcOffset); + ssize_t ret = srcdw.readData(buf, r-readLength, srcOffset); destdw.writeData(buf, ret, srcOffset-initialOffset); srcOffset += ret; readLength += ret; @@ -307,7 +308,7 @@ void Util::rangedFileCopy(const std::string& dest, const std::string& src, int64 } } -bool Util::isPowerOf(int32_t num, int32_t base) { +bool Util::isPowerOf(int num, int base) { if(base <= 0) { return false; } if(base == 1) { return true; } @@ -320,14 +321,14 @@ bool Util::isPowerOf(int32_t num, int32_t base) { return false; } -std::string Util::secfmt(int32_t sec) { +std::string Util::secfmt(time_t sec) { std::string str; if(sec >= 3600) { str = itos(sec/3600)+"h"; sec %= 3600; } if(sec >= 60) { - int32_t min = sec/60; + int min = sec/60; if(min < 10) { str += "0"; } @@ -341,7 +342,7 @@ std::string Util::secfmt(int32_t sec) { return str; } -int32_t Util::expandBuffer(char** pbuf, int32_t curLength, int32_t newLength) { +size_t Util::expandBuffer(char** pbuf, size_t curLength, size_t newLength) { char* newbuf = new char[newLength]; memcpy(newbuf, *pbuf, curLength); delete [] *pbuf; @@ -349,16 +350,16 @@ int32_t Util::expandBuffer(char** pbuf, int32_t curLength, int32_t newLength) { return newLength; } -int32_t getNum(const char* buf, int32_t offset, int32_t length) { +int getNum(const char* buf, int offset, size_t length) { char* temp = new char[length+1]; memcpy(temp, buf+offset, length); temp[length] = '\0'; - int32_t x = strtol(temp, NULL, 10); + int x = strtol(temp, 0, 10); delete [] temp; return x; } -void unfoldSubRange(const std::string& src, std::deque& range) { +void unfoldSubRange(const std::string& src, std::deque& range) { if(src.empty()) { return; } @@ -369,18 +370,18 @@ void unfoldSubRange(const std::string& src, std::deque& range) { range.push_back(atoi(src.c_str())); } else { if(src.at(p) == ',') { - int32_t num = getNum(src.c_str(), 0, p); + int num = getNum(src.c_str(), 0, p); range.push_back(num); unfoldSubRange(src.substr(p+1), range); } else if(src.at(p) == '-') { - int32_t rightNumBegin = p+1; + std::string::size_type rightNumBegin = p+1; std::string::size_type nextDelim = src.find_first_of(",", rightNumBegin); if(nextDelim == std::string::npos) { nextDelim = src.size(); } - int32_t left = getNum(src.c_str(), 0, p); - int32_t right = getNum(src.c_str(), rightNumBegin, nextDelim-rightNumBegin); - for(int32_t i = left; i <= right; i++) { + int left = getNum(src.c_str(), 0, p); + int right = getNum(src.c_str(), rightNumBegin, nextDelim-rightNumBegin); + for(int i = left; i <= right; i++) { range.push_back(i); } if(src.size() > nextDelim) { @@ -390,7 +391,7 @@ void unfoldSubRange(const std::string& src, std::deque& range) { } } -void Util::unfoldRange(const std::string& src, std::deque& range) { +void Util::unfoldRange(const std::string& src, std::deque& range) { unfoldSubRange(src, range); std::sort(range.begin(), range.end()); range.erase(std::unique(range.begin(), range.end()), range.end()); @@ -486,7 +487,7 @@ std::string Util::getContentDispositionFilename(const std::string& header) { return trim(header.substr(filenamesp, filenameep-filenamesp), "\r\n '\""); } -static int32_t nbits[] = { +static int nbits[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, @@ -505,7 +506,7 @@ static int32_t nbits[] = { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, }; -int32_t Util::countBit(uint32_t n) { +unsigned int Util::countBit(uint32_t n) { return nbits[n&0xffu]+ nbits[(n >> 8)&0xffu]+ @@ -513,11 +514,11 @@ int32_t Util::countBit(uint32_t n) { nbits[(n >> 24)&0xffu]; } -std::string Util::randomAlpha(int32_t length, const RandomizerHandle& randomizer) { +std::string Util::randomAlpha(size_t length, const RandomizerHandle& randomizer) { static const char *random_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; std::string str; - for(int32_t i = 0; i < length; i++) { - int32_t index = randomizer->getRandomNumber(strlen(random_chars)); + for(size_t i = 0; i < length; i++) { + size_t index = randomizer->getRandomNumber(strlen(random_chars)); str += random_chars[index]; } return str; @@ -544,7 +545,7 @@ bool Util::isNumbersAndDotsNotation(const std::string& name) { } } -void Util::setGlobalSignalHandler(int32_t sig, void (*handler)(int), int32_t flags) { +void Util::setGlobalSignalHandler(int sig, void (*handler)(int), int flags) { #ifdef HAVE_SIGACTION struct sigaction sigact; sigact.sa_handler = handler; @@ -556,8 +557,8 @@ void Util::setGlobalSignalHandler(int32_t sig, void (*handler)(int), int32_t fla #endif // HAVE_SIGACTION } -void Util::indexRange(int32_t& startIndex, int32_t& endIndex, - int64_t offset, int32_t srcLength, int32_t destLength) +void Util::indexRange(size_t& startIndex, size_t& endIndex, + off_t offset, size_t srcLength, size_t destLength) { int64_t _startIndex = offset/destLength; int64_t _endIndex = (offset+srcLength-1)/destLength; @@ -609,9 +610,9 @@ std::string Util::abbrevSize(int64_t size) return Util::itos(size, true); } char units[] = { 'K', 'M' }; - int32_t numUnit = sizeof(units)/sizeof(char); - int32_t i = 0; - int32_t r = size&0x3ff; + size_t numUnit = sizeof(units)/sizeof(char); + size_t i = 0; + int r = size&0x3ff; size >>= 10; for(; i < numUnit-1 && size >= 1024; ++i) { r = size&0x3ff; @@ -729,7 +730,7 @@ bool Util::isUppercase(const std::string& what) return true; } -int32_t Util::alphaToNum(const std::string& alphabets) +int Util::alphaToNum(const std::string& alphabets) { if(alphabets.empty()) { return 0; @@ -740,9 +741,9 @@ int32_t Util::alphaToNum(const std::string& alphabets) } else { base = 'A'; } - int32_t num = 0; - for(uint32_t i = 0; i < alphabets.size(); ++i) { - int32_t v = alphabets[i]-base; + int num = 0; + for(size_t i = 0; i < alphabets.size(); ++i) { + int v = alphabets[i]-base; num = num*26+v; } return num; @@ -792,7 +793,7 @@ std::string Util::toString(const BinaryStreamHandle& binaryStream) void* Util::allocateAlignedMemory(size_t alignment, size_t size) { void* buffer; - int32_t res; + int res; if((res = posix_memalign(&buffer, alignment, size)) != 0) { throw new FatalException("Error in posix_memalign: %s", strerror(res)); } diff --git a/src/Util.h b/src/Util.h index 6013ba56e3..3cec6dcf28 100644 --- a/src/Util.h +++ b/src/Util.h @@ -51,7 +51,8 @@ class BitfieldMan; class BinaryStream; class FileEntry; -#define STRTOLL(X) strtoll(X, (char**)NULL, 10) +#define STRTOLL(X) strtoll(X, (char**)0, 10) +#define STRTOULL(X) strtoull(X, (char**)0, 10) #define START_INDEX(OFFSET, PIECE_LENGTH) ((OFFSET)/(PIECE_LENGTH)) #define END_INDEX(OFFSET, LENGTH, PIECE_LENGTH) (((OFFSET)+(LENGTH)-1)/(PIECE_LENGTH)) @@ -74,7 +75,7 @@ class Util { str = "0"; return str; } - int32_t count = 0; + unsigned int count = 0; while(value) { ++count; char digit = value%10+'0'; @@ -124,7 +125,7 @@ class Util { static std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr); - static std::string urlencode(const unsigned char* target, int32_t len); + static std::string urlencode(const unsigned char* target, size_t len); static std::string urlencode(const std::string& target) { @@ -135,7 +136,7 @@ class Util { static std::string urldecode(const std::string& target); - static std::string torrentUrlencode(const unsigned char* target, int32_t len); + static std::string torrentUrlencode(const unsigned char* target, size_t len); static std::string torrentUrlencode(const std::string& target) { @@ -143,7 +144,7 @@ class Util { target.size()); } - static std::string toHex(const unsigned char* src, int32_t len); + static std::string toHex(const unsigned char* src, size_t len); static std::string toHex(const std::string& src) { @@ -154,15 +155,15 @@ class Util { static void fileCopy(const std::string& destFile, const std::string& src); - static void rangedFileCopy(const std::string& destFile, const std::string& src, int64_t srcOffset, int64_t length); + static void rangedFileCopy(const std::string& destFile, const std::string& src, off_t srcOffset, uint64_t length); - static bool isPowerOf(int32_t num, int32_t base); + static bool isPowerOf(int num, int base); - static std::string secfmt(int32_t sec); + static std::string secfmt(time_t sec); - static int32_t expandBuffer(char** pbuf, int32_t curLength, int32_t newLength); + static size_t expandBuffer(char** pbuf, size_t curLength, size_t newLength); - static void unfoldRange(const std::string& src, std::deque& range); + static void unfoldRange(const std::string& src, std::deque& range); static int32_t parseInt(const std::string& s, int32_t base = 10); @@ -173,9 +174,9 @@ class Util { // this function temporarily put here static std::string getContentDispositionFilename(const std::string& header); - static int32_t countBit(uint32_t n); + static unsigned int countBit(uint32_t n); - static std::string randomAlpha(int32_t length, + static std::string randomAlpha(size_t length, const SharedHandle& randomizer); static std::string toUpper(const std::string& src); @@ -184,11 +185,11 @@ class Util { static bool isNumbersAndDotsNotation(const std::string& name); - static void setGlobalSignalHandler(int32_t signal, void (*handler)(int), int32_t flags); + static void setGlobalSignalHandler(int signal, void (*handler)(int), int flags); - static void indexRange(int32_t& startIndex, int32_t& endIndex, - int64_t offset, - int32_t srcLength, int32_t destLength); + static void indexRange(size_t& startIndex, size_t& endIndex, + off_t offset, + size_t srcLength, size_t destLength); static std::string getHomeDir(); @@ -211,7 +212,7 @@ class Util { static bool isUppercase(const std::string& what); - static int32_t alphaToNum(const std::string& alphabets); + static int alphaToNum(const std::string& alphabets); static void mkdirs(const std::string& dirpath); diff --git a/src/VerificationMetalinkParserState.cc b/src/VerificationMetalinkParserState.cc index c962b6d23b..e90811b442 100644 --- a/src/VerificationMetalinkParserState.cc +++ b/src/VerificationMetalinkParserState.cc @@ -56,7 +56,7 @@ void VerificationMetalinkParserState::beginElement(MetalinkParserStateMachine* s } else if(name == "pieces") { stm->setPiecesState(); try { - int32_t length; + size_t length; { std::map::const_iterator itr = attrs.find("length"); if(itr == attrs.end()) { diff --git a/src/XML2SAXMetalinkProcessor.cc b/src/XML2SAXMetalinkProcessor.cc index b4c1dd698a..e169eee836 100644 --- a/src/XML2SAXMetalinkProcessor.cc +++ b/src/XML2SAXMetalinkProcessor.cc @@ -128,8 +128,8 @@ XML2SAXMetalinkProcessor::parseFile(const std::string& filename) { _stm = new MetalinkParserStateMachine(); SharedHandle sessionData = new SessionData(_stm); - int32_t retval = xmlSAXUserParseFile(&mySAXHandler, sessionData.get(), - filename.c_str()); + int retval = xmlSAXUserParseFile(&mySAXHandler, sessionData.get(), + filename.c_str()); if(retval != 0) { throw new DlAbortEx(MSG_CANNOT_PARSE_METALINK); } @@ -140,10 +140,10 @@ SharedHandle XML2SAXMetalinkProcessor::parseFromBinaryStream(const SharedHandle& binaryStream) { _stm = new MetalinkParserStateMachine(); - int32_t bufSize = 4096; + size_t bufSize = 4096; unsigned char buf[bufSize]; - int32_t res = binaryStream->readData(buf, 4, 0); + ssize_t res = binaryStream->readData(buf, 4, 0); if(res != 4) { throw new DlAbortEx("Too small data for parsing XML."); } @@ -151,9 +151,9 @@ XML2SAXMetalinkProcessor::parseFromBinaryStream(const SharedHandle SharedHandle sessionData = new SessionData(_stm); xmlParserCtxtPtr ctx = xmlCreatePushParserCtxt(&mySAXHandler, sessionData.get(), (const char*)buf, res, 0); try { - int64_t readOffset = res; + off_t readOffset = res; while(1) { - int32_t res = binaryStream->readData(buf, bufSize, readOffset); + ssize_t res = binaryStream->readData(buf, bufSize, readOffset); if(res == 0) { break; } diff --git a/src/a2algo.h b/src/a2algo.h index 1a5a8aab0b..81c3c34dc1 100644 --- a/src/a2algo.h +++ b/src/a2algo.h @@ -41,10 +41,10 @@ namespace aria2 { template OutputIterator ncopy(InputIterator first, InputIterator last, - int32_t count, OutputIterator destination) + size_t count, OutputIterator destination) { OutputIterator x = destination; - for(int32_t i = 0; i < count; ++i) { + while(count--) { x = std::copy(first, last, destination); } return x; diff --git a/src/messageDigest.cc b/src/messageDigest.cc index 848afbe083..190153141b 100644 --- a/src/messageDigest.cc +++ b/src/messageDigest.cc @@ -56,7 +56,7 @@ MessageDigestContext::digestAlgos(&digests[0], std::string MessageDigestContext::digestFinal() { - int32_t length = digestLength(algo); + size_t length = digestLength(algo); unsigned char* rawMD = new unsigned char[length]; digestFinal(rawMD); std::string rawMDString(&rawMD[0], &rawMD[length]); diff --git a/src/messageDigest.h b/src/messageDigest.h index 8186b0cd5a..62531ca5fe 100644 --- a/src/messageDigest.h +++ b/src/messageDigest.h @@ -56,7 +56,7 @@ class MessageDigestContext { typedef const EVP_MD* DigestAlgo; #endif // HAVE_LIBSSL #ifdef HAVE_LIBGCRYPT - typedef int32_t DigestAlgo; + typedef int DigestAlgo; #endif // HAVE_LIBGCRYPT typedef std::map DigestAlgoMap; private: @@ -112,7 +112,7 @@ class MessageDigestContext { return algos; } - static int digestLength(const std::string& algostring) + static size_t digestLength(const std::string& algostring) { return digestLength(getDigestAlgo(algostring)); } @@ -122,16 +122,16 @@ class MessageDigestContext { #if defined(HAVE_OLD_LIBSSL) void digestInit() {EVP_DigestInit(&ctx, algo);} void digestReset() {EVP_DigestInit(&ctx, algo);} - void digestUpdate(const void* data, int32_t length) {EVP_DigestUpdate(&ctx, data, length);} + void digestUpdate(const void* data, size_t length) {EVP_DigestUpdate(&ctx, data, length);} void digestFinal(unsigned char* md) { unsigned int len; EVP_DigestFinal(&ctx, md, &len); } void digestFree() {/*empty*/} - int32_t digestLength() const { + size_t digestLength() const { return digestLength(algo); } - static int32_t digestLength(DigestAlgo algo) { + static size_t digestLength(DigestAlgo algo) { return EVP_MD_size(algo); } @@ -143,7 +143,7 @@ class MessageDigestContext { void digestReset() { EVP_DigestInit_ex(&ctx, algo, 0); } - void digestUpdate(const void* data, int32_t length) { + void digestUpdate(const void* data, size_t length) { EVP_DigestUpdate(&ctx, data, length); } void digestFinal(unsigned char* md) { @@ -153,10 +153,10 @@ class MessageDigestContext { void digestFree() { EVP_MD_CTX_cleanup(&ctx); } - int32_t digestLength() const { + size_t digestLength() const { return digestLength(algo); } - static int32_t digestLength(DigestAlgo algo) { + static size_t digestLength(DigestAlgo algo) { return EVP_MD_size(algo); } @@ -167,7 +167,7 @@ class MessageDigestContext { void digestReset() { gcry_md_reset(ctx); } - void digestUpdate(const void* data, int32_t length) { + void digestUpdate(const void* data, size_t length) { gcry_md_write(ctx, data, length); } void digestFinal(unsigned char* md) { @@ -177,10 +177,10 @@ class MessageDigestContext { void digestFree() { gcry_md_close(ctx); } - int32_t digestLength() const { + size_t digestLength() const { return digestLength(algo); } - static int digestLength(DigestAlgo algo) { + static size_t digestLength(DigestAlgo algo) { return gcry_md_get_algo_dlen(algo); } #endif // HAVE_LIBGCRYPT diff --git a/test/AlphaNumberDecoratorTest.cc b/test/AlphaNumberDecoratorTest.cc index 5aa9cec6c9..913846804e 100644 --- a/test/AlphaNumberDecoratorTest.cc +++ b/test/AlphaNumberDecoratorTest.cc @@ -43,15 +43,7 @@ void AlphaNumberDecoratorTest::testDecorate_uppercase() void AlphaNumberDecoratorTest::testDecorate_minus() { - try { - AlphaNumberDecorator(1, true).decorate(-1); - CPPUNIT_FAIL("exception must be thrown."); - } catch(DlAbortEx* e) { - std::cerr << e->getMsg() << std::endl; - delete e; - } catch(...) { - CPPUNIT_FAIL("DlAbortEx must be thrown."); - } + CPPUNIT_ASSERT_EQUAL(std::string("NXMRLXV"), AlphaNumberDecorator(1, true).decorate(-1)); } } // namespace aria2 diff --git a/test/AnnounceListTest.cc b/test/AnnounceListTest.cc index dc3df779aa..4c9fec8165 100644 --- a/test/AnnounceListTest.cc +++ b/test/AnnounceListTest.cc @@ -206,22 +206,22 @@ void AnnounceListTest::testCountStoppedAllowedTier() { // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] AnnounceList announceList(announces); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::STARTED); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::HALTED); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::DOWNLOADING); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::STOPPED); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::COMPLETED); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countStoppedAllowedTier()); announceList.setEvent(AnnounceTier::SEEDING); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countStoppedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countStoppedAllowedTier()); } @@ -233,22 +233,22 @@ void AnnounceListTest::testCountCompletedAllowedTier() { // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ] AnnounceList announceList(announces); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::STARTED); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::STARTED_AFTER_COMPLETION); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::STOPPED); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::SEEDING); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::HALTED); - CPPUNIT_ASSERT_EQUAL((int32_t)0, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)0, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::DOWNLOADING); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countCompletedAllowedTier()); announceList.setEvent(AnnounceTier::COMPLETED); - CPPUNIT_ASSERT_EQUAL((int32_t)1, announceList.countCompletedAllowedTier()); + CPPUNIT_ASSERT_EQUAL((size_t)1, announceList.countCompletedAllowedTier()); } diff --git a/test/BtAllowedFastMessageTest.cc b/test/BtAllowedFastMessageTest.cc index 7c50060a07..57d573f264 100644 --- a/test/BtAllowedFastMessageTest.cc +++ b/test/BtAllowedFastMessageTest.cc @@ -37,8 +37,8 @@ void BtAllowedFastMessageTest::testCreate() { PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 17); PeerMessageUtil::setIntParam(&msg[5], 12345); SharedHandle pm = BtAllowedFastMessage::create(&msg[4], 5); - CPPUNIT_ASSERT_EQUAL((int8_t)17, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint8_t)17, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); // case: payload size is wrong try { diff --git a/test/BtBitfieldMessageTest.cc b/test/BtBitfieldMessageTest.cc index c50e09de4a..6f76567485 100644 --- a/test/BtBitfieldMessageTest.cc +++ b/test/BtBitfieldMessageTest.cc @@ -37,9 +37,9 @@ void BtBitfieldMessageTest::testCreate() { memset(bitfield, 0xff, sizeof(bitfield)); memcpy(&msg[5], bitfield, sizeof(bitfield)); SharedHandle pm = BtBitfieldMessage::create(&msg[4], 3); - CPPUNIT_ASSERT_EQUAL((int8_t)5, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)5, pm->getId()); CPPUNIT_ASSERT(memcmp(bitfield, pm->getBitfield(), sizeof(bitfield)) == 0); - CPPUNIT_ASSERT_EQUAL((int32_t)2, pm->getBitfieldLength()); + CPPUNIT_ASSERT_EQUAL((size_t)2, pm->getBitfieldLength()); // case: payload size is wrong try { unsigned char msg[5]; diff --git a/test/BtCancelMessageTest.cc b/test/BtCancelMessageTest.cc index 4af683cef3..4554d77560 100644 --- a/test/BtCancelMessageTest.cc +++ b/test/BtCancelMessageTest.cc @@ -48,15 +48,15 @@ class BtCancelMessageTest:public CppUnit::TestFixture { class MockBtMessageDispatcher2 : public MockBtMessageDispatcher { public: - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; public: MockBtMessageDispatcher2():index(0), begin(0), length(0) {} - virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) { + virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) { this->index = index; this->begin = begin; this->length = length; @@ -74,10 +74,10 @@ void BtCancelMessageTest::testCreate() { PeerMessageUtil::setIntParam(&msg[9], 256); PeerMessageUtil::setIntParam(&msg[13], 1024); SharedHandle pm = BtCancelMessage::create(&msg[4], 13); - CPPUNIT_ASSERT_EQUAL((int8_t)8, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((uint8_t)8, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength()); // case: payload size is wrong try { diff --git a/test/BtChokeMessageTest.cc b/test/BtChokeMessageTest.cc index f77327c497..cf56119dcb 100644 --- a/test/BtChokeMessageTest.cc +++ b/test/BtChokeMessageTest.cc @@ -85,7 +85,7 @@ void BtChokeMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 0); SharedHandle pm = BtChokeMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)0, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)0, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtExtendedMessageTest.cc b/test/BtExtendedMessageTest.cc index 7e5de256af..ba8d42a8a1 100644 --- a/test/BtExtendedMessageTest.cc +++ b/test/BtExtendedMessageTest.cc @@ -73,7 +73,7 @@ void BtExtendedMessageTest::testCreate() { SharedHandle pm = BtExtendedMessage::create(ctx, peer, &msg[4], 13); - CPPUNIT_ASSERT_EQUAL((int8_t)20, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)20, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtHandshakeMessageTest.cc b/test/BtHandshakeMessageTest.cc index 21da5f2a1e..d845f2bdda 100644 --- a/test/BtHandshakeMessageTest.cc +++ b/test/BtHandshakeMessageTest.cc @@ -56,8 +56,8 @@ void BtHandshakeMessageTest::testCreate() { unsigned char msg[68]; createHandshakeMessageData(msg); SharedHandle message = BtHandshakeMessage::create(&msg[0], sizeof(msg)); - CPPUNIT_ASSERT_EQUAL((int8_t)INT8_MAX, message->getId()); - CPPUNIT_ASSERT_EQUAL((int8_t)19, message->getPstrlen()); + CPPUNIT_ASSERT_EQUAL((uint8_t)INT8_MAX, message->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)19, message->getPstrlen()); CPPUNIT_ASSERT_EQUAL(Util::toHex((const unsigned char*)BTPSTR.c_str(), BTPSTR.size()), Util::toHex(message->getPstr(), BtHandshakeMessage::PSTR_LENGTH)); CPPUNIT_ASSERT_EQUAL(std::string("0000000000100004"), diff --git a/test/BtHaveAllMessageTest.cc b/test/BtHaveAllMessageTest.cc index b8d8945ff9..9351eefae2 100644 --- a/test/BtHaveAllMessageTest.cc +++ b/test/BtHaveAllMessageTest.cc @@ -31,7 +31,7 @@ void BtHaveAllMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 14); SharedHandle pm = BtHaveAllMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)14, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)14, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtHaveMessageTest.cc b/test/BtHaveMessageTest.cc index abf5928678..5081bfb3f2 100644 --- a/test/BtHaveMessageTest.cc +++ b/test/BtHaveMessageTest.cc @@ -34,8 +34,8 @@ void BtHaveMessageTest::testCreate() { PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 4); PeerMessageUtil::setIntParam(&msg[5], 12345); SharedHandle pm = BtHaveMessage::create(&msg[4], 5); - CPPUNIT_ASSERT_EQUAL((int8_t)4, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint8_t)4, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); // case: payload size is wrong try { diff --git a/test/BtHaveNoneMessageTest.cc b/test/BtHaveNoneMessageTest.cc index 6d9df0062d..8acaa10be1 100644 --- a/test/BtHaveNoneMessageTest.cc +++ b/test/BtHaveNoneMessageTest.cc @@ -33,7 +33,7 @@ void BtHaveNoneMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 15); SharedHandle pm = BtHaveNoneMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)15, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)15, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtInterestedMessageTest.cc b/test/BtInterestedMessageTest.cc index 77ba2ff63f..23f32349c3 100644 --- a/test/BtInterestedMessageTest.cc +++ b/test/BtInterestedMessageTest.cc @@ -35,7 +35,7 @@ void BtInterestedMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 2); BtInterestedMessageHandle pm = BtInterestedMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)2, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)2, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtKeepAliveMessageTest.cc b/test/BtKeepAliveMessageTest.cc index fc1a4e3711..b456216039 100644 --- a/test/BtKeepAliveMessageTest.cc +++ b/test/BtKeepAliveMessageTest.cc @@ -26,8 +26,8 @@ void BtKeepAliveMessageTest::testGetMessage() { char msg[4]; memset(msg, 0, sizeof(msg)); BtKeepAliveMessage message; - CPPUNIT_ASSERT_EQUAL((int8_t)99, message.getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)4, message.getMessageLength()); + CPPUNIT_ASSERT_EQUAL((uint8_t)99, message.getId()); + CPPUNIT_ASSERT_EQUAL((size_t)4, message.getMessageLength()); CPPUNIT_ASSERT(memcmp(msg, message.getMessage(), 4) == 0); } diff --git a/test/BtNotInterestedMessageTest.cc b/test/BtNotInterestedMessageTest.cc index 476a836a72..cca0fc9f4c 100644 --- a/test/BtNotInterestedMessageTest.cc +++ b/test/BtNotInterestedMessageTest.cc @@ -35,7 +35,7 @@ void BtNotInterestedMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 3); BtNotInterestedMessageHandle pm = BtNotInterestedMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)3, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)3, pm->getId()); // case: payload size is wrong try { diff --git a/test/BtPieceMessageTest.cc b/test/BtPieceMessageTest.cc index 19cc95f733..219cf67bdc 100644 --- a/test/BtPieceMessageTest.cc +++ b/test/BtPieceMessageTest.cc @@ -56,20 +56,20 @@ class BtPieceMessageTest:public CppUnit::TestFixture { class MockBtMessage2 : public MockBtMessage { public: - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; public: - MockBtMessage2(int32_t index, int32_t begin, int32_t length):index(index), begin(begin), length(length) {} + MockBtMessage2(size_t index, uint32_t begin, size_t length):index(index), begin(begin), length(length) {} }; class MockBtMessageFactory2 : public MockBtMessageFactory { public: virtual SharedHandle - createRejectMessage(int32_t index, - int32_t begin, - int32_t length) { + createRejectMessage(size_t index, + uint32_t begin, + size_t length) { SharedHandle msg = new MockBtMessage2(index, begin, length); return msg; } @@ -120,11 +120,11 @@ void BtPieceMessageTest::testCreate() { PeerMessageUtil::setIntParam(&msg[9], 256); memcpy(&msg[13], data, sizeof(data)); SharedHandle pm = BtPieceMessage::create(&msg[4], 11); - CPPUNIT_ASSERT_EQUAL((int8_t)7, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((uint8_t)7, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin()); CPPUNIT_ASSERT(memcmp(data, pm->getBlock(), sizeof(data)) == 0); - CPPUNIT_ASSERT_EQUAL((int32_t)2, pm->getBlockLength()); + CPPUNIT_ASSERT_EQUAL((size_t)2, pm->getBlockLength()); // case: payload size is wrong try { @@ -181,9 +181,9 @@ void BtPieceMessageTest::testChokingEvent_allowedFastEnabled() { CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->messageQueue.size()); MockBtMessage2* rej = (MockBtMessage2*)btMessageDispatcher->messageQueue.front().get(); - CPPUNIT_ASSERT_EQUAL((int32_t)1, rej->index); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->begin); - CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->length); + CPPUNIT_ASSERT_EQUAL((size_t)1, rej->index); + CPPUNIT_ASSERT_EQUAL((uint32_t)1024, rej->begin); + CPPUNIT_ASSERT_EQUAL((size_t)16*1024, rej->length); } void BtPieceMessageTest::testChokingEvent_inAmAllowedIndexSet() { @@ -266,9 +266,9 @@ void BtPieceMessageTest::testCancelSendingPieceEvent_allowedFastEnabled() { CPPUNIT_ASSERT(msg->isInvalidate()); CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->messageQueue.size()); MockBtMessage2* rej = (MockBtMessage2*)btMessageDispatcher->messageQueue.front().get(); - CPPUNIT_ASSERT_EQUAL((int32_t)1, rej->index); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, rej->begin); - CPPUNIT_ASSERT_EQUAL((int32_t)16*1024, rej->length); + CPPUNIT_ASSERT_EQUAL((size_t)1, rej->index); + CPPUNIT_ASSERT_EQUAL((uint32_t)1024, rej->begin); + CPPUNIT_ASSERT_EQUAL((size_t)16*1024, rej->length); } void BtPieceMessageTest::testCancelSendingPieceEvent_invalidate() { diff --git a/test/BtPortMessageTest.cc b/test/BtPortMessageTest.cc index 6585151c36..26dda68734 100644 --- a/test/BtPortMessageTest.cc +++ b/test/BtPortMessageTest.cc @@ -60,7 +60,7 @@ void BtPortMessageTest::testCreate() { PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 3, 9); PeerMessageUtil::setShortIntParam(&msg[5], 12345); SharedHandle pm = BtPortMessage::create(&msg[4], 3); - CPPUNIT_ASSERT_EQUAL((int8_t)9, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)9, pm->getId()); CPPUNIT_ASSERT_EQUAL((uint16_t)12345, pm->getPort()); // case: payload size is wrong diff --git a/test/BtRejectMessageTest.cc b/test/BtRejectMessageTest.cc index 3242da2d40..e92b5875fd 100644 --- a/test/BtRejectMessageTest.cc +++ b/test/BtRejectMessageTest.cc @@ -46,8 +46,8 @@ class BtRejectMessageTest:public CppUnit::TestFixture { this->slot = slot; } - virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, - int32_t length) { + virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, + size_t length) { if(slot.getIndex() == index && slot.getBegin() == begin && slot.getLength() == length) { return slot; @@ -107,10 +107,10 @@ void BtRejectMessageTest::testCreate() { PeerMessageUtil::setIntParam(&msg[9], 256); PeerMessageUtil::setIntParam(&msg[13], 1024); SharedHandle pm = BtRejectMessage::create(&msg[4], 13); - CPPUNIT_ASSERT_EQUAL((int8_t)16, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((uint8_t)16, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength()); // case: payload size is wrong try { diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index 9b1cc8be42..1d653e93d6 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -62,11 +62,11 @@ class BtRequestMessageTest:public CppUnit::TestFixture { class MockBtMessage2 : public MockBtMessage { public: std::string type; - int32_t index; - int32_t begin; - int32_t length; + size_t index; + uint32_t begin; + size_t length; public: - MockBtMessage2(std::string type, int32_t index, int32_t begin, int32_t length):type(type), index(index), begin(begin), length(length) {} + MockBtMessage2(std::string type, size_t index, uint32_t begin, size_t length):type(type), index(index), begin(begin), length(length) {} }; typedef SharedHandle MockBtMessage2Handle; @@ -74,13 +74,13 @@ class BtRequestMessageTest:public CppUnit::TestFixture { class MockBtMessageFactory2 : public MockBtMessageFactory { public: virtual SharedHandle - createPieceMessage(int32_t index, int32_t begin, int32_t length) { + createPieceMessage(size_t index, uint32_t begin, size_t length) { SharedHandle btMsg = new MockBtMessage2("piece", index, begin, length); return btMsg; } virtual SharedHandle - createRejectMessage(int32_t index, int32_t begin, int32_t length) { + createRejectMessage(size_t index, uint32_t begin, size_t length) { SharedHandle btMsg = new MockBtMessage2("reject", index, begin, length); return btMsg; } @@ -141,10 +141,10 @@ void BtRequestMessageTest::testCreate() { PeerMessageUtil::setIntParam(&msg[9], 256); PeerMessageUtil::setIntParam(&msg[13], 1024); SharedHandle pm = BtRequestMessage::create(&msg[4], 13); - CPPUNIT_ASSERT_EQUAL((int8_t)6, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); - CPPUNIT_ASSERT_EQUAL((int32_t)256, pm->getBegin()); - CPPUNIT_ASSERT_EQUAL((int32_t)1024, pm->getLength()); + CPPUNIT_ASSERT_EQUAL((uint8_t)6, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength()); // case: payload size is wrong try { @@ -184,9 +184,9 @@ void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmNotChoking() { CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(std::string("piece"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL((int32_t)1, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((size_t)1, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((uint32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((size_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionEnabled() { @@ -197,9 +197,9 @@ void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExten CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(std::string("reject"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL((int32_t)1, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((size_t)1, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((uint32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((size_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmChokingAndFastExtensionDisabled() { @@ -218,9 +218,9 @@ void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionE CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher->messageQueue.size()); MockBtMessage2* pieceMsg = (MockBtMessage2*)dispatcher->messageQueue.front().get(); CPPUNIT_ASSERT_EQUAL(std::string("reject"), pieceMsg->type); - CPPUNIT_ASSERT_EQUAL((int32_t)2, pieceMsg->index); - CPPUNIT_ASSERT_EQUAL((int32_t)16, pieceMsg->begin); - CPPUNIT_ASSERT_EQUAL((int32_t)32, pieceMsg->length); + CPPUNIT_ASSERT_EQUAL((size_t)2, pieceMsg->index); + CPPUNIT_ASSERT_EQUAL((uint32_t)16, pieceMsg->begin); + CPPUNIT_ASSERT_EQUAL((size_t)32, pieceMsg->length); } void BtRequestMessageTest::testDoReceivedAction_doesntHavePieceAndFastExtensionDisabled() { diff --git a/test/BtSuggestPieceMessageTest.cc b/test/BtSuggestPieceMessageTest.cc index b40c576f76..744ec11da9 100644 --- a/test/BtSuggestPieceMessageTest.cc +++ b/test/BtSuggestPieceMessageTest.cc @@ -31,8 +31,8 @@ void BtSuggestPieceMessageTest::testCreate() { PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 13); PeerMessageUtil::setIntParam(&msg[5], 12345); SharedHandle pm = BtSuggestPieceMessage::create(&msg[4], 5); - CPPUNIT_ASSERT_EQUAL((int8_t)13, pm->getId()); - CPPUNIT_ASSERT_EQUAL((int32_t)12345, pm->getIndex()); + CPPUNIT_ASSERT_EQUAL((uint8_t)13, pm->getId()); + CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex()); // case: payload size is wrong try { diff --git a/test/BtUnchokeMessageTest.cc b/test/BtUnchokeMessageTest.cc index 9931909c2b..9ab7ce6cab 100644 --- a/test/BtUnchokeMessageTest.cc +++ b/test/BtUnchokeMessageTest.cc @@ -34,7 +34,7 @@ void BtUnchokeMessageTest::testCreate() { unsigned char msg[5]; PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 1); SharedHandle pm = BtUnchokeMessage::create(&msg[4], 1); - CPPUNIT_ASSERT_EQUAL((int8_t)1, pm->getId()); + CPPUNIT_ASSERT_EQUAL((uint8_t)1, pm->getId()); // case: payload size is wrong try { diff --git a/test/ChunkedEncodingTest.cc b/test/ChunkedEncodingTest.cc index a0afae5a27..f55f38f63f 100644 --- a/test/ChunkedEncodingTest.cc +++ b/test/ChunkedEncodingTest.cc @@ -31,7 +31,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( ChunkedEncodingTest ); void ChunkedEncodingTest::testInflate1() { std::string msg = "a\r\n1234567890\r\n"; unsigned char buf[100]; - int32_t len = sizeof(buf); + size_t len = sizeof(buf); enc->inflate(buf, len, reinterpret_cast(msg.c_str()), msg.size()); CPPUNIT_ASSERT_EQUAL(std::string("1234567890"), std::string(&buf[0], &buf[len])); @@ -54,7 +54,7 @@ void ChunkedEncodingTest::testInflateLargeChunk() { std::string body; is >> body; unsigned char buf[4097]; - int32_t len = sizeof(buf); + size_t len = sizeof(buf); for(int i = 0; i < 2; i++) { std::string msg = "1000\r\n"+body+"\r\n"; len = sizeof(buf); @@ -63,7 +63,7 @@ void ChunkedEncodingTest::testInflateLargeChunk() { CPPUNIT_ASSERT_EQUAL(body, std::string(&buf[0], &buf[len])); } enc->inflate(buf, len, reinterpret_cast("0\r\n"), 3); - CPPUNIT_ASSERT_EQUAL((int32_t)0, len); + CPPUNIT_ASSERT_EQUAL((size_t)0, len); CPPUNIT_ASSERT(enc->finished()); } diff --git a/test/DataTest.cc b/test/DataTest.cc index e2ef376242..c6d8644c4b 100644 --- a/test/DataTest.cc +++ b/test/DataTest.cc @@ -38,11 +38,11 @@ void DataTest::testToString() { void DataTest::testGetData() { Data data("aria2", 5); CPPUNIT_ASSERT_EQUAL(0, memcmp("aria2", data.getData(), 5)); - CPPUNIT_ASSERT_EQUAL((int32_t)5, data.getLen()); + CPPUNIT_ASSERT_EQUAL((size_t)5, data.getLen()); Data null(reinterpret_cast(0), 0); CPPUNIT_ASSERT(null.getData() == 0); - CPPUNIT_ASSERT_EQUAL((int32_t)0, null.getLen()); + CPPUNIT_ASSERT_EQUAL((size_t)0, null.getLen()); } diff --git a/test/DefaultBtAnnounceTest.cc b/test/DefaultBtAnnounceTest.cc index e16053380e..7e6e67ff2e 100644 --- a/test/DefaultBtAnnounceTest.cc +++ b/test/DefaultBtAnnounceTest.cc @@ -322,10 +322,10 @@ void DefaultBtAnnounceTest::testProcessAnnounceResponse() DefaultBtAnnounce an(new MockBtContext(), _option); an.processAnnounceResponse(reinterpret_cast(res.c_str()), res.size()); CPPUNIT_ASSERT_EQUAL(std::string("foo"), an.getTrackerID()); - CPPUNIT_ASSERT_EQUAL(3000, an.getInterval()); - CPPUNIT_ASSERT_EQUAL(1800, an.getMinInterval()); - CPPUNIT_ASSERT_EQUAL(100, an.getComplete()); - CPPUNIT_ASSERT_EQUAL(200, an.getIncomplete()); + CPPUNIT_ASSERT_EQUAL((time_t)3000, an.getInterval()); + CPPUNIT_ASSERT_EQUAL((time_t)1800, an.getMinInterval()); + CPPUNIT_ASSERT_EQUAL((unsigned int)100, an.getComplete()); + CPPUNIT_ASSERT_EQUAL((unsigned int)200, an.getIncomplete()); } } // namespace aria2 diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc index 97504f571f..5b3ae2d165 100644 --- a/test/DefaultBtMessageDispatcherTest.cc +++ b/test/DefaultBtMessageDispatcherTest.cc @@ -123,7 +123,7 @@ class DefaultBtMessageDispatcherTest:public CppUnit::TestFixture { class MockBtMessageFactory2 : public MockBtMessageFactory { public: virtual SharedHandle - createCancelMessage(int32_t index, int32_t begin, int32_t length) { + createCancelMessage(size_t index, uint32_t begin, size_t length) { SharedHandle btMsg = new MockBtMessage2(); btMsg->type = "cancel"; return btMsg; @@ -378,7 +378,7 @@ void DefaultBtMessageDispatcherTest::testIsSendingInProgress() { void DefaultBtMessageDispatcherTest::testCountOutstandingRequest() { RequestSlot slot(0, 0, MY_PIECE_LENGTH, 0); btMessageDispatcher->addOutstandingRequest(slot); - CPPUNIT_ASSERT_EQUAL((int32_t)1, btMessageDispatcher->countOutstandingRequest()); + CPPUNIT_ASSERT_EQUAL((size_t)1, btMessageDispatcher->countOutstandingRequest()); } void DefaultBtMessageDispatcherTest::testIsOutstandingRequest() { diff --git a/test/DefaultBtProgressInfoFileTest.cc b/test/DefaultBtProgressInfoFileTest.cc index 6f8458d05c..b6f3564daa 100644 --- a/test/DefaultBtProgressInfoFileTest.cc +++ b/test/DefaultBtProgressInfoFileTest.cc @@ -103,7 +103,7 @@ void DefaultBtProgressInfoFileTest::testLoad() // check the contents of objects // upload length - CPPUNIT_ASSERT_EQUAL((int64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup()); + CPPUNIT_ASSERT_EQUAL((uint64_t)1024, BT_RUNTIME(_btContext)->getUploadLengthAtStartup()); // bitfield CPPUNIT_ASSERT_EQUAL(std::string("fffffffffffffffffffe"), diff --git a/test/DefaultBtRequestFactoryTest.cc b/test/DefaultBtRequestFactoryTest.cc index 905e4bbaab..d4b956c9f9 100644 --- a/test/DefaultBtRequestFactoryTest.cc +++ b/test/DefaultBtRequestFactoryTest.cc @@ -50,14 +50,14 @@ class DefaultBtRequestFactoryTest:public CppUnit::TestFixture { class MockBtMessageFactory2 : public MockBtMessageFactory { public: virtual SharedHandle - createRequestMessage(const SharedHandle& piece, int32_t blockIndex) { + createRequestMessage(const SharedHandle& piece, size_t blockIndex) { return new MockBtRequestMessage(piece->getIndex(), blockIndex); } }; class MockBtMessageDispatcher2 : public MockBtMessageDispatcher { public: - virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex) { + virtual bool isOutstandingRequest(size_t index, size_t blockIndex) { return index == 0 && blockIndex == 0; } }; @@ -114,7 +114,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest); void DefaultBtRequestFactoryTest::testAddTargetPiece() { SharedHandle piece = new Piece(0, 16*1024); btRequestFactory->addTargetPiece(piece); - CPPUNIT_ASSERT_EQUAL((int32_t)1, btRequestFactory->countTargetPiece()); + CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece()); } void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() { @@ -123,9 +123,9 @@ void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() { piece2->setAllBlock(); btRequestFactory->addTargetPiece(piece1); btRequestFactory->addTargetPiece(piece2); - CPPUNIT_ASSERT_EQUAL((int32_t)2, btRequestFactory->countTargetPiece()); + CPPUNIT_ASSERT_EQUAL((size_t)2, btRequestFactory->countTargetPiece()); btRequestFactory->removeCompletedPiece(); - CPPUNIT_ASSERT_EQUAL((int32_t)1, btRequestFactory->countTargetPiece()); + CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece()); CPPUNIT_ASSERT_EQUAL((size_t)0, btRequestFactory->getTargetPieces().front()->getIndex()); } diff --git a/test/DefaultDiskWriterTest.cc b/test/DefaultDiskWriterTest.cc index d9a93ab8da..cded6964cb 100644 --- a/test/DefaultDiskWriterTest.cc +++ b/test/DefaultDiskWriterTest.cc @@ -24,7 +24,7 @@ void DefaultDiskWriterTest::testSize() { DefaultDiskWriter dw; dw.openExistingFile("4096chunk.txt"); - CPPUNIT_ASSERT_EQUAL((int64_t)4096, dw.size()); + CPPUNIT_ASSERT_EQUAL(4096ULL, dw.size()); } } // namespace aria2 diff --git a/test/DefaultPeerListProcessorTest.cc b/test/DefaultPeerListProcessorTest.cc index f7a1b15854..46200920d1 100644 --- a/test/DefaultPeerListProcessorTest.cc +++ b/test/DefaultPeerListProcessorTest.cc @@ -27,7 +27,7 @@ class DefaultPeerListProcessorTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_REGISTRATION( DefaultPeerListProcessorTest ); void DefaultPeerListProcessorTest::testExtractPeer() { - DefaultPeerListProcessor proc(1024*1024, 10*1024*1024); + DefaultPeerListProcessor proc; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee"; Dictionary* dic = (Dictionary*)MetaFileUtil::bdecoding(peersString); @@ -42,7 +42,7 @@ void DefaultPeerListProcessorTest::testExtractPeer() { } void DefaultPeerListProcessorTest::testExtract2Peers() { - DefaultPeerListProcessor proc(1024*1024, 10*1024*1024); + DefaultPeerListProcessor proc; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee"; Dictionary* dic = (Dictionary*)MetaFileUtil::bdecoding(peersString); diff --git a/test/FeatureConfigTest.cc b/test/FeatureConfigTest.cc index 8055686221..e744784d92 100644 --- a/test/FeatureConfigTest.cc +++ b/test/FeatureConfigTest.cc @@ -21,11 +21,11 @@ class FeatureConfigTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE_REGISTRATION(FeatureConfigTest); void FeatureConfigTest::testGetDefaultPort() { - CPPUNIT_ASSERT_EQUAL((int32_t)80, + CPPUNIT_ASSERT_EQUAL((uint16_t)80, FeatureConfig::getInstance()->getDefaultPort("http")); - CPPUNIT_ASSERT_EQUAL((int32_t)443, + CPPUNIT_ASSERT_EQUAL((uint16_t)443, FeatureConfig::getInstance()->getDefaultPort("https")); - CPPUNIT_ASSERT_EQUAL((int32_t)21, + CPPUNIT_ASSERT_EQUAL((uint16_t)21, FeatureConfig::getInstance()->getDefaultPort("ftp")); } diff --git a/test/HttpHeaderProcessorTest.cc b/test/HttpHeaderProcessorTest.cc index f3e1b2026d..5b85570c16 100644 --- a/test/HttpHeaderProcessorTest.cc +++ b/test/HttpHeaderProcessorTest.cc @@ -64,7 +64,7 @@ void HttpHeaderProcessorTest::testGetPutBackDataLength() "\r\nputbackme"; proc.update(hd1); CPPUNIT_ASSERT(proc.eoh()); - CPPUNIT_ASSERT_EQUAL((int32_t)9, proc.getPutBackDataLength()); + CPPUNIT_ASSERT_EQUAL((size_t)9, proc.getPutBackDataLength()); proc.clear(); @@ -72,7 +72,7 @@ void HttpHeaderProcessorTest::testGetPutBackDataLength() "\nputbackme"; proc.update(hd2); CPPUNIT_ASSERT(proc.eoh()); - CPPUNIT_ASSERT_EQUAL((int32_t)9, proc.getPutBackDataLength()); + CPPUNIT_ASSERT_EQUAL((size_t)9, proc.getPutBackDataLength()); } void HttpHeaderProcessorTest::testGetPutBackDataLength_nullChar() @@ -84,7 +84,7 @@ void HttpHeaderProcessorTest::testGetPutBackDataLength_nullChar() std::string hd1(&x[0], &x[42]); proc.update(hd1); CPPUNIT_ASSERT(proc.eoh()); - CPPUNIT_ASSERT_EQUAL((int32_t)9, proc.getPutBackDataLength()); + CPPUNIT_ASSERT_EQUAL((size_t)9, proc.getPutBackDataLength()); } void HttpHeaderProcessorTest::testGetHttpStatusHeader() @@ -109,7 +109,7 @@ void HttpHeaderProcessorTest::testGetHttpStatusHeader() CPPUNIT_ASSERT_EQUAL(std::string("200"), status); CPPUNIT_ASSERT_EQUAL(std::string("Mon, 25 Jun 2007 16:04:59 GMT"), header->getFirst("Date")); CPPUNIT_ASSERT_EQUAL(std::string("Apache/2.2.3 (Debian)"), header->getFirst("Server")); - CPPUNIT_ASSERT_EQUAL((int64_t)9187LL, header->getFirstAsLLInt("Content-Length")); + CPPUNIT_ASSERT_EQUAL(9187ULL, header->getFirstAsULLInt("Content-Length")); CPPUNIT_ASSERT_EQUAL(std::string("text/html; charset=UTF-8"), header->getFirst("Content-Type")); } diff --git a/test/HttpHeaderTest.cc b/test/HttpHeaderTest.cc index 8e6ab94557..389aaf8349 100644 --- a/test/HttpHeaderTest.cc +++ b/test/HttpHeaderTest.cc @@ -25,9 +25,9 @@ void HttpHeaderTest::testGetRange() SharedHandle range = httpHeader.getRange(); - CPPUNIT_ASSERT_EQUAL((int64_t)1, range->getStartByte()); - CPPUNIT_ASSERT_EQUAL((int64_t)499, range->getEndByte()); - CPPUNIT_ASSERT_EQUAL((int64_t)1234, range->getEntityLength()); + CPPUNIT_ASSERT_EQUAL(1LL, range->getStartByte()); + CPPUNIT_ASSERT_EQUAL(499LL, range->getEndByte()); + CPPUNIT_ASSERT_EQUAL(1234ULL, range->getEntityLength()); } } // namespace aria2 diff --git a/test/HttpResponseTest.cc b/test/HttpResponseTest.cc index 8d4a72e486..e995749a93 100644 --- a/test/HttpResponseTest.cc +++ b/test/HttpResponseTest.cc @@ -66,7 +66,7 @@ void HttpResponseTest::testGetContentLength_null() { HttpResponse httpResponse; - CPPUNIT_ASSERT_EQUAL((int64_t)0, httpResponse.getContentLength()); + CPPUNIT_ASSERT_EQUAL(0ULL, httpResponse.getContentLength()); } void HttpResponseTest::testGetContentLength_contentLength() @@ -78,7 +78,7 @@ void HttpResponseTest::testGetContentLength_contentLength() httpResponse.setHttpHeader(httpHeader); - CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getContentLength()); + CPPUNIT_ASSERT_EQUAL(4294967296ULL, httpResponse.getContentLength()); } void HttpResponseTest::testGetEntityLength() @@ -90,11 +90,11 @@ void HttpResponseTest::testGetEntityLength() httpResponse.setHttpHeader(httpHeader); - CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getEntityLength()); + CPPUNIT_ASSERT_EQUAL(4294967296ULL, httpResponse.getEntityLength()); httpHeader->put("Content-Range", "bytes 1-4294967296/4294967297"); - CPPUNIT_ASSERT_EQUAL((int64_t)4294967297LL, httpResponse.getEntityLength()); + CPPUNIT_ASSERT_EQUAL(4294967297ULL, httpResponse.getEntityLength()); } diff --git a/test/MSEHandshakeTest.cc b/test/MSEHandshakeTest.cc index f90de035df..4986d76a01 100644 --- a/test/MSEHandshakeTest.cc +++ b/test/MSEHandshakeTest.cc @@ -53,7 +53,7 @@ static std::pair createSocketPair() receiverServerSock.bind(0); receiverServerSock.beginListen(); - std::pair receiverAddrInfo; + std::pair receiverAddrInfo; receiverServerSock.getAddrInfo(receiverAddrInfo); initiatorSock->establishConnection("127.0.0.1", receiverAddrInfo.second); initiatorSock->setBlockingMode(); diff --git a/test/MetalinkParserControllerTest.cc b/test/MetalinkParserControllerTest.cc index 64b040388d..b7feb9d14a 100644 --- a/test/MetalinkParserControllerTest.cc +++ b/test/MetalinkParserControllerTest.cc @@ -56,8 +56,8 @@ void MetalinkParserControllerTest::testEntryTransaction() CPPUNIT_ASSERT_EQUAL((size_t)1, m->entries.size()); SharedHandle e = m->entries.front(); CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), e->file->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)1024*1024, e->file->getLength()); - CPPUNIT_ASSERT_EQUAL((int64_t)0, e->file->getOffset()); + CPPUNIT_ASSERT_EQUAL(1024*1024ULL, e->file->getLength()); + CPPUNIT_ASSERT_EQUAL((off_t)0, e->file->getOffset()); CPPUNIT_ASSERT_EQUAL(std::string("1.0"), e->version); CPPUNIT_ASSERT_EQUAL(std::string("ja_JP"), e->language); CPPUNIT_ASSERT_EQUAL(std::string("Linux"), e->os); @@ -134,8 +134,8 @@ void MetalinkParserControllerTest::testChunkChecksumTransaction() SharedHandle m = ctrl.getResult(); SharedHandle md = m->entries.front()->chunkChecksum; CPPUNIT_ASSERT_EQUAL(std::string("md5"), md->getAlgo()); - CPPUNIT_ASSERT_EQUAL(256*1024, md->getChecksumLength()); - CPPUNIT_ASSERT_EQUAL(5, md->countChecksum()); + CPPUNIT_ASSERT_EQUAL((size_t)256*1024, md->getChecksumLength()); + CPPUNIT_ASSERT_EQUAL((size_t)5, md->countChecksum()); CPPUNIT_ASSERT_EQUAL(std::string("hash1"), md->getChecksums()[0]); CPPUNIT_ASSERT_EQUAL(std::string("hash2"), md->getChecksums()[1]); CPPUNIT_ASSERT_EQUAL(std::string("hash3"), md->getChecksums()[2]); diff --git a/test/MetalinkProcessorTest.cc b/test/MetalinkProcessorTest.cc index 8b7ab45e5d..fe67da75b6 100644 --- a/test/MetalinkProcessorTest.cc +++ b/test/MetalinkProcessorTest.cc @@ -72,11 +72,11 @@ void MetalinkProcessorTest::testParseFile() SharedHandle entry1 = *entryItr; CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), entry1->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)0, entry1->getLength()); + CPPUNIT_ASSERT_EQUAL(0ULL, entry1->getLength()); CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), entry1->version); CPPUNIT_ASSERT_EQUAL(std::string("en-US"), entry1->language); CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), entry1->os); - CPPUNIT_ASSERT_EQUAL((int32_t)1, entry1->maxConnections); + CPPUNIT_ASSERT_EQUAL(1, entry1->maxConnections); #ifdef ENABLE_MESSAGE_DIGEST CPPUNIT_ASSERT_EQUAL(std::string("a96cf3f0266b91d87d5124cf94326422800b627d"), entry1->checksum->getMessageDigest()); @@ -86,10 +86,10 @@ void MetalinkProcessorTest::testParseFile() SharedHandle resource1 = *resourceItr1; CPPUNIT_ASSERT_EQUAL(MetalinkResource::TYPE_FTP, resource1->type); CPPUNIT_ASSERT_EQUAL(std::string("JP"), resource1->location); - CPPUNIT_ASSERT_EQUAL((int32_t)100, resource1->preference); + CPPUNIT_ASSERT_EQUAL(100, resource1->preference); CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"), resource1->url); - CPPUNIT_ASSERT_EQUAL((int32_t)1, resource1->maxConnections); + CPPUNIT_ASSERT_EQUAL(1, resource1->maxConnections); resourceItr1++; SharedHandle resource2 = *resourceItr1; @@ -98,22 +98,22 @@ void MetalinkProcessorTest::testParseFile() CPPUNIT_ASSERT_EQUAL((int32_t)100, resource2->preference); CPPUNIT_ASSERT_EQUAL(std::string("http://httphost/aria2-0.5.2.tar.bz2"), resource2->url); - CPPUNIT_ASSERT_EQUAL((int32_t)-1, resource2->maxConnections); + CPPUNIT_ASSERT_EQUAL(-1, resource2->maxConnections); entryItr++; SharedHandle entry2 = *entryItr; CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.1.tar.bz2"), entry2->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)345689, entry2->getLength()); + CPPUNIT_ASSERT_EQUAL(345689ULL, entry2->getLength()); CPPUNIT_ASSERT_EQUAL(std::string("0.5.1"), entry2->version); CPPUNIT_ASSERT_EQUAL(std::string("ja-JP"), entry2->language); CPPUNIT_ASSERT_EQUAL(std::string("Linux-m68k"), entry2->os); - CPPUNIT_ASSERT_EQUAL((int32_t)-1, entry2->maxConnections); + CPPUNIT_ASSERT_EQUAL(-1, entry2->maxConnections); #ifdef ENABLE_MESSAGE_DIGEST CPPUNIT_ASSERT_EQUAL(std::string("4c255b0ed130f5ea880f0aa061c3da0487e251cc"), entry2->checksum->getMessageDigest()); - CPPUNIT_ASSERT_EQUAL((int32_t)2, entry2->chunkChecksum->countChecksum()); - CPPUNIT_ASSERT_EQUAL((int32_t)262144, entry2->chunkChecksum->getChecksumLength()); + CPPUNIT_ASSERT_EQUAL((size_t)2, entry2->chunkChecksum->countChecksum()); + CPPUNIT_ASSERT_EQUAL((size_t)262144, entry2->chunkChecksum->getChecksumLength()); CPPUNIT_ASSERT_EQUAL(std::string("179463a88d79cbf0b1923991708aead914f26142"), entry2->chunkChecksum->getChecksum(0)); CPPUNIT_ASSERT_EQUAL(std::string("fecf8bc9a1647505fe16746f94e97a477597dbf3"), @@ -221,7 +221,7 @@ void MetalinkProcessorTest::testBadSize() std::deque >::iterator entryItr = m->entries.begin(); SharedHandle e = *entryItr; CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.5.2.tar.bz2"), e->getPath()); - CPPUNIT_ASSERT_EQUAL((int64_t)0, e->getLength()); + CPPUNIT_ASSERT_EQUAL(0ULL, e->getLength()); CPPUNIT_ASSERT_EQUAL(std::string("0.5.2"), e->version); CPPUNIT_ASSERT_EQUAL(std::string("en-US"), e->language); CPPUNIT_ASSERT_EQUAL(std::string("Linux-x86"), e->os); @@ -253,7 +253,7 @@ void MetalinkProcessorTest::testBadMaxConn() std::deque >::iterator entryItr = m->entries.begin(); SharedHandle e = *entryItr; - CPPUNIT_ASSERT_EQUAL((int64_t)43743838, e->getLength()); + CPPUNIT_ASSERT_EQUAL(43743838ULL, e->getLength()); } catch(Exception* e) { CPPUNIT_FAIL(e->getMsg()); delete e; @@ -420,7 +420,7 @@ void MetalinkProcessorTest::testMultiplePieces() SharedHandle c = e->chunkChecksum; CPPUNIT_ASSERT_EQUAL(std::string("sha1"), c->getAlgo()); - CPPUNIT_ASSERT_EQUAL(1024, c->getChecksumLength()); + CPPUNIT_ASSERT_EQUAL((size_t)1024, c->getChecksumLength()); } catch(Exception* e) { CPPUNIT_FAIL(e->getMsg()); delete e; @@ -540,7 +540,7 @@ void MetalinkProcessorTest::testLargeFileSize() try { SharedHandle m = proc->parseFromBinaryStream(dw); SharedHandle e = m->entries[0]; - CPPUNIT_ASSERT_EQUAL(9223372036854775807LL, e->getLength()); + CPPUNIT_ASSERT_EQUAL(9223372036854775807ULL, e->getLength()); } catch(Exception* e) { std::cerr << *e << std::endl; std::string m = e->getMsg(); diff --git a/test/MockBtMessage.h b/test/MockBtMessage.h index 18277733d3..1afb905328 100644 --- a/test/MockBtMessage.h +++ b/test/MockBtMessage.h @@ -44,7 +44,7 @@ class MockBtMessage : public BtMessage { bool sendingInProgress; bool invalidate; bool uploading; - int8_t id; + uint8_t id; public: MockBtMessage() {} @@ -74,11 +74,11 @@ class MockBtMessage : public BtMessage { this->uploading = flag; } - virtual int8_t getId() { + virtual uint8_t getId() { return id; } - void setId(int8_t id) { + void setId(uint8_t id) { this->id = id; } diff --git a/test/MockBtMessageDispatcher.h b/test/MockBtMessageDispatcher.h index 4b88e48b38..5cd846895c 100644 --- a/test/MockBtMessageDispatcher.h +++ b/test/MockBtMessageDispatcher.h @@ -22,7 +22,7 @@ class MockBtMessageDispatcher : public BtMessageDispatcher { virtual void sendMessages() {} - virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) {} + virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) {} virtual void doCancelSendingPieceAction(const SharedHandle& piece) {} @@ -38,19 +38,19 @@ class MockBtMessageDispatcher : public BtMessageDispatcher { return false; } - virtual int32_t countMessageInQueue() { + virtual size_t countMessageInQueue() { return messageQueue.size(); } - virtual int32_t countOutstandingRequest() { + virtual size_t countOutstandingRequest() { return 0; } - virtual bool isOutstandingRequest(int32_t index, int32_t blockIndex) { + virtual bool isOutstandingRequest(size_t index, size_t blockIndex) { return false; } - virtual RequestSlot getOutstandingRequest(int32_t index, int32_t begin, int32_t length) { + virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length) { return RequestSlot::nullSlot; } diff --git a/test/MockBtMessageFactory.h b/test/MockBtMessageFactory.h index 8141fb6fc1..6fa5233f9a 100644 --- a/test/MockBtMessageFactory.h +++ b/test/MockBtMessageFactory.h @@ -14,12 +14,12 @@ class MockBtMessageFactory : public BtMessageFactory { virtual ~MockBtMessageFactory() {} virtual SharedHandle - createBtMessage(const unsigned char* msg, int32_t msgLength) { + createBtMessage(const unsigned char* msg, size_t msgLength) { return SharedHandle(0); }; virtual SharedHandle - createHandshakeMessage(const unsigned char* msg, int32_t msgLength) { + createHandshakeMessage(const unsigned char* msg, size_t msgLength) { return SharedHandle(0); } @@ -30,21 +30,21 @@ class MockBtMessageFactory : public BtMessageFactory { } virtual SharedHandle - createRequestMessage(const SharedHandle& piece, int32_t blockIndex) { + createRequestMessage(const SharedHandle& piece, size_t blockIndex) { return SharedHandle(0); } virtual SharedHandle - createCancelMessage(int32_t index, int32_t begin, int32_t length) { + createCancelMessage(size_t index, uint32_t begin, size_t length) { return SharedHandle(0); } virtual SharedHandle - createPieceMessage(int32_t index, int32_t begin, int32_t length) { + createPieceMessage(size_t index, uint32_t begin, size_t length) { return SharedHandle(0); } - virtual SharedHandle createHaveMessage(int32_t index) { + virtual SharedHandle createHaveMessage(size_t index) { return SharedHandle(0); } @@ -81,11 +81,11 @@ class MockBtMessageFactory : public BtMessageFactory { } virtual SharedHandle - createRejectMessage(int32_t index, int32_t begin, int32_t length) { + createRejectMessage(size_t index, uint32_t begin, size_t length) { return SharedHandle(0); } - virtual SharedHandle createAllowedFastMessage(int32_t index) { + virtual SharedHandle createAllowedFastMessage(size_t index) { return SharedHandle(0); } diff --git a/test/MockBtRequestFactory.h b/test/MockBtRequestFactory.h index 9307675ba6..3a31a77f90 100644 --- a/test/MockBtRequestFactory.h +++ b/test/MockBtRequestFactory.h @@ -15,7 +15,7 @@ class MockBtRequestFactory : public BtRequestFactory { virtual void removeAllTargetPiece() {} - virtual int32_t countTargetPiece() { return 0; } + virtual size_t countTargetPiece() { return 0; } virtual void removeCompletedPiece() {} diff --git a/test/MultiFileAllocationIteratorTest.cc b/test/MultiFileAllocationIteratorTest.cc index e4cadeb953..3e2b110657 100644 --- a/test/MultiFileAllocationIteratorTest.cc +++ b/test/MultiFileAllocationIteratorTest.cc @@ -140,12 +140,12 @@ void MultiFileAllocationIteratorTest::testAllocate() while(!itr->finished()) { itr->allocateChunk(); } - CPPUNIT_ASSERT_EQUAL((int64_t)length1, File(dir+"/"+topDir+"/"+fname1).size()); - CPPUNIT_ASSERT_EQUAL((int64_t)length2, File(dir+"/"+topDir+"/"+fname2).size()); - CPPUNIT_ASSERT_EQUAL((int64_t)length3, File(dir+"/"+topDir+"/"+fname3).size()); - CPPUNIT_ASSERT_EQUAL((int64_t)0, File(dir+"/"+topDir+"/"+fname4).size()); - CPPUNIT_ASSERT_EQUAL((int64_t)length5, File(dir+"/"+topDir+"/"+fname5).size()); - CPPUNIT_ASSERT_EQUAL((int64_t)0, File(dir+"/"+topDir+"/"+fname6).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(dir+"/"+topDir+"/"+fname1).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(dir+"/"+topDir+"/"+fname2).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(dir+"/"+topDir+"/"+fname3).size()); + CPPUNIT_ASSERT_EQUAL(0ULL, File(dir+"/"+topDir+"/"+fname4).size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(dir+"/"+topDir+"/"+fname5).size()); + CPPUNIT_ASSERT_EQUAL(0ULL, File(dir+"/"+topDir+"/"+fname6).size()); } catch(Exception* e) { std::cerr << *e << std::endl; diff --git a/test/ParameterizedStringParserTest.cc b/test/ParameterizedStringParserTest.cc index 638e1afcf2..99f201312b 100644 --- a/test/ParameterizedStringParserTest.cc +++ b/test/ParameterizedStringParserTest.cc @@ -126,9 +126,9 @@ void ParameterizedStringParserTest::testParse_loop() SharedHandle loop1 = ls; CPPUNIT_ASSERT(!loop1.isNull()); - CPPUNIT_ASSERT_EQUAL((int32_t)1, loop1->getStartValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)10, loop1->getEndValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)2, loop1->getStep()); + CPPUNIT_ASSERT_EQUAL(1, loop1->getStartValue()); + CPPUNIT_ASSERT_EQUAL(10, loop1->getEndValue()); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, loop1->getStep()); } void ParameterizedStringParserTest::testParse_loop_empty() @@ -189,9 +189,9 @@ void ParameterizedStringParserTest::testParse_alphaLoop() SharedHandle loop1 = ls; CPPUNIT_ASSERT(!loop1.isNull()); - CPPUNIT_ASSERT_EQUAL((int32_t)0, loop1->getStartValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)25, loop1->getEndValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)2, loop1->getStep()); + CPPUNIT_ASSERT_EQUAL(0, loop1->getStartValue()); + CPPUNIT_ASSERT_EQUAL(25, loop1->getEndValue()); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, loop1->getStep()); } void ParameterizedStringParserTest::testParse_loop_mixedChar() @@ -230,9 +230,9 @@ void ParameterizedStringParserTest::testParse_segment_loop() SharedHandle loop1 = segment1->getNext(); CPPUNIT_ASSERT(!loop1.isNull()); - CPPUNIT_ASSERT_EQUAL((int32_t)1, loop1->getStartValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)3, loop1->getEndValue()); - CPPUNIT_ASSERT_EQUAL((int32_t)1, loop1->getStep()); + CPPUNIT_ASSERT_EQUAL(1, loop1->getStartValue()); + CPPUNIT_ASSERT_EQUAL(3, loop1->getEndValue()); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, loop1->getStep()); SharedHandle segment2 = loop1->getNext(); CPPUNIT_ASSERT(!segment2.isNull()); diff --git a/test/RequestTest.cc b/test/RequestTest.cc index 0497f0129f..b6b7806cf7 100644 --- a/test/RequestTest.cc +++ b/test/RequestTest.cc @@ -74,7 +74,7 @@ void RequestTest::testSetUrl1() { CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getCurrentUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); @@ -94,7 +94,7 @@ void RequestTest::testSetUrl2() { // previousUrl must equal to referer; CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); @@ -106,7 +106,7 @@ void RequestTest::testSetUrl3() { CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); @@ -118,7 +118,7 @@ void RequestTest::testSetUrl4() { CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); @@ -130,7 +130,7 @@ void RequestTest::testSetUrl5() { CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); @@ -142,7 +142,7 @@ void RequestTest::testSetUrl6() { CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria3"), req.getFile()); @@ -216,7 +216,7 @@ void RequestTest::testSetUrl14() { CPPUNIT_ASSERT(v); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); - CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("abc?query"), req.getFile()); } @@ -274,7 +274,7 @@ void RequestTest::testRedirectUrl() { CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.co.jp"), req.getHost()); - CPPUNIT_ASSERT_EQUAL((int32_t)80, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile()); } @@ -315,7 +315,7 @@ void RequestTest::testResetUrl() { // referer is unchanged CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getReferer()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)8080, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); @@ -333,7 +333,7 @@ void RequestTest::testSetUrl_zeroUsername() Request req; CPPUNIT_ASSERT(req.setUrl("ftp://@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)21, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); @@ -342,7 +342,7 @@ void RequestTest::testSetUrl_zeroUsername() CPPUNIT_ASSERT(req.setUrl("ftp://:@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)21, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); @@ -351,7 +351,7 @@ void RequestTest::testSetUrl_zeroUsername() CPPUNIT_ASSERT(req.setUrl("ftp://:pass@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)21, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); @@ -365,7 +365,7 @@ void RequestTest::testSetUrl_username() Request req; CPPUNIT_ASSERT(req.setUrl("ftp://aria2user@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)21, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); @@ -378,7 +378,7 @@ void RequestTest::testSetUrl_usernamePassword() Request req; CPPUNIT_ASSERT(req.setUrl("ftp://aria2user%40:aria2pass%40@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); - CPPUNIT_ASSERT_EQUAL((int32_t)21, req.getPort()); + CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); diff --git a/test/SharedHandleTest.cc b/test/SharedHandleTest.cc index 5220d66dad..760e84f86a 100644 --- a/test/SharedHandleTest.cc +++ b/test/SharedHandleTest.cc @@ -35,23 +35,23 @@ void SharedHandleTest::testSharedHandle() { std::cerr << "xh:" << std::endl; SharedHandle xh = new int(1); - CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, xh.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, xh.getRefCount()->strongRefCount); std::cerr << "nullHandle:" << std::endl; SharedHandle nullHandle = 0; - CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, nullHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, nullHandle.getRefCount()->strongRefCount); std::cerr << "staticHandle:" << std::endl; - CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, staticHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)1, staticHandle.getRefCount()->strongRefCount); SharedHandle localStaticHandle = getInstance(); - CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->totalRefCount); - CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->strongRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, localStaticHandle.getRefCount()->totalRefCount); + CPPUNIT_ASSERT_EQUAL((unsigned int)2, localStaticHandle.getRefCount()->strongRefCount); } } // namespace aria2 diff --git a/test/SingleFileAllocationIteratorTest.cc b/test/SingleFileAllocationIteratorTest.cc index e238b181a3..39d2bc028f 100644 --- a/test/SingleFileAllocationIteratorTest.cc +++ b/test/SingleFileAllocationIteratorTest.cc @@ -32,7 +32,7 @@ void SingleFileAllocationIteratorTest::testAllocate() of.close(); File x(fn); - CPPUNIT_ASSERT_EQUAL((int64_t)10, x.size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)10, x.size()); DefaultDiskWriter writer; int64_t offset = 10; @@ -47,7 +47,7 @@ void SingleFileAllocationIteratorTest::testAllocate() itr.allocateChunk(); } File f(fn); - CPPUNIT_ASSERT_EQUAL((int64_t)40960, f.size()); + CPPUNIT_ASSERT_EQUAL((uint64_t)40960, f.size()); } } // namespace aria2 diff --git a/test/SocketCoreTest.cc b/test/SocketCoreTest.cc index 55962c1c85..da0862ccfd 100644 --- a/test/SocketCoreTest.cc +++ b/test/SocketCoreTest.cc @@ -29,7 +29,7 @@ void SocketCoreTest::testWriteAndReadDatagram() SocketCore c(SOCK_DGRAM); c.bind(0); - std::pair svaddr; + std::pair svaddr; s.getAddrInfo(svaddr); std::string message1 = "hello world."; diff --git a/test/UtilTest.cc b/test/UtilTest.cc index b6c467028f..355217dd6a 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -305,8 +305,8 @@ void UtilTest::testUrldecode() { } void UtilTest::testCountBit() { - CPPUNIT_ASSERT_EQUAL((int32_t)32, Util::countBit(UINT32_MAX)); - CPPUNIT_ASSERT_EQUAL((int32_t)8, Util::countBit(255)); + CPPUNIT_ASSERT_EQUAL((unsigned int)32, Util::countBit(UINT32_MAX)); + CPPUNIT_ASSERT_EQUAL((unsigned int)8, Util::countBit(255)); } void UtilTest::testGetRealSize() @@ -412,12 +412,12 @@ void UtilTest::testIsUppercase() void UtilTest::testAlphaToNum() { - CPPUNIT_ASSERT_EQUAL((int32_t)0, Util::alphaToNum("a")); - CPPUNIT_ASSERT_EQUAL((int32_t)0, Util::alphaToNum("aa")); - CPPUNIT_ASSERT_EQUAL((int32_t)1, Util::alphaToNum("b")); - CPPUNIT_ASSERT_EQUAL((int32_t)675, Util::alphaToNum("zz")); // 25*26+25 - CPPUNIT_ASSERT_EQUAL((int32_t)675, Util::alphaToNum("ZZ")); // 25*26+25 - CPPUNIT_ASSERT_EQUAL((int32_t)0, Util::alphaToNum("")); + CPPUNIT_ASSERT_EQUAL(0, Util::alphaToNum("a")); + CPPUNIT_ASSERT_EQUAL(0, Util::alphaToNum("aa")); + CPPUNIT_ASSERT_EQUAL(1, Util::alphaToNum("b")); + CPPUNIT_ASSERT_EQUAL(675, Util::alphaToNum("zz")); // 25*26+25 + CPPUNIT_ASSERT_EQUAL(675, Util::alphaToNum("ZZ")); // 25*26+25 + CPPUNIT_ASSERT_EQUAL(0, Util::alphaToNum("")); } void UtilTest::testMkdirs() @@ -604,27 +604,27 @@ void UtilTest::testToString_binaryStream() void UtilTest::testItos() { { - int32_t i = 0; + int i = 0; CPPUNIT_ASSERT_EQUAL(std::string("0"), Util::itos(i)); } { - int32_t i = 100; + int i = 100; CPPUNIT_ASSERT_EQUAL(std::string("100"), Util::itos(i, true)); } { - int32_t i = 100; + int i = 100; CPPUNIT_ASSERT_EQUAL(std::string("100"), Util::itos(i)); } { - int32_t i = 12345; + int i = 12345; CPPUNIT_ASSERT_EQUAL(std::string("12,345"), Util::itos(i, true)); } { - int32_t i = 12345; + int i = 12345; CPPUNIT_ASSERT_EQUAL(std::string("12345"), Util::itos(i)); } { - int32_t i = -12345; + int i = -12345; CPPUNIT_ASSERT_EQUAL(std::string("-12,345"), Util::itos(i, true)); } {