mirror of https://github.com/aria2/aria2
Use int or int32_t instead of size_t where suitable
parent
30e0e19e67
commit
7989cd898d
|
@ -39,7 +39,7 @@
|
|||
namespace aria2 {
|
||||
|
||||
BtPieceMessageValidator::BtPieceMessageValidator
|
||||
(const BtPieceMessage* message, size_t numPiece, size_t pieceLength)
|
||||
(const BtPieceMessage* message, size_t numPiece, int32_t pieceLength)
|
||||
: message_(message),
|
||||
numPiece_(numPiece),
|
||||
pieceLength_(pieceLength)
|
||||
|
|
|
@ -45,11 +45,11 @@ class BtPieceMessageValidator : public BtMessageValidator {
|
|||
private:
|
||||
const BtPieceMessage* message_;
|
||||
size_t numPiece_;
|
||||
size_t pieceLength_;
|
||||
int32_t pieceLength_;
|
||||
public:
|
||||
BtPieceMessageValidator(const BtPieceMessage* message,
|
||||
size_t numPiece,
|
||||
size_t pieceLength);
|
||||
int32_t pieceLength);
|
||||
|
||||
~BtPieceMessageValidator();
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ void BtPortMessage::doReceivedAction()
|
|||
SharedHandle<DHTTask> task = taskFactory_->createPingTask(node);
|
||||
taskQueue_->addImmediateTask(task);
|
||||
}
|
||||
if(routingTable_->countBucket() == 1) {
|
||||
if(routingTable_->getNumBucket() == 1) {
|
||||
// initiate bootstrap
|
||||
A2_LOG_INFO("Dispatch node_lookup since too few buckets.");
|
||||
taskQueue_->addImmediateTask
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
namespace aria2 {
|
||||
|
||||
DHTPingTask::DHTPingTask
|
||||
(const SharedHandle<DHTNode>& remoteNode, size_t numMaxRetry):
|
||||
(const SharedHandle<DHTNode>& remoteNode, int numMaxRetry):
|
||||
remoteNode_(remoteNode),
|
||||
numMaxRetry_(numMaxRetry),
|
||||
numRetry_(0),
|
||||
|
|
|
@ -46,9 +46,9 @@ class DHTPingTask:public DHTAbstractTask {
|
|||
private:
|
||||
SharedHandle<DHTNode> remoteNode_;
|
||||
|
||||
size_t numMaxRetry_;
|
||||
int numMaxRetry_;
|
||||
|
||||
size_t numRetry_;
|
||||
int numRetry_;
|
||||
|
||||
bool pingSuccessful_;
|
||||
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
|
||||
void addMessage();
|
||||
public:
|
||||
DHTPingTask(const SharedHandle<DHTNode>& remoteNode, size_t numMaxRetry = 0);
|
||||
DHTPingTask(const SharedHandle<DHTNode>& remoteNode, int numMaxRetry = 0);
|
||||
|
||||
virtual ~DHTPingTask();
|
||||
|
||||
|
|
|
@ -82,12 +82,16 @@ void DHTReplaceNodeTask::onReceived(const DHTPingReplyMessage* message)
|
|||
setFinished(true);
|
||||
}
|
||||
|
||||
namespace {
|
||||
const int MAX_RETRY = 2;
|
||||
} //namespace
|
||||
|
||||
void DHTReplaceNodeTask::onTimeout(const SharedHandle<DHTNode>& node)
|
||||
{
|
||||
++numRetry_;
|
||||
if(numRetry_ >= MAX_RETRY) {
|
||||
A2_LOG_INFO(fmt("ReplaceNode: Ping failed %lu times. Replace %s with %s.",
|
||||
static_cast<unsigned long>(numRetry_),
|
||||
A2_LOG_INFO(fmt("ReplaceNode: Ping failed %d times. Replace %s with %s.",
|
||||
numRetry_,
|
||||
node->toString().c_str(),
|
||||
newNode_->toString().c_str()));
|
||||
node->markBad();
|
||||
|
|
|
@ -49,9 +49,7 @@ private:
|
|||
|
||||
SharedHandle<DHTNode> newNode_;
|
||||
|
||||
static const size_t MAX_RETRY = 2;
|
||||
|
||||
size_t numRetry_;
|
||||
int numRetry_;
|
||||
|
||||
time_t timeout_;
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ void DHTRoutingTable::getClosestKNodes
|
|||
dht::findClosestKNodes(nodes, root_, key);
|
||||
}
|
||||
|
||||
size_t DHTRoutingTable::countBucket() const
|
||||
int DHTRoutingTable::getNumBucket() const
|
||||
{
|
||||
return numBucket_;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
|
||||
DHTBucketTreeNode* root_;
|
||||
|
||||
size_t numBucket_;
|
||||
int numBucket_;
|
||||
|
||||
SharedHandle<DHTTaskQueue> taskQueue_;
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
|||
void getClosestKNodes(std::vector<SharedHandle<DHTNode> >& nodes,
|
||||
const unsigned char* key) const;
|
||||
|
||||
size_t countBucket() const;
|
||||
int getNumBucket() const;
|
||||
|
||||
void showBuckets() const;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
DHTTaskExecutor::DHTTaskExecutor(size_t numConcurrent)
|
||||
DHTTaskExecutor::DHTTaskExecutor(int numConcurrent)
|
||||
: numConcurrent_(numConcurrent)
|
||||
{}
|
||||
|
||||
|
@ -55,7 +55,12 @@ void DHTTaskExecutor::update()
|
|||
execTasks_.erase(std::remove_if(execTasks_.begin(), execTasks_.end(),
|
||||
mem_fun_sh(&DHTTask::finished)),
|
||||
execTasks_.end());
|
||||
size_t r = numConcurrent_-execTasks_.size();
|
||||
int r;
|
||||
if(static_cast<size_t>(numConcurrent_) > execTasks_.size()) {
|
||||
r = numConcurrent_-execTasks_.size();
|
||||
} else {
|
||||
r = 0;
|
||||
}
|
||||
while(r && !queue_.empty()) {
|
||||
SharedHandle<DHTTask> task = queue_.front();
|
||||
queue_.pop_front();
|
||||
|
|
|
@ -48,11 +48,11 @@ class DHTTask;
|
|||
|
||||
class DHTTaskExecutor {
|
||||
private:
|
||||
size_t numConcurrent_;
|
||||
int numConcurrent_;
|
||||
std::vector<SharedHandle<DHTTask> > execTasks_;
|
||||
std::deque<SharedHandle<DHTTask> > queue_;
|
||||
public:
|
||||
DHTTaskExecutor(size_t numConcurrent);
|
||||
DHTTaskExecutor(int numConcurrent);
|
||||
|
||||
~DHTTaskExecutor();
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
return execTasks_.size();
|
||||
}
|
||||
|
||||
size_t getNumConcurrent() const
|
||||
int getNumConcurrent() const
|
||||
{
|
||||
return numConcurrent_;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createPingTask(const SharedHandle<DHTNode>& remoteNode,
|
||||
size_t numRetry = 0) = 0;
|
||||
int numRetry = 0) = 0;
|
||||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createNodeLookupTask(const unsigned char* targetID) = 0;
|
||||
|
|
|
@ -62,7 +62,7 @@ DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {}
|
|||
|
||||
SharedHandle<DHTTask>
|
||||
DHTTaskFactoryImpl::createPingTask(const SharedHandle<DHTNode>& remoteNode,
|
||||
size_t numRetry)
|
||||
int numRetry)
|
||||
{
|
||||
SharedHandle<DHTPingTask> task(new DHTPingTask(remoteNode, numRetry));
|
||||
task->setTimeout(timeout_);
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createPingTask(const SharedHandle<DHTNode>& remoteNode,
|
||||
size_t numRetry = 0);
|
||||
int numRetry = 0);
|
||||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createNodeLookupTask(const unsigned char* targetID);
|
||||
|
|
|
@ -149,7 +149,7 @@ FileEntry::getRequest
|
|||
if(req->setUri(uri)) {
|
||||
if(std::count(inFlightHosts.begin(),
|
||||
inFlightHosts.end(),req->getHost())
|
||||
>= static_cast<int>(maxConnectionPerServer_)) {
|
||||
>= maxConnectionPerServer_) {
|
||||
pending.push_back(uri);
|
||||
ignoreHost.push_back(req->getHost());
|
||||
req.reset();
|
||||
|
@ -250,10 +250,10 @@ FileEntry::findFasterRequest
|
|||
continue;
|
||||
}
|
||||
if(std::count(inFlightHosts.begin(), inFlightHosts.end(),us.host)
|
||||
>= static_cast<int>(maxConnectionPerServer_)) {
|
||||
>= maxConnectionPerServer_) {
|
||||
A2_LOG_DEBUG(fmt("%s has already used %d times, not considered.",
|
||||
(*i).c_str(),
|
||||
static_cast<int>(maxConnectionPerServer_)));
|
||||
maxConnectionPerServer_));
|
||||
continue;
|
||||
}
|
||||
if(findSecond(usedHosts.begin(), usedHosts.end(), us.host) !=
|
||||
|
|
|
@ -71,7 +71,7 @@ private:
|
|||
// available.
|
||||
std::deque<URIResult> uriResults_;
|
||||
bool uniqueProtocol_;
|
||||
size_t maxConnectionPerServer_;
|
||||
int maxConnectionPerServer_;
|
||||
std::string originalName_;
|
||||
Timer lastFasterReplace_;
|
||||
|
||||
|
@ -214,12 +214,12 @@ public:
|
|||
void extractURIResult
|
||||
(std::deque<URIResult>& res, error_code::Value r);
|
||||
|
||||
void setMaxConnectionPerServer(size_t n)
|
||||
void setMaxConnectionPerServer(int n)
|
||||
{
|
||||
maxConnectionPerServer_ = n;
|
||||
}
|
||||
|
||||
size_t getMaxConnectionPerServer() const
|
||||
int getMaxConnectionPerServer() const
|
||||
{
|
||||
return maxConnectionPerServer_;
|
||||
}
|
||||
|
|
|
@ -68,13 +68,13 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
static const size_t PRIME_BITS = 768;
|
||||
static const size_t KEY_LENGTH = (PRIME_BITS+7)/8;
|
||||
static const size_t VC_LENGTH = 8;
|
||||
static const size_t PRIME_BITS = 768U;
|
||||
static const size_t KEY_LENGTH = (PRIME_BITS+7U)/8U;
|
||||
static const size_t VC_LENGTH = 8U;
|
||||
// The largest buffering occurs when receiver receives step2
|
||||
// handshake. We believe that IA is less than or equal to
|
||||
// BtHandshakeMessage::MESSAGE_LENGTH
|
||||
static const size_t MAX_BUFFER_LENGTH = 636;
|
||||
static const size_t MAX_BUFFER_LENGTH = 636U;
|
||||
|
||||
cuid_t cuid_;
|
||||
SharedHandle<SocketCore> socket_;
|
||||
|
|
|
@ -241,7 +241,7 @@ void MultiDiskAdaptor::openIfNot
|
|||
// A2_LOG_DEBUG(fmt("DiskWriterEntry: Cache MISS. offset=%s",
|
||||
// util::itos(entry->getFileEntry()->getOffset()).c_str()));
|
||||
|
||||
size_t numOpened = openedDiskWriterEntries_.size();
|
||||
int numOpened = openedDiskWriterEntries_.size();
|
||||
(entry.get()->*open)();
|
||||
if(numOpened >= maxOpenFiles_) {
|
||||
// Cache is full.
|
||||
|
@ -465,7 +465,7 @@ void MultiDiskAdaptor::cutTrailingGarbage()
|
|||
}
|
||||
}
|
||||
|
||||
void MultiDiskAdaptor::setMaxOpenFiles(size_t maxOpenFiles)
|
||||
void MultiDiskAdaptor::setMaxOpenFiles(int maxOpenFiles)
|
||||
{
|
||||
maxOpenFiles_ = maxOpenFiles;
|
||||
}
|
||||
|
|
|
@ -104,12 +104,12 @@ typedef std::vector<DiskWriterEntryHandle> DiskWriterEntries;
|
|||
class MultiDiskAdaptor : public DiskAdaptor {
|
||||
friend class MultiFileAllocationIterator;
|
||||
private:
|
||||
size_t pieceLength_;
|
||||
int32_t pieceLength_;
|
||||
DiskWriterEntries diskWriterEntries_;
|
||||
|
||||
std::vector<SharedHandle<DiskWriterEntry> > openedDiskWriterEntries_;
|
||||
|
||||
size_t maxOpenFiles_;
|
||||
int maxOpenFiles_;
|
||||
|
||||
bool readOnly_;
|
||||
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
void openIfNot(const SharedHandle<DiskWriterEntry>& entry,
|
||||
void (DiskWriterEntry::*f)());
|
||||
|
||||
static const size_t DEFAULT_MAX_OPEN_FILES = 100;
|
||||
static const int DEFAULT_MAX_OPEN_FILES = 100;
|
||||
|
||||
public:
|
||||
MultiDiskAdaptor();
|
||||
|
@ -149,18 +149,18 @@ public:
|
|||
|
||||
virtual bool isReadOnlyEnabled() const { return readOnly_; }
|
||||
|
||||
void setPieceLength(size_t pieceLength)
|
||||
void setPieceLength(int32_t pieceLength)
|
||||
{
|
||||
pieceLength_ = pieceLength;
|
||||
}
|
||||
|
||||
size_t getPieceLength() const {
|
||||
int32_t getPieceLength() const {
|
||||
return pieceLength_;
|
||||
}
|
||||
|
||||
virtual void cutTrailingGarbage();
|
||||
|
||||
void setMaxOpenFiles(size_t maxOpenFiles);
|
||||
void setMaxOpenFiles(int maxOpenFiles);
|
||||
|
||||
virtual size_t utime(const Time& actime, const Time& modtime);
|
||||
|
||||
|
|
|
@ -560,10 +560,10 @@ void RequestGroupMan::closeFile()
|
|||
|
||||
RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
|
||||
{
|
||||
size_t finished = 0;
|
||||
size_t error = removedErrorResult_;
|
||||
size_t inprogress = 0;
|
||||
size_t removed = 0;
|
||||
int finished = 0;
|
||||
int error = removedErrorResult_;
|
||||
int inprogress = 0;
|
||||
int removed = 0;
|
||||
error_code::Value lastError = removedLastErrorResult_;
|
||||
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr =
|
||||
downloadResults_.begin(), eoi = downloadResults_.end();
|
||||
|
@ -850,7 +850,7 @@ void RequestGroupMan::addDownloadResult(const SharedHandle<DownloadResult>& dr)
|
|||
++removedErrorResult_;
|
||||
}
|
||||
} else {
|
||||
size_t curSize = downloadResults_.size();
|
||||
int curSize = downloadResults_.size();
|
||||
if(curSize >= maxDownloadResult_) {
|
||||
std::deque<SharedHandle<DownloadResult> >::iterator last =
|
||||
downloadResults_.begin()+curSize-maxDownloadResult_+1;
|
||||
|
|
|
@ -78,12 +78,12 @@ private:
|
|||
|
||||
// The number of error DownloadResult removed because of upper limit
|
||||
// of the queue
|
||||
size_t removedErrorResult_;
|
||||
int removedErrorResult_;
|
||||
|
||||
// The last error of removed DownloadResult
|
||||
error_code::Value removedLastErrorResult_;
|
||||
|
||||
size_t maxDownloadResult_;
|
||||
int maxDownloadResult_;
|
||||
|
||||
void formatDownloadResultFull
|
||||
(OutputFile& out,
|
||||
|
@ -173,18 +173,18 @@ public:
|
|||
|
||||
class DownloadStat {
|
||||
private:
|
||||
size_t completed_;
|
||||
size_t error_;
|
||||
size_t inProgress_;
|
||||
size_t removed_;
|
||||
size_t waiting_;
|
||||
int completed_;
|
||||
int error_;
|
||||
int inProgress_;
|
||||
int removed_;
|
||||
int waiting_;
|
||||
error_code::Value lastErrorResult_;
|
||||
public:
|
||||
DownloadStat(size_t completed,
|
||||
size_t error,
|
||||
size_t inProgress,
|
||||
size_t removed,
|
||||
size_t waiting,
|
||||
DownloadStat(int completed,
|
||||
int error,
|
||||
int inProgress,
|
||||
int removed,
|
||||
int waiting,
|
||||
error_code::Value lastErrorResult =
|
||||
error_code::FINISHED):
|
||||
completed_(completed),
|
||||
|
@ -204,7 +204,7 @@ public:
|
|||
return error_ == 0 && inProgress_ == 0 && waiting_ == 0;
|
||||
}
|
||||
|
||||
size_t getInProgress() const
|
||||
int getInProgress() const
|
||||
{
|
||||
return inProgress_;
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ public:
|
|||
return serverStatMan_;
|
||||
}
|
||||
|
||||
void setMaxDownloadResult(size_t v)
|
||||
void setMaxDownloadResult(int v)
|
||||
{
|
||||
maxDownloadResult_ = v;
|
||||
}
|
||||
|
|
|
@ -331,11 +331,11 @@ private:
|
|||
template<typename InputIterator>
|
||||
std::pair<InputIterator, InputIterator>
|
||||
getPaginationRange
|
||||
(ssize_t offset, size_t num, InputIterator first, InputIterator last)
|
||||
(int offset, int num, InputIterator first, InputIterator last)
|
||||
{
|
||||
size_t size = std::distance(first, last);
|
||||
int size = std::distance(first, last);
|
||||
if(offset < 0) {
|
||||
ssize_t tempoffset = offset+size;
|
||||
int tempoffset = offset+size;
|
||||
if(tempoffset < 0) {
|
||||
return std::make_pair(last, last);
|
||||
}
|
||||
|
@ -344,10 +344,10 @@ private:
|
|||
offset = 0;
|
||||
num = tempoffset+1;
|
||||
}
|
||||
} else if(size <= (size_t)offset) {
|
||||
} else if(size <= offset) {
|
||||
return std::make_pair(last, last);
|
||||
}
|
||||
size_t lastDistance;
|
||||
int lastDistance;
|
||||
if(size < offset+num) {
|
||||
lastDistance = size;
|
||||
} else {
|
||||
|
@ -369,8 +369,8 @@ protected:
|
|||
if(numParam->i() < 0) {
|
||||
throw DL_ABORT_EX("The parameter num must be zero or positive integer.");
|
||||
}
|
||||
ssize_t offset = offsetParam->i();
|
||||
size_t num = numParam->i();
|
||||
int offset = offsetParam->i();
|
||||
int num = numParam->i();
|
||||
std::vector<std::string> keys;
|
||||
toStringList(std::back_inserter(keys), keysParam);
|
||||
const std::deque<SharedHandle<T> >& items = getItems(e);
|
||||
|
|
|
@ -175,12 +175,12 @@ void BittorrentHelperTest::testGetFileEntries() {
|
|||
fileEntry1->getPath());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-test/aria2/src/aria2c"),
|
||||
fileEntry1->getOriginalName());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry1->getMaxConnectionPerServer());
|
||||
CPPUNIT_ASSERT_EQUAL(10, fileEntry1->getMaxConnectionPerServer());
|
||||
itr++;
|
||||
SharedHandle<FileEntry> fileEntry2 = *itr;
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("./aria2-test/aria2-0.2.2.tar.bz2"),
|
||||
fileEntry2->getPath());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry2->getMaxConnectionPerServer());
|
||||
CPPUNIT_ASSERT_EQUAL(10, fileEntry2->getMaxConnectionPerServer());
|
||||
}
|
||||
|
||||
void BittorrentHelperTest::testGetFileEntriesSingle() {
|
||||
|
@ -198,7 +198,7 @@ void BittorrentHelperTest::testGetFileEntriesSingle() {
|
|||
fileEntry1->getPath());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"),
|
||||
fileEntry1->getOriginalName());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)10, fileEntry1->getMaxConnectionPerServer());
|
||||
CPPUNIT_ASSERT_EQUAL(10, fileEntry1->getMaxConnectionPerServer());
|
||||
}
|
||||
|
||||
void BittorrentHelperTest::testGetTotalLength() {
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
class MockDHTTaskFactory2:public MockDHTTaskFactory {
|
||||
public:
|
||||
virtual SharedHandle<DHTTask>
|
||||
createPingTask(const SharedHandle<DHTNode>& remoteNode, size_t numRetry)
|
||||
createPingTask(const SharedHandle<DHTNode>& remoteNode, int numRetry)
|
||||
{
|
||||
return SharedHandle<DHTTask>(new MockDHTTask(remoteNode));
|
||||
}
|
||||
|
|
|
@ -11,14 +11,7 @@ public:
|
|||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createPingTask(const SharedHandle<DHTNode>& remoteNode,
|
||||
size_t numRetry = 0)
|
||||
{
|
||||
return SharedHandle<DHTTask>();
|
||||
}
|
||||
|
||||
virtual SharedHandle<DHTTask>
|
||||
createGetIDTask(const SharedHandle<DHTNode>& remoteNode,
|
||||
size_t numRetry = 0)
|
||||
int numRetry = 0)
|
||||
{
|
||||
return SharedHandle<DHTTask>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue