diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 118846f1..b4777013 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -320,7 +320,7 @@ bool AbstractCommand::execute() { req_->addTryCount(); req_->resetRedirectCount(); req_->resetUri(); - const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES); + const int maxTries = getOption()->getAsInt(PREF_MAX_TRIES); bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries; if(isAbort) { A2_LOG_INFO(fmt(MSG_MAX_TRY, diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index d2b54c81..35be6bea 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -82,10 +82,9 @@ bool ActivePeerConnectionCommand::execute() { if(checkPoint_.difference(global::wallclock()) >= interval_) { checkPoint_ = global::wallclock(); TransferStat tstat = requestGroup_->calculateStat(); - const unsigned int maxDownloadLimit = - requestGroup_->getMaxDownloadSpeedLimit(); - const unsigned int maxUploadLimit = requestGroup_->getMaxUploadSpeedLimit(); - unsigned int thresholdSpeed; + const int maxDownloadLimit = requestGroup_->getMaxDownloadSpeedLimit(); + const int maxUploadLimit = requestGroup_->getMaxUploadSpeedLimit(); + int thresholdSpeed; if(!bittorrent::getTorrentAttrs (requestGroup_->getDownloadContext())->metadata.empty()) { thresholdSpeed = @@ -104,7 +103,7 @@ bool ActivePeerConnectionCommand::execute() { (tstat.getDownloadSpeed() < thresholdSpeed || btRuntime_->lessThanMinPeers()))) { - unsigned int numConnection = 0; + int numConnection = 0; if(pieceStorage_->downloadFinished()) { if(btRuntime_->getMaxPeers() > btRuntime_->getConnections()) { numConnection = @@ -115,7 +114,7 @@ bool ActivePeerConnectionCommand::execute() { numConnection = numNewConnection_; } - for(unsigned int numAdd = numConnection; + for(int numAdd = numConnection; numAdd > 0 && peerStorage_->isPeerAvailable(); --numAdd) { SharedHandle peer = peerStorage_->getUnusedPeer(); connectToPeer(peer); diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h index 5b270e39..b1912584 100644 --- a/src/ActivePeerConnectionCommand.h +++ b/src/ActivePeerConnectionCommand.h @@ -60,7 +60,7 @@ private: time_t interval_; // UNIT: sec DownloadEngine* e_; Timer checkPoint_; - unsigned int numNewConnection_; // the number of the connection to establish. + int numNewConnection_; // the number of the connection to establish. public: ActivePeerConnectionCommand(cuid_t cuid, RequestGroup* requestGroup, @@ -73,7 +73,7 @@ public: void connectToPeer(const SharedHandle& peer); - void setNumNewConnection(size_t numNewConnection) + void setNumNewConnection(int numNewConnection) { numNewConnection_ = numNewConnection; } diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index 3392a1da..eca81f82 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -125,12 +125,13 @@ std::string AdaptiveURISelector::selectOne(const std::deque& uris) if(uris.empty()) { return A2STR::NIL; } else { - const unsigned int numPieces = + const size_t numPieces = requestGroup_->getDownloadContext()->getNumPieces(); bool reservedContext = numPieces > 0 && - nbConnections_ > std::min(numPieces, - requestGroup_->getNumConcurrentCommand()); + static_cast(nbConnections_) > std::min + (numPieces, + static_cast(requestGroup_->getNumConcurrentCommand())); bool selectBest = numPieces == 0 || reservedContext; if(numPieces > 0) @@ -180,8 +181,8 @@ std::string AdaptiveURISelector::getBestMirror (const std::deque& uris) const { /* Here we return one of the bests mirrors */ - unsigned int max = getMaxDownloadSpeed(uris); - unsigned int min = max-(int)(max*0.25); + int max = getMaxDownloadSpeed(uris); + int min = max-(int)(max*0.25); std::deque bests = getUrisBySpeed(uris, min); if (bests.size() < 2) { @@ -218,11 +219,11 @@ void AdaptiveURISelector::tuneDownloadCommand void AdaptiveURISelector::adjustLowestSpeedLimit (const std::deque& uris, DownloadCommand* command) const { - unsigned int lowest = + int lowest = requestGroup_->getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT); if (lowest > 0) { - unsigned int low_lowest = 4 * 1024; - unsigned int max = getMaxDownloadSpeed(uris); + int low_lowest = 4 * 1024; + int max = getMaxDownloadSpeed(uris); if (max > 0 && lowest > max / 4) { A2_LOG_NOTICE(fmt(_("Lowering lowest-speed-limit since known max speed is" " too near (new:%d was:%d max:%d)"), @@ -241,14 +242,14 @@ void AdaptiveURISelector::adjustLowestSpeedLimit } namespace { -unsigned int getUriMaxSpeed(SharedHandle ss) +int getUriMaxSpeed(SharedHandle ss) { return std::max(ss->getSingleConnectionAvgSpeed(), ss->getMultiConnectionAvgSpeed()); } } // namespace -unsigned int AdaptiveURISelector::getMaxDownloadSpeed +int AdaptiveURISelector::getMaxDownloadSpeed (const std::deque& uris) const { std::string uri = getMaxDownloadSpeedUri(uris); @@ -281,7 +282,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri } std::deque AdaptiveURISelector::getUrisBySpeed -(const std::deque& uris, unsigned int min) const +(const std::deque& uris, int min) const { std::deque bests; for(std::deque::const_iterator i = uris.begin(), @@ -321,7 +322,7 @@ std::string AdaptiveURISelector::getFirstNotTestedUri std::string AdaptiveURISelector::getFirstToTestUri (const std::deque& uris) const { - unsigned int counter; + int counter; int power; for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { @@ -352,10 +353,10 @@ SharedHandle AdaptiveURISelector::getServerStats } } -unsigned int AdaptiveURISelector::getNbTestedServers +int AdaptiveURISelector::getNbTestedServers (const std::deque& uris) const { - unsigned int counter = 0; + int counter = 0; for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); diff --git a/src/AdaptiveURISelector.h b/src/AdaptiveURISelector.h index b8ac6b75..a2d4843c 100644 --- a/src/AdaptiveURISelector.h +++ b/src/AdaptiveURISelector.h @@ -49,8 +49,8 @@ private: SharedHandle serverStatMan_; // No need to delete requestGroup_ RequestGroup* requestGroup_; - unsigned int nbServerToEvaluate_; - unsigned int nbConnections_; + int nbServerToEvaluate_; + int nbConnections_; static const time_t MAX_TIMEOUT = 60; @@ -59,15 +59,15 @@ private: std::string selectOne(const std::deque& uris); void adjustLowestSpeedLimit(const std::deque& uris, DownloadCommand* command) const; - unsigned int getMaxDownloadSpeed(const std::deque& uris) const; + int getMaxDownloadSpeed(const std::deque& uris) const; std::string getMaxDownloadSpeedUri(const std::deque& uris) const; std::deque getUrisBySpeed(const std::deque& uris, - unsigned int min) const; + int min) const; std::string selectRandomUri(const std::deque& uris) const; std::string getFirstNotTestedUri(const std::deque& uris) const; std::string getFirstToTestUri(const std::deque& uris) const; SharedHandle getServerStats(const std::string& uri) const; - unsigned int getNbTestedServers(const std::deque& uris) const; + int getNbTestedServers(const std::deque& uris) const; std::string getBestMirror(const std::deque& uris) const; public: AdaptiveURISelector(const SharedHandle& serverStatMan, diff --git a/src/BtLeecherStateChoke.cc b/src/BtLeecherStateChoke.cc index 41a2ab45..79bb72a2 100644 --- a/src/BtLeecherStateChoke.cc +++ b/src/BtLeecherStateChoke.cc @@ -91,7 +91,7 @@ const SharedHandle& BtLeecherStateChoke::PeerEntry::getPeer() const return peer_; } -unsigned int BtLeecherStateChoke::PeerEntry::getDownloadSpeed() const +int BtLeecherStateChoke::PeerEntry::getDownloadSpeed() const { return downloadSpeed_; } @@ -178,7 +178,7 @@ void BtLeecherStateChoke::regularUnchoke(std::vector& peerEntries) std::vector::iterator peerIter = peerEntries.begin(); for(;peerIter != rest && count; ++peerIter, --count) { (*peerIter).disableChokingRequired(); - A2_LOG_INFO(fmt("RU: %s, dlspd=%u", + A2_LOG_INFO(fmt("RU: %s, dlspd=%d", (*peerIter).getPeer()->getIPAddress().c_str(), (*peerIter).getDownloadSpeed())); if((*peerIter).getPeer()->optUnchoking()) { diff --git a/src/BtLeecherStateChoke.h b/src/BtLeecherStateChoke.h index cb1ca6d9..9baa7ca7 100644 --- a/src/BtLeecherStateChoke.h +++ b/src/BtLeecherStateChoke.h @@ -55,7 +55,7 @@ private: class PeerEntry { private: SharedHandle peer_; - unsigned int downloadSpeed_; + int downloadSpeed_; bool regularUnchoker_; public: PeerEntry(const SharedHandle& peer); @@ -70,7 +70,7 @@ private: const SharedHandle& getPeer() const; - unsigned int getDownloadSpeed() const; + int getDownloadSpeed() const; bool isRegularUnchoker() const; diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc index 62cd04c0..55eba7cd 100644 --- a/src/BtPieceMessage.cc +++ b/src/BtPieceMessage.cc @@ -136,7 +136,7 @@ void BtPieceMessage::doReceivedAction() } } } else { - A2_LOG_DEBUG(fmt("CUID#%lld - RequestSlot not found, index=%lu, begin=%u", + A2_LOG_DEBUG(fmt("CUID#%lld - RequestSlot not found, index=%lu, begin=%d", getCuid(), static_cast(index_), begin_)); diff --git a/src/BtRuntime.cc b/src/BtRuntime.cc index dca3e09d..6007789c 100644 --- a/src/BtRuntime.cc +++ b/src/BtRuntime.cc @@ -48,10 +48,10 @@ BtRuntime::BtRuntime() BtRuntime::~BtRuntime() {} -void BtRuntime::setMaxPeers(unsigned int maxPeers) +void BtRuntime::setMaxPeers(int maxPeers) { maxPeers_ = maxPeers; - minPeers_ = static_cast(maxPeers*0.8); + minPeers_ = maxPeers*0.8; if(minPeers_ == 0 && maxPeers != 0) { minPeers_ = maxPeers; } diff --git a/src/BtRuntime.h b/src/BtRuntime.h index 90859f41..c2ef7454 100644 --- a/src/BtRuntime.h +++ b/src/BtRuntime.h @@ -44,17 +44,14 @@ class BtRuntime { private: off_t uploadLengthAtStartup_; bool halt_; - unsigned int connections_; + int connections_; bool ready_; // Maximum number of peers to hold connections at the same time. // 0 means unlimited. - unsigned int maxPeers_; + int maxPeers_; // Minimum number of peers. This value is used for getting more peers from // tracker. 0 means always the number of peers is under minimum. - unsigned int minPeers_; - - static const unsigned int DEFAULT_MIN_PEERS = 40; - + int minPeers_; public: BtRuntime(); @@ -74,7 +71,7 @@ public: halt_ = halt; } - unsigned int getConnections() const { return connections_; } + int getConnections() const { return connections_; } void increaseConnections() { ++connections_; } @@ -99,14 +96,15 @@ public: void setReady(bool go) { ready_ = go; } - void setMaxPeers(unsigned int maxPeers); + void setMaxPeers(int maxPeers); - unsigned int getMaxPeers() const + int getMaxPeers() const { return maxPeers_; } - static const unsigned int DEFAULT_MAX_PEERS = 55; + static const int DEFAULT_MAX_PEERS = 55; + static const int DEFAULT_MIN_PEERS = 40; }; typedef SharedHandle BtRuntimeHandle; diff --git a/src/BtSeederStateChoke.cc b/src/BtSeederStateChoke.cc index 724ac17a..152421fc 100644 --- a/src/BtSeederStateChoke.cc +++ b/src/BtSeederStateChoke.cc @@ -134,7 +134,7 @@ void BtSeederStateChoke::unchoke for(std::vector::iterator eoi = peers.end(); r != eoi && count; ++r, --count) { (*r).getPeer()->chokingRequired(false); - A2_LOG_INFO(fmt("RU: %s, ulspd=%u", + A2_LOG_INFO(fmt("RU: %s, ulspd=%d", (*r).getPeer()->getIPAddress().c_str(), (*r).getUploadSpeed())); } diff --git a/src/BtSeederStateChoke.h b/src/BtSeederStateChoke.h index c87fd55f..13e869f2 100644 --- a/src/BtSeederStateChoke.h +++ b/src/BtSeederStateChoke.h @@ -58,7 +58,7 @@ private: size_t outstandingUpload_; Timer lastAmUnchoking_; bool recentUnchoking_; - unsigned int uploadSpeed_; + int uploadSpeed_; const static time_t TIME_FRAME = 20; public: @@ -74,7 +74,7 @@ private: const SharedHandle& getPeer() const { return peer_; } - unsigned int getUploadSpeed() const { return uploadSpeed_; } + int getUploadSpeed() const { return uploadSpeed_; } void disableOptUnchoking(); }; diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index ecc50b18..735a6a84 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -101,7 +101,7 @@ void printProgress const SizeFormatter& sizeFormatter) { TransferStat stat = rg->calculateStat(); - unsigned int eta = 0; + int eta = 0; if(rg->getTotalLength() > 0 && stat.getDownloadSpeed() > 0) { eta = (rg->getTotalLength()-rg->getCompletedLength())/stat.getDownloadSpeed(); } diff --git a/src/DHTConstants.h b/src/DHTConstants.h index 36efab82..a6534b47 100644 --- a/src/DHTConstants.h +++ b/src/DHTConstants.h @@ -37,7 +37,7 @@ // Increment this if major improvements or bug fixes are made in DHT // code. This is 2 bytes unsigned integer. -#define DHT_VERSION 3 +#define DHT_VERSION 3U #define DHT_ID_LENGTH 20 diff --git a/src/DHTNode.cc b/src/DHTNode.cc index 4ef0f64a..3fbdbb8f 100644 --- a/src/DHTNode.cc +++ b/src/DHTNode.cc @@ -117,7 +117,7 @@ void DHTNode::timeout() std::string DHTNode::toString() const { - return fmt("DHTNode ID=%s, Host=%s(%u), Condition=%u, RTT=%u", + return fmt("DHTNode ID=%s, Host=%s(%u), Condition=%d, RTT=%d", util::toHex(id_, DHT_ID_LENGTH).c_str(), ipaddr_.c_str(), port_, diff --git a/src/DHTNode.h b/src/DHTNode.h index dcddcdf2..e6c3bcc9 100644 --- a/src/DHTNode.h +++ b/src/DHTNode.h @@ -54,9 +54,9 @@ private: uint16_t port_; // in milli sec - unsigned int rtt_; + int rtt_; - unsigned int condition_; + int condition_; Timer lastContact_; public: @@ -76,7 +76,7 @@ public: return id_; } - void updateRTT(unsigned int millisec) + void updateRTT(int millisec) { rtt_ = millisec; } diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index 049f3bcd..705ddeef 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -137,7 +137,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() { } else { return A2STR::NIL; } - unsigned int numWant = 50; + int numWant = 50; if(!btRuntime_->lessThanMinPeers() || btRuntime_->isHalt()) { numWant = 0; } @@ -155,7 +155,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() { "left=%lld&" "compact=1&" "key=%s&" - "numwant=%u&" + "numwant=%d&" "no_peer_id=1", util::torrentPercentEncode (bittorrent::getInfoHash(downloadContext_), diff --git a/src/DefaultBtAnnounce.h b/src/DefaultBtAnnounce.h index c69e4214..a760a140 100644 --- a/src/DefaultBtAnnounce.h +++ b/src/DefaultBtAnnounce.h @@ -51,13 +51,13 @@ class Randomizer; class DefaultBtAnnounce : public BtAnnounce { private: SharedHandle downloadContext_; - unsigned int trackers_; + int trackers_; Timer prevAnnounceTimer_; time_t interval_; time_t minInterval_; time_t userDefinedInterval_; - unsigned int complete_; - unsigned int incomplete_; + int complete_; + int incomplete_; AnnounceList announceList_; std::string trackerId_; const Option* option_; @@ -139,12 +139,12 @@ public: return minInterval_; } - unsigned int getComplete() const + int getComplete() const { return complete_; } - unsigned int getIncomplete() const + int getIncomplete() const { return incomplete_; } diff --git a/src/DefaultBtInteractive.h b/src/DefaultBtInteractive.h index a34569d5..2185fa7e 100644 --- a/src/DefaultBtInteractive.h +++ b/src/DefaultBtInteractive.h @@ -64,28 +64,28 @@ class UTMetadataRequestTracker; class FloodingStat { private: - unsigned int chokeUnchokeCount; - unsigned int keepAliveCount; + int chokeUnchokeCount; + int keepAliveCount; public: FloodingStat():chokeUnchokeCount(0), keepAliveCount(0) {} void incChokeUnchokeCount() { - if(chokeUnchokeCount < UINT_MAX) { + if(chokeUnchokeCount < INT_MAX) { chokeUnchokeCount++; } } void incKeepAliveCount() { - if(keepAliveCount < UINT_MAX) { + if(keepAliveCount < INT_MAX) { keepAliveCount++; } } - unsigned int getChokeUnchokeCount() const { + int getChokeUnchokeCount() const { return chokeUnchokeCount; } - unsigned int getKeepAliveCount() const { + int getKeepAliveCount() const { return keepAliveCount; } diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 4ee8e89a..4bdbe506 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -275,7 +275,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const if(lowestDownloadSpeedLimit_ > 0 && peerStat_->getDownloadStartTime().difference(global::wallclock()) >= startupIdleTime_) { - unsigned int nowSpeed = peerStat_->calculateDownloadSpeed(); + int nowSpeed = peerStat_->calculateDownloadSpeed(); if(nowSpeed <= lowestDownloadSpeedLimit_) { throw DL_ABORT_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed, diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index 85dcc8f5..8d33639f 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -50,7 +50,7 @@ class MessageDigest; class DownloadCommand : public AbstractCommand { private: time_t startupIdleTime_; - unsigned int lowestDownloadSpeedLimit_; + int lowestDownloadSpeedLimit_; SharedHandle peerStat_; bool pieceHashValidationEnabled_; @@ -99,7 +99,7 @@ public: startupIdleTime_ = startupIdleTime; } - void setLowestDownloadSpeedLimit(unsigned int lowestDownloadSpeedLimit) + void setLowestDownloadSpeedLimit(int lowestDownloadSpeedLimit) { lowestDownloadSpeedLimit_ = lowestDownloadSpeedLimit; } diff --git a/src/FeedbackURISelector.cc b/src/FeedbackURISelector.cc index e93af40c..6445e9eb 100644 --- a/src/FeedbackURISelector.cc +++ b/src/FeedbackURISelector.cc @@ -126,7 +126,7 @@ std::string FeedbackURISelector::selectFaster // Use first 10 good URIs to introduce some randomness. const size_t NUM_URI = 10; // Ignore low speed server - const unsigned int SPEED_THRESHOLD = 20*1024; + const int SPEED_THRESHOLD = 20*1024; std::vector, std::string> > fastCands; std::vector normCands; for(std::deque::const_iterator i = uris.begin(), diff --git a/src/FileEntry.cc b/src/FileEntry.cc index 1af951da..43a226aa 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -230,7 +230,7 @@ FileEntry::findFasterRequest const SharedHandle& serverStatMan) { const int startupIdleTime = 10; - const unsigned int SPEED_THRESHOLD = 20*1024; + const int SPEED_THRESHOLD = 20*1024; if(lastFasterReplace_.difference(global::wallclock()) < startupIdleTime) { return SharedHandle(); } diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 4436d7c0..2710acda 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -235,11 +235,11 @@ bool FtpConnection::sendPort(const SharedHandle& serverSocket) if(socketBuffer_.sendBufferIsEmpty()) { std::pair addrinfo; socket_->getAddrInfo(addrinfo); - unsigned int ipaddr[4]; - sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u", + int ipaddr[4]; + sscanf(addrinfo.first.c_str(), "%d.%d.%d.%d", &ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]); serverSocket->getAddrInfo(addrinfo); - std::string request = fmt("PORT %u,%u,%u,%u,%u,%u\r\n", + std::string request = fmt("PORT %d,%d,%d,%d,%d,%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3], addrinfo.second/256, addrinfo.second%256); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, @@ -280,16 +280,16 @@ bool FtpConnection::sendRetr() return socketBuffer_.sendBufferIsEmpty(); } -unsigned int FtpConnection::getStatus(const std::string& response) const +int FtpConnection::getStatus(const std::string& response) const { - unsigned int status; - // When the response is not like "%u %*s", + int status; + // When the response is not like "%d %*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(), "%u %*s", &status) == 1) { + if(sscanf(response.c_str(), "%d %*s", &status) == 1) { return status; } else { return 0; @@ -300,8 +300,8 @@ unsigned int FtpConnection::getStatus(const std::string& response) const // The length includes \r\n. // If the whole response has not been received, then returns std::string::npos. std::string::size_type -FtpConnection::findEndOfResponse(unsigned int status, - const std::string& buf) const +FtpConnection::findEndOfResponse +(int status, const std::string& buf) const { if(buf.size() <= 4) { return std::string::npos; @@ -310,7 +310,7 @@ FtpConnection::findEndOfResponse(unsigned int status, if(buf.at(3) == '-') { // multi line response std::string::size_type p; - p = buf.find(fmt("\r\n%u ", status)); + p = buf.find(fmt("\r\n%d ", status)); if(p == std::string::npos) { return std::string::npos; } @@ -331,8 +331,7 @@ FtpConnection::findEndOfResponse(unsigned int status, } } -bool FtpConnection::bulkReceiveResponse -(std::pair& response) +bool FtpConnection::bulkReceiveResponse(std::pair& response) { char buf[1024]; while(1) { @@ -352,7 +351,7 @@ bool FtpConnection::bulkReceiveResponse } strbuf_.append(&buf[0], &buf[size]); } - unsigned int status; + int status; if(strbuf_.size() >= 4) { status = getStatus(strbuf_); if(status == 0) { @@ -377,9 +376,9 @@ bool FtpConnection::bulkReceiveResponse } } -unsigned int FtpConnection::receiveResponse() +int FtpConnection::receiveResponse() { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { return response.first; } else { @@ -400,9 +399,9 @@ unsigned int FtpConnection::receiveResponse() # define ULONGLONG_SCANF "%Lu" #endif // __MINGW32__ -unsigned int FtpConnection::receiveSizeResponse(off_t& size) +int FtpConnection::receiveSizeResponse(off_t& size) { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { std::pair rp; @@ -418,10 +417,10 @@ unsigned int FtpConnection::receiveSizeResponse(off_t& size) } } -unsigned int FtpConnection::receiveMdtmResponse(Time& time) +int FtpConnection::receiveMdtmResponse(Time& time) { // MDTM command, specified in RFC3659. - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { char buf[15]; // YYYYMMDDhhmmss+\0, milli second part is dropped. @@ -448,9 +447,9 @@ unsigned int FtpConnection::receiveMdtmResponse(Time& time) } } -unsigned int FtpConnection::receiveEpsvResponse(uint16_t& port) +int FtpConnection::receiveEpsvResponse(uint16_t& port) { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 229) { port = 0; @@ -479,22 +478,22 @@ unsigned int FtpConnection::receiveEpsvResponse(uint16_t& port) } } -unsigned int FtpConnection::receivePasvResponse +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)." - unsigned int h1, h2, h3, h4, p1, p2; + int h1, h2, h3, h4, p1, p2; std::string::size_type p = response.second.find("("); if(p >= 4) { sscanf(response.second.c_str()+p, - "(%u,%u,%u,%u,%u,%u).", + "(%d,%d,%d,%d,%d,%d).", &h1, &h2, &h3, &h4, &p1, &p2); // ip address - dest.first = fmt("%u.%u.%u.%u", h1, h2, h3, h4); + dest.first = fmt("%d.%d.%d.%d", h1, h2, h3, h4); // port number dest.second = 256*p1+p2; } else { @@ -507,9 +506,9 @@ unsigned int FtpConnection::receivePasvResponse } } -unsigned int FtpConnection::receivePwdResponse(std::string& pwd) +int FtpConnection::receivePwdResponse(std::string& pwd) { - std::pair response; + std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 257) { std::string::size_type first; diff --git a/src/FtpConnection.h b/src/FtpConnection.h index 1abb9683..04010940 100644 --- a/src/FtpConnection.h +++ b/src/FtpConnection.h @@ -69,10 +69,10 @@ private: std::string baseWorkingDir_; - unsigned int getStatus(const std::string& response) const; - std::string::size_type findEndOfResponse(unsigned int status, - const std::string& buf) const; - bool bulkReceiveResponse(std::pair& response); + int getStatus(const std::string& response) const; + std::string::size_type findEndOfResponse + (int status, const std::string& buf) const; + bool bulkReceiveResponse(std::pair& response); static const std::string A; @@ -101,18 +101,18 @@ public: bool sendRest(const SharedHandle& segment); bool sendRetr(); - unsigned int receiveResponse(); - unsigned int receiveSizeResponse(off_t& size); + int receiveResponse(); + int receiveSizeResponse(off_t& size); // Returns status code of MDTM reply. If the status code is 213, parses // time-val and store it in time. // If a code other than 213 is returned, time is not touched. // Expect MDTM reply is YYYYMMDDhhmmss in GMT. If status is 213 but returned // date cannot be parsed, then assign Time::null() to given time. // If reply is not received yet, returns 0. - unsigned int receiveMdtmResponse(Time& time); - unsigned int receiveEpsvResponse(uint16_t& port); - unsigned int receivePasvResponse(std::pair& dest); - unsigned int receivePwdResponse(std::string& pwd); + int receiveMdtmResponse(Time& time); + int receiveEpsvResponse(uint16_t& port); + int receivePasvResponse(std::pair& dest); + int receivePwdResponse(std::string& pwd); void setBaseWorkingDir(const std::string& baseWorkingDir); diff --git a/src/FtpFinishDownloadCommand.cc b/src/FtpFinishDownloadCommand.cc index 208fb79f..75d5ad49 100644 --- a/src/FtpFinishDownloadCommand.cc +++ b/src/FtpFinishDownloadCommand.cc @@ -78,7 +78,7 @@ bool FtpFinishDownloadCommand::execute() try { if(readEventEnabled() || hupEventEnabled()) { getCheckPoint() = global::wallclock(); - unsigned int status = ftpConnection_->receiveResponse(); + int status = ftpConnection_->receiveResponse(); if(status == 0) { getDownloadEngine()->addCommand(this); return false; diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 6412c7ac..70e29468 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -153,7 +153,7 @@ bool FtpNegotiationCommand::recvGreeting() { disableWriteCheckSocket(); setReadCheckSocket(getSocket()); - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -176,7 +176,7 @@ bool FtpNegotiationCommand::sendUser() { } bool FtpNegotiationCommand::recvUser() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); switch(status) { case 0: return false; @@ -204,7 +204,7 @@ bool FtpNegotiationCommand::sendPass() { } bool FtpNegotiationCommand::recvPass() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -227,7 +227,7 @@ bool FtpNegotiationCommand::sendType() { } bool FtpNegotiationCommand::recvType() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -253,7 +253,7 @@ bool FtpNegotiationCommand::sendPwd() bool FtpNegotiationCommand::recvPwd() { std::string pwd; - unsigned int status = ftp_->receivePwdResponse(pwd); + int status = ftp_->receivePwdResponse(pwd); if(status == 0) { return false; } @@ -292,7 +292,7 @@ bool FtpNegotiationCommand::sendCwd() bool FtpNegotiationCommand::recvCwd() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -333,7 +333,7 @@ bool FtpNegotiationCommand::sendMdtm() bool FtpNegotiationCommand::recvMdtm() { Time lastModifiedTime = Time::null(); - unsigned int status = ftp_->receiveMdtmResponse(lastModifiedTime); + int status = ftp_->receiveMdtmResponse(lastModifiedTime); if(status == 0) { return false; } @@ -465,7 +465,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(off_t totalLength) bool FtpNegotiationCommand::recvSize() { off_t size = 0; - unsigned int status = ftp_->receiveSizeResponse(size); + int status = ftp_->receiveSizeResponse(size); if(status == 0) { return false; } @@ -546,7 +546,7 @@ bool FtpNegotiationCommand::sendEprt() { } bool FtpNegotiationCommand::recvEprt() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -569,7 +569,7 @@ bool FtpNegotiationCommand::sendPort() { } bool FtpNegotiationCommand::recvPort() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -603,7 +603,7 @@ bool FtpNegotiationCommand::sendEpsv() { bool FtpNegotiationCommand::recvEpsv() { uint16_t port; - unsigned int status = ftp_->receiveEpsvResponse(port); + int status = ftp_->receiveEpsvResponse(port); if(status == 0) { return false; } @@ -628,7 +628,7 @@ bool FtpNegotiationCommand::sendPasv() { bool FtpNegotiationCommand::recvPasv() { std::pair dest; - unsigned int status = ftp_->receivePasvResponse(dest); + int status = ftp_->receivePasvResponse(dest); if(status == 0) { return false; } @@ -781,7 +781,7 @@ bool FtpNegotiationCommand::sendRest(const SharedHandle& segment) { } bool FtpNegotiationCommand::recvRest(const SharedHandle& segment) { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } @@ -808,7 +808,7 @@ bool FtpNegotiationCommand::sendRetr() { } bool FtpNegotiationCommand::recvRetr() { - unsigned int status = ftp_->receiveResponse(); + int status = ftp_->receiveResponse(); if(status == 0) { return false; } diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index 56d96ecc..08499240 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -189,7 +189,7 @@ bool HttpSkipResponseCommand::processResponse() { int statusCode; if(httpResponse_->isRedirect()) { - unsigned int rnum = + int rnum = httpResponse_->getHttpRequest()->getRequest()->getRedirectCount(); if(rnum >= Request::MAX_REDIRECT) { throw DL_ABORT_EX2(fmt("Too many redirects: count=%u", rnum), diff --git a/src/LpdDispatchMessageCommand.h b/src/LpdDispatchMessageCommand.h index d034a815..cd53cfa0 100644 --- a/src/LpdDispatchMessageCommand.h +++ b/src/LpdDispatchMessageCommand.h @@ -48,7 +48,7 @@ class LpdDispatchMessageCommand:public Command { private: SharedHandle dispatcher_; DownloadEngine* e_; - unsigned int tryCount_; + int tryCount_; SharedHandle btRuntime_; public: LpdDispatchMessageCommand diff --git a/src/Peer.cc b/src/Peer.cc index e31ae10a..2621b929 100644 --- a/src/Peer.cc +++ b/src/Peer.cc @@ -216,13 +216,13 @@ void Peer::updateBitfield(size_t index, int operation) { updateSeeder(); } -unsigned int Peer::calculateUploadSpeed() +int Peer::calculateUploadSpeed() { assert(res_); return res_->getPeerStat().calculateUploadSpeed(); } -unsigned int Peer::calculateDownloadSpeed() +int Peer::calculateDownloadSpeed() { assert(res_); return res_->getPeerStat().calculateDownloadSpeed(); diff --git a/src/Peer.h b/src/Peer.h index 2f296603..1b94cf19 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -224,12 +224,12 @@ public: /** * Returns the transfer rate from localhost to remote host. */ - unsigned int calculateUploadSpeed(); + int calculateUploadSpeed(); /** * Returns the transfer rate from remote host to localhost. */ - unsigned int calculateDownloadSpeed(); + int calculateDownloadSpeed(); /** * Returns the number of bytes uploaded to the remote host. diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc index e8ffa170..850fb589 100644 --- a/src/PeerReceiveHandshakeCommand.cc +++ b/src/PeerReceiveHandshakeCommand.cc @@ -127,9 +127,9 @@ bool PeerReceiveHandshakeCommand::executeInternal() } TransferStat tstat = downloadContext->getOwnerRequestGroup()->calculateStat(); - const unsigned int maxDownloadLimit = + const int maxDownloadLimit = downloadContext->getOwnerRequestGroup()->getMaxDownloadSpeedLimit(); - unsigned int thresholdSpeed = + int thresholdSpeed = downloadContext->getOwnerRequestGroup()-> getOption()->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT); if(maxDownloadLimit > 0) { diff --git a/src/PeerStat.cc b/src/PeerStat.cc index 1a060a90..78e416fb 100644 --- a/src/PeerStat.cc +++ b/src/PeerStat.cc @@ -65,23 +65,23 @@ PeerStat::~PeerStat() {} /** * Returns current download speed in byte per sec. */ -unsigned int PeerStat::calculateDownloadSpeed() +int PeerStat::calculateDownloadSpeed() { return downloadSpeed_.calculateSpeed(); } -unsigned int PeerStat::calculateAvgDownloadSpeed() +int PeerStat::calculateAvgDownloadSpeed() { avgDownloadSpeed_ = downloadSpeed_.calculateAvgSpeed(); return avgDownloadSpeed_; } -unsigned int PeerStat::calculateUploadSpeed() +int PeerStat::calculateUploadSpeed() { return uploadSpeed_.calculateSpeed(); } -unsigned int PeerStat::calculateAvgUploadSpeed() +int PeerStat::calculateAvgUploadSpeed() { avgUploadSpeed_ = uploadSpeed_.calculateAvgSpeed(); return avgUploadSpeed_; @@ -99,12 +99,12 @@ void PeerStat::updateUploadLength(size_t bytes) sessionUploadLength_ += bytes; } -unsigned int PeerStat::getMaxDownloadSpeed() const +int PeerStat::getMaxDownloadSpeed() const { return downloadSpeed_.getMaxSpeed(); } -unsigned int PeerStat::getMaxUploadSpeed() const +int PeerStat::getMaxUploadSpeed() const { return uploadSpeed_.getMaxSpeed(); } diff --git a/src/PeerStat.h b/src/PeerStat.h index c328173d..f651e9f5 100644 --- a/src/PeerStat.h +++ b/src/PeerStat.h @@ -59,8 +59,8 @@ private: SpeedCalc uploadSpeed_; Timer downloadStartTime_; PeerStat::STATUS status_; - unsigned int avgDownloadSpeed_; - unsigned int avgUploadSpeed_; + int avgDownloadSpeed_; + int avgUploadSpeed_; int64_t sessionDownloadLength_; int64_t sessionUploadLength_; public: @@ -78,28 +78,28 @@ public: /** * Returns current download speed in byte per sec. */ - unsigned int calculateDownloadSpeed(); + int calculateDownloadSpeed(); - unsigned int calculateAvgDownloadSpeed(); + int calculateAvgDownloadSpeed(); - unsigned int calculateUploadSpeed(); + int calculateUploadSpeed(); - unsigned int calculateAvgUploadSpeed(); + int calculateAvgUploadSpeed(); void updateDownloadLength(size_t bytes); void updateUploadLength(size_t bytes); - unsigned int getMaxDownloadSpeed() const; + int getMaxDownloadSpeed() const; - unsigned int getMaxUploadSpeed() const; + int getMaxUploadSpeed() const; - unsigned int getAvgDownloadSpeed() const + int getAvgDownloadSpeed() const { return avgDownloadSpeed_; } - unsigned int getAvgUploadSpeed() const + int getAvgUploadSpeed() const { return avgUploadSpeed_; } diff --git a/src/Request.cc b/src/Request.cc index 5732f391..dfdfff19 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -144,7 +144,7 @@ void Request::resetRedirectCount() redirectCount_ = 0; } -void Request::setMaxPipelinedRequest(unsigned int num) +void Request::setMaxPipelinedRequest(int num) { maxPipelinedRequest_ = num; } diff --git a/src/Request.h b/src/Request.h index 36578da4..22f2ebc5 100644 --- a/src/Request.h +++ b/src/Request.h @@ -63,8 +63,8 @@ private: std::string connectedHostname_; std::string connectedAddr_; - unsigned int tryCount_; - unsigned int redirectCount_; + int tryCount_; + int redirectCount_; // whether or not the server supports persistent connection bool supportsPersistentConnection_; // enable keep-alive if possible. @@ -72,7 +72,7 @@ private: // enable pipelining if possible. bool pipeliningHint_; // maximum number of pipelined requests - unsigned int maxPipelinedRequest_; + int maxPipelinedRequest_; SharedHandle peerStat_; bool removalRequested_; uint16_t connectedPort_; @@ -91,9 +91,9 @@ public: bool resetUri(); void resetTryCount() { tryCount_ = 0; } void addTryCount() { ++tryCount_; } - unsigned int getTryCount() const { return tryCount_; } + int getTryCount() const { return tryCount_; } void resetRedirectCount(); - unsigned int getRedirectCount() const { return redirectCount_; } + int getRedirectCount() const { return redirectCount_; } // Returns URI passed by setUri() const std::string& getUri() const { return uri_; } const std::string& getCurrentUri() const { return currentUri_; } @@ -146,9 +146,9 @@ public: return pipeliningHint_; } - void setMaxPipelinedRequest(unsigned int num); + void setMaxPipelinedRequest(int num); - unsigned int getMaxPipelinedRequest() const + int getMaxPipelinedRequest() const { return maxPipelinedRequest_; } @@ -230,7 +230,7 @@ public: static const std::string PROTO_FTP; - static const unsigned int MAX_REDIRECT = 20; + static const int MAX_REDIRECT = 20; }; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index b09fb818..9d2597e3 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -788,8 +788,8 @@ bool RequestGroup::tryAutoFileRenaming() if(filepath.empty()) { return false; } - for(unsigned int i = 1; i < 10000; ++i) { - std::string newfilename = fmt("%s.%u", filepath.c_str(), i); + for(int i = 1; i < 10000; ++i) { + std::string newfilename = fmt("%s.%d", filepath.c_str(), i); File newfile(newfilename); File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix()); if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) { @@ -808,7 +808,7 @@ void RequestGroup::createNextCommandWithAdj(std::vector& commands, numCommand = 1+numAdj; } else { numCommand = std::min(downloadContext_->getNumPieces(), - numConcurrentCommand_); + static_cast(numConcurrentCommand_)); numCommand += numAdj; } if(numCommand > 0) { @@ -830,8 +830,9 @@ void RequestGroup::createNextCommand(std::vector& commands, if(numStreamCommand_ >= numConcurrentCommand_) { numCommand = 0; } else { - numCommand = std::min(downloadContext_->getNumPieces(), - numConcurrentCommand_-numStreamCommand_); + numCommand = + std::min(downloadContext_->getNumPieces(), + static_cast(numConcurrentCommand_-numStreamCommand_)); } } if(numCommand > 0) { @@ -841,9 +842,9 @@ void RequestGroup::createNextCommand(std::vector& commands, void RequestGroup::createNextCommand(std::vector& commands, DownloadEngine* e, - unsigned int numCommand) + int numCommand) { - for(; numCommand--; ) { + for(; numCommand > 0; --numCommand) { Command* command = new CreateRequestCommand(e->newCUID(), this, e); commands.push_back(command); } @@ -946,9 +947,9 @@ void RequestGroup::decreaseStreamConnection() --numStreamConnection_; } -unsigned int RequestGroup::getNumConnection() const +int RequestGroup::getNumConnection() const { - unsigned int numConnection = numStreamConnection_; + int numConnection = numStreamConnection_; #ifdef ENABLE_BITTORRENT if(btRuntime_) { numConnection += btRuntime_->getConnections(); @@ -1259,12 +1260,12 @@ void RequestGroup::updateLastModifiedTime(const Time& time) void RequestGroup::increaseAndValidateFileNotFoundCount() { ++fileNotFoundCount_; - const unsigned int maxCount = option_->getAsInt(PREF_MAX_FILE_NOT_FOUND); + const int maxCount = option_->getAsInt(PREF_MAX_FILE_NOT_FOUND); if(maxCount > 0 && fileNotFoundCount_ >= maxCount && (!segmentMan_ || segmentMan_->calculateSessionDownloadLength() == 0)) { throw DOWNLOAD_FAILURE_EXCEPTION2 - (fmt("Reached max-file-not-found count=%u", maxCount), + (fmt("Reached max-file-not-found count=%d", maxCount), error_code::MAX_FILE_NOT_FOUND); } } diff --git a/src/RequestGroup.h b/src/RequestGroup.h index b2bfb9cd..42257893 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -90,16 +90,16 @@ private: SharedHandle