mirror of https://github.com/aria2/aria2
2010-03-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Avoid to calculate end() iterator in each loop. std::deque is particularly slow. Make sure that recalculate end iterator if element is erased during loop.pull/1/head
parent
c342bde962
commit
72e475dfde
|
@ -1,3 +1,9 @@
|
|||
2010-03-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Avoid to calculate end() iterator in each loop. std::deque is
|
||||
particularly slow. Make sure that recalculate end iterator if
|
||||
element is erased during loop.
|
||||
|
||||
2010-02-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use vector instead of deque for containers which is used for
|
||||
|
|
|
@ -106,8 +106,8 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
|
|||
std::mem_fun_ref(&URIResult::getURI));
|
||||
|
||||
if(_logger->debug()) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
_logger->debug("AdaptiveURISelector: will retry server with increased"
|
||||
" timeout (%d s): %s",
|
||||
_requestGroup->getTimeout(), (*i).c_str());
|
||||
|
@ -257,8 +257,8 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
|
|||
{
|
||||
int max = -1;
|
||||
std::string uri = A2STR::NIL;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
SharedHandle<ServerStat> ss = getServerStats(*i);
|
||||
if(ss.isNull())
|
||||
continue;
|
||||
|
@ -279,8 +279,8 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
|
|||
(const std::deque<std::string>& uris, unsigned int min) const
|
||||
{
|
||||
std::deque<std::string> bests;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
SharedHandle<ServerStat> ss = getServerStats(*i);
|
||||
if(ss.isNull())
|
||||
continue;
|
||||
|
@ -304,8 +304,8 @@ std::string AdaptiveURISelector::selectRandomUri
|
|||
std::string AdaptiveURISelector::getFirstNotTestedUri
|
||||
(const std::deque<std::string>& uris) const
|
||||
{
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
SharedHandle<ServerStat> ss = getServerStats(*i);
|
||||
if(ss.isNull())
|
||||
return *i;
|
||||
|
@ -318,8 +318,8 @@ std::string AdaptiveURISelector::getFirstToTestUri
|
|||
{
|
||||
unsigned int counter;
|
||||
int power;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
SharedHandle<ServerStat> ss = getServerStats(*i);
|
||||
if(ss.isNull())
|
||||
continue;
|
||||
|
@ -348,8 +348,8 @@ unsigned int AdaptiveURISelector::getNbTestedServers
|
|||
(const std::deque<std::string>& uris) const
|
||||
{
|
||||
unsigned int counter = 0;
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
SharedHandle<ServerStat> ss = getServerStats(*i);
|
||||
if(ss.isNull())
|
||||
++counter;
|
||||
|
|
|
@ -63,15 +63,15 @@ AnnounceList::AnnounceList
|
|||
void AnnounceList::reconfigure(const BDE& announceList)
|
||||
{
|
||||
if(announceList.isList()) {
|
||||
for(BDE::List::const_iterator itr = announceList.listBegin();
|
||||
itr != announceList.listEnd(); ++itr) {
|
||||
for(BDE::List::const_iterator itr = announceList.listBegin(),
|
||||
eoi = announceList.listEnd(); itr != eoi; ++itr) {
|
||||
const BDE& elemList = *itr;
|
||||
if(!elemList.isList()) {
|
||||
continue;
|
||||
}
|
||||
std::deque<std::string> urls;
|
||||
for(BDE::List::const_iterator elemItr = elemList.listBegin();
|
||||
elemItr != elemList.listEnd(); ++elemItr) {
|
||||
for(BDE::List::const_iterator elemItr = elemList.listBegin(),
|
||||
eoi2 = elemList.listEnd(); elemItr != eoi2; ++elemItr) {
|
||||
const BDE& data = *elemItr;
|
||||
if(data.isString()) {
|
||||
urls.push_back(data.s());
|
||||
|
@ -242,8 +242,8 @@ void AnnounceList::moveToCompletedAllowedTier() {
|
|||
}
|
||||
|
||||
void AnnounceList::shuffle() {
|
||||
for(std::deque<SharedHandle<AnnounceTier> >::iterator itr = tiers.begin();
|
||||
itr != tiers.end(); ++itr) {
|
||||
for(std::deque<SharedHandle<AnnounceTier> >::const_iterator itr =
|
||||
tiers.begin(), eoi = tiers.end(); itr != eoi; ++itr) {
|
||||
std::deque<std::string>& urls = (*itr)->urls;
|
||||
std::random_shuffle(urls.begin(), urls.end(),
|
||||
*(SimpleRandomizer::getInstance().get()));
|
||||
|
|
|
@ -109,17 +109,19 @@ bool BtDependency::resolve()
|
|||
// Copy file path in _dependant's FileEntries to newly created
|
||||
// context's FileEntries to endorse the path structure of
|
||||
// _dependant. URIs and singleHostMultiConnection are also copied.
|
||||
std::vector<SharedHandle<FileEntry> >::const_iterator ctxFilesEnd =
|
||||
fileEntries.end();
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
|
||||
dependantFileEntries.begin(); s != dependantFileEntries.end();
|
||||
++s){
|
||||
dependantFileEntries.begin(), eoi = dependantFileEntries.end();
|
||||
s != eoi; ++s){
|
||||
std::vector<SharedHandle<FileEntry> >::const_iterator d =
|
||||
context->getFileEntries().begin();
|
||||
for(; d != context->getFileEntries().end(); ++d) {
|
||||
fileEntries.begin();
|
||||
for(; d != ctxFilesEnd; ++d) {
|
||||
if((*d)->getOriginalName() == (*s)->getOriginalName()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(d == context->getFileEntries().end()) {
|
||||
if(d == ctxFilesEnd) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat("No entry %s in torrent file",
|
||||
(*s)->getOriginalName().c_str()).str());
|
||||
|
|
|
@ -165,8 +165,8 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|||
if(fastOptUnchoker) {
|
||||
std::random_shuffle(peerIter, peerEntries.end(),
|
||||
*(SimpleRandomizer::getInstance().get()));
|
||||
for(std::vector<PeerEntry>::iterator i = peerIter; i != peerEntries.end();
|
||||
++i) {
|
||||
for(std::vector<PeerEntry>::iterator i = peerIter,
|
||||
eoi = peerEntries.end(); i != eoi; ++i) {
|
||||
if((*i).getPeer()->peerInterested()) {
|
||||
(*i).enableOptUnchoking();
|
||||
_logger->info("OU: %s", (*i).getPeer()->ipaddr.c_str());
|
||||
|
|
|
@ -54,8 +54,8 @@ SharedHandle<DownloadContext>
|
|||
BtRegistry::getDownloadContext(const std::string& infoHash) const
|
||||
{
|
||||
SharedHandle<DownloadContext> dctx;
|
||||
for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin();
|
||||
i != _pool.end(); ++i) {
|
||||
for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin(),
|
||||
eoi = _pool.end(); i != eoi; ++i) {
|
||||
const BDE& attrs =
|
||||
(*i).second._downloadContext->getAttribute(bittorrent::BITTORRENT);
|
||||
if(attrs[bittorrent::INFO_HASH].s() == infoHash) {
|
||||
|
|
|
@ -101,8 +101,8 @@ public:
|
|||
template<typename OutputIterator>
|
||||
OutputIterator getAllDownloadContext(OutputIterator dest)
|
||||
{
|
||||
for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin();
|
||||
i != _pool.end(); ++i) {
|
||||
for(std::map<int32_t, BtObject>::const_iterator i = _pool.begin(),
|
||||
eoi = _pool.end(); i != eoi; ++i) {
|
||||
*dest++ = (*i).second._downloadContext;
|
||||
}
|
||||
return dest;
|
||||
|
|
|
@ -90,7 +90,8 @@ void BtSeederStateChoke::unchoke
|
|||
std::sort(peers.begin(), peers.end());
|
||||
|
||||
std::vector<PeerEntry>::iterator r = peers.begin();
|
||||
for(; r != peers.end() && count; ++r, --count) {
|
||||
for(std::vector<PeerEntry>::iterator eoi = peers.end();
|
||||
r != eoi && count; ++r, --count) {
|
||||
(*r).getPeer()->chokingRequired(false);
|
||||
_logger->info("RU: %s, ulspd=%u", (*r).getPeer()->ipaddr.c_str(),
|
||||
(*r).getUploadSpeed());
|
||||
|
|
|
@ -190,7 +190,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
std::vector<std::pair<sockaddr_storage, socklen_t> > ifAddrs;
|
||||
getInterfaceAddress(ifAddrs, lpdInterface, AF_INET, AI_NUMERICHOST);
|
||||
for(std::vector<std::pair<sockaddr_storage, socklen_t> >::const_iterator
|
||||
i = ifAddrs.begin(); i != ifAddrs.end(); ++i) {
|
||||
i = ifAddrs.begin(), eoi = ifAddrs.end(); i != eoi; ++i) {
|
||||
sockaddr_in addr;
|
||||
memcpy(&addr, &(*i).first, (*i).second);
|
||||
if(receiver->init(inet_ntoa(addr.sin_addr))) {
|
||||
|
|
|
@ -66,8 +66,8 @@ Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defa
|
|||
util::split(nameValue, terms.front(), '=');
|
||||
|
||||
std::map<std::string, std::string> values;
|
||||
for(std::vector<std::string>::iterator itr = terms.begin()+1;
|
||||
itr != terms.end(); ++itr) {
|
||||
for(std::vector<std::string>::iterator itr = terms.begin()+1,
|
||||
eoi = terms.end(); itr != eoi; ++itr) {
|
||||
std::pair<std::string, std::string> nv;
|
||||
util::split(nv, *itr, '=');
|
||||
values[nv.first] = nv.second;
|
||||
|
|
|
@ -98,8 +98,8 @@ bool CookieStorage::DomainEntry::contains(const Cookie& cookie) const
|
|||
|
||||
void CookieStorage::DomainEntry::writeCookie(std::ostream& o) const
|
||||
{
|
||||
for(std::deque<Cookie>::const_iterator i = _cookies.begin();
|
||||
i != _cookies.end(); ++i) {
|
||||
for(std::deque<Cookie>::const_iterator i = _cookies.begin(),
|
||||
eoi = _cookies.end(); i != eoi; ++i) {
|
||||
o << (*i).toNsCookieFormat() << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,8 @@ std::vector<Cookie> CookieStorage::criteriaFind(const std::string& requestHost,
|
|||
std::string domain = A2STR::DOT_C;
|
||||
domain += domainComponents[0];
|
||||
for(std::vector<std::string>::const_iterator di =
|
||||
domainComponents.begin()+1; di != domainComponents.end(); ++di) {
|
||||
domainComponents.begin()+1, eoi = domainComponents.end();
|
||||
di != eoi; ++di) {
|
||||
domain = strconcat(A2STR::DOT_C, *di, domain);
|
||||
searchCookieByDomainSuffix(domain, _domains.begin(), _domains.end(),
|
||||
std::back_inserter(res),
|
||||
|
@ -275,8 +276,8 @@ std::vector<Cookie> CookieStorage::criteriaFind(const std::string& requestHost,
|
|||
size_t CookieStorage::size() const
|
||||
{
|
||||
size_t numCookie = 0;
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin();
|
||||
i != _domains.end(); ++i) {
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin(),
|
||||
eoi = _domains.end(); i != eoi; ++i) {
|
||||
numCookie += (*i).countCookie();
|
||||
}
|
||||
return numCookie;
|
||||
|
@ -327,8 +328,8 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
|
|||
filename.c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin();
|
||||
i != _domains.end(); ++i) {
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin(),
|
||||
eoi = _domains.end(); i != eoi; ++i) {
|
||||
(*i).writeCookie(o);
|
||||
}
|
||||
o.flush();
|
||||
|
|
|
@ -173,8 +173,8 @@ public:
|
|||
template<typename OutputIterator>
|
||||
OutputIterator dumpCookie(OutputIterator out) const
|
||||
{
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin();
|
||||
i != _domains.end(); ++i) {
|
||||
for(std::deque<DomainEntry>::const_iterator i = _domains.begin(),
|
||||
eoi = _domains.end(); i != eoi; ++i) {
|
||||
out = (*i).dumpCookie(out);
|
||||
}
|
||||
return out;
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "DHTAbstractNodeLookupTask.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include "DHTRoutingTable.h"
|
||||
#include "DHTMessageDispatcher.h"
|
||||
#include "DHTMessageFactory.h"
|
||||
|
@ -44,8 +48,6 @@
|
|||
#include "Logger.h"
|
||||
#include "util.h"
|
||||
#include "DHTIDCloser.h"
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -66,7 +68,7 @@ void DHTAbstractNodeLookupTask::onReceived(const SharedHandle<DHTMessage>& messa
|
|||
|
||||
size_t count = 0;
|
||||
for(std::vector<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
|
||||
newEntries.begin(); i != newEntries.end(); ++i) {
|
||||
newEntries.begin(), eoi = newEntries.end(); i != eoi; ++i) {
|
||||
if(memcmp(_localNode->getID(), (*i)->_node->getID(), DHT_ID_LENGTH) != 0) {
|
||||
_entries.push_front(*i);
|
||||
++count;
|
||||
|
@ -98,7 +100,8 @@ void DHTAbstractNodeLookupTask::onTimeout(const SharedHandle<DHTNode>& node)
|
|||
util::toHex(node->getID(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
--_inFlightMessage;
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i = _entries.begin(); i != _entries.end(); ++i) {
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
||||
if((*i)->_node == node) {
|
||||
_entries.erase(i);
|
||||
break;
|
||||
|
@ -132,8 +135,8 @@ void DHTAbstractNodeLookupTask::sendMessageAndCheckFinish()
|
|||
void DHTAbstractNodeLookupTask::sendMessage()
|
||||
{
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
|
||||
_entries.begin();
|
||||
i != _entries.end() && _inFlightMessage < ALPHA; ++i) {
|
||||
_entries.begin(), eoi = _entries.end();
|
||||
i != eoi && _inFlightMessage < ALPHA; ++i) {
|
||||
if((*i)->_used == false) {
|
||||
++_inFlightMessage;
|
||||
(*i)->_used = true;
|
||||
|
|
|
@ -61,8 +61,8 @@ protected:
|
|||
void toEntries
|
||||
(Container& entries, const std::vector<SharedHandle<DHTNode> >& nodes) const
|
||||
{
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i = nodes.begin();
|
||||
i != nodes.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i = nodes.begin(),
|
||||
eoi = nodes.end(); i != eoi; ++i) {
|
||||
SharedHandle<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
|
||||
entries.push_back(e);
|
||||
}
|
||||
|
|
|
@ -101,8 +101,8 @@ void DHTAutoSaveCommand::save()
|
|||
std::vector<SharedHandle<DHTNode> > nodes;
|
||||
std::vector<SharedHandle<DHTBucket> > buckets;
|
||||
_routingTable->getBuckets(buckets);
|
||||
for(std::vector<SharedHandle<DHTBucket> >::const_iterator i = buckets.begin();
|
||||
i != buckets.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DHTBucket> >::const_iterator i = buckets.begin(),
|
||||
eoi = buckets.end(); i != eoi; ++i) {
|
||||
const SharedHandle<DHTBucket>& bucket = *i;
|
||||
std::vector<SharedHandle<DHTNode> > goodNodes;
|
||||
bucket->getGoodNodes(goodNodes);
|
||||
|
|
|
@ -107,7 +107,8 @@ bool DHTBucket::isInRange(const unsigned char* nodeID,
|
|||
bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
|
||||
{
|
||||
notifyUpdate();
|
||||
std::deque<SharedHandle<DHTNode> >::iterator itr = std::find(_nodes.begin(), _nodes.end(), node);
|
||||
std::deque<SharedHandle<DHTNode> >::iterator itr =
|
||||
std::find(_nodes.begin(), _nodes.end(), node);
|
||||
if(itr == _nodes.end()) {
|
||||
if(_nodes.size() < K) {
|
||||
_nodes.push_back(node);
|
||||
|
@ -140,7 +141,8 @@ void DHTBucket::cacheNode(const SharedHandle<DHTNode>& node)
|
|||
void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
|
||||
{
|
||||
if(_cachedNodes.size()) {
|
||||
std::deque<SharedHandle<DHTNode> >::iterator itr = find(_nodes.begin(), _nodes.end(), node);
|
||||
std::deque<SharedHandle<DHTNode> >::iterator itr =
|
||||
find(_nodes.begin(), _nodes.end(), node);
|
||||
if(itr != _nodes.end()) {
|
||||
_nodes.erase(itr);
|
||||
_nodes.push_back(_cachedNodes.front());
|
||||
|
@ -191,8 +193,8 @@ SharedHandle<DHTBucket> DHTBucket::split()
|
|||
rMax, rMin, _localNode));
|
||||
|
||||
std::deque<SharedHandle<DHTNode> > lNodes;
|
||||
for(std::deque<SharedHandle<DHTNode> >::iterator i = _nodes.begin();
|
||||
i != _nodes.end(); ++i) {
|
||||
for(std::deque<SharedHandle<DHTNode> >::iterator i = _nodes.begin(),
|
||||
eoi = _nodes.end(); i != eoi; ++i) {
|
||||
if(rBucket->isInRange(*i)) {
|
||||
assert(rBucket->addNode(*i));
|
||||
} else {
|
||||
|
|
|
@ -53,8 +53,8 @@ void DHTBucketRefreshTask::startup()
|
|||
{
|
||||
std::vector<SharedHandle<DHTBucket> > buckets;
|
||||
_routingTable->getBuckets(buckets);
|
||||
for(std::vector<SharedHandle<DHTBucket> >::iterator i = buckets.begin();
|
||||
i != buckets.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DHTBucket> >::iterator i = buckets.begin(),
|
||||
eoi = buckets.end(); i != eoi; ++i) {
|
||||
if(_forceRefresh || (*i)->needsRefresh()) {
|
||||
(*i)->notifyUpdate();
|
||||
unsigned char targetID[DHT_ID_LENGTH];
|
||||
|
|
|
@ -57,8 +57,8 @@ bool DHTConnectionImpl::bind(uint16_t& port, IntSequence& ports)
|
|||
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||
*SimpleRandomizer::getInstance().get());
|
||||
|
||||
for(std::vector<int32_t>::const_iterator portItr = randPorts.begin();
|
||||
portItr != randPorts.end(); ++portItr) {
|
||||
for(std::vector<int32_t>::const_iterator portItr = randPorts.begin(),
|
||||
eoi = randPorts.end(); portItr != eoi; ++portItr) {
|
||||
if(!(0 < (*portItr) && (*portItr) <= 65535)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ DHTFindNodeReplyMessage::~DHTFindNodeReplyMessage() {}
|
|||
|
||||
void DHTFindNodeReplyMessage::doReceivedAction()
|
||||
{
|
||||
for(std::vector<SharedHandle<DHTNode> >::iterator i = _closestKNodes.begin();
|
||||
i != _closestKNodes.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DHTNode> >::iterator i = _closestKNodes.begin(),
|
||||
eoi = _closestKNodes.end(); i != eoi; ++i) {
|
||||
if(memcmp((*i)->getID(), _localNode->getID(), DHT_ID_LENGTH) != 0) {
|
||||
_routingTable->addNode(*i);
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ BDE DHTFindNodeReplyMessage::getResponse()
|
|||
unsigned char buffer[DHTBucket::K*26];
|
||||
// TODO if _closestKNodes.size() > DHTBucket::K ??
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
|
||||
_closestKNodes.begin();
|
||||
i != _closestKNodes.end() && offset < DHTBucket::K*26; ++i) {
|
||||
_closestKNodes.begin(), eoi = _closestKNodes.end();
|
||||
i != eoi && offset < DHTBucket::K*26; ++i) {
|
||||
SharedHandle<DHTNode> node = *i;
|
||||
memcpy(buffer+offset, node->getID(), DHT_ID_LENGTH);
|
||||
if(bittorrent::createcompact(buffer+20+offset, node->getIPAddress(),
|
||||
|
|
|
@ -82,8 +82,8 @@ BDE DHTGetPeersReplyMessage::getResponse()
|
|||
size_t offset = 0;
|
||||
unsigned char buffer[DHTBucket::K*26];
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
|
||||
_closestKNodes.begin();
|
||||
i != _closestKNodes.end() && offset < DHTBucket::K*26; ++i) {
|
||||
_closestKNodes.begin(), eoi = _closestKNodes.end();
|
||||
i != eoi && offset < DHTBucket::K*26; ++i) {
|
||||
SharedHandle<DHTNode> node = *i;
|
||||
memcpy(buffer+offset, node->getID(), DHT_ID_LENGTH);
|
||||
if(bittorrent::createcompact
|
||||
|
@ -114,8 +114,9 @@ BDE DHTGetPeersReplyMessage::getResponse()
|
|||
// number of peer info that a message can carry.
|
||||
static const size_t MAX_VALUES_SIZE = 100;
|
||||
BDE valuesList = BDE::list();
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator i = _values.begin();
|
||||
i != _values.end() && valuesList.size() < MAX_VALUES_SIZE; ++i) {
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator i = _values.begin(),
|
||||
eoi = _values.end(); i != eoi && valuesList.size() < MAX_VALUES_SIZE;
|
||||
++i) {
|
||||
const SharedHandle<Peer>& peer = *i;
|
||||
unsigned char buffer[6];
|
||||
if(bittorrent::createcompact(buffer, peer->ipaddr, peer->port)) {
|
||||
|
|
|
@ -416,8 +416,8 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
|
|||
const BDE& valuesList = getList(rDict,
|
||||
DHTGetPeersReplyMessage::VALUES);
|
||||
std::vector<SharedHandle<Peer> > peers;
|
||||
for(BDE::List::const_iterator i = valuesList.listBegin();
|
||||
i != valuesList.listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = valuesList.listBegin(),
|
||||
eoi = valuesList.listEnd(); i != eoi; ++i) {
|
||||
const BDE& data = *i;
|
||||
if(data.isString() && data.s().size() == 6) {
|
||||
std::pair<std::string, uint16_t> addr =
|
||||
|
|
|
@ -82,7 +82,7 @@ DHTMessageTracker::messageArrived(const BDE& dict,
|
|||
util::toHex(tid.s()).c_str(), ipaddr.c_str(), port);
|
||||
}
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
||||
_entries.begin(); i != _entries.end(); ++i) {
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
||||
if((*i)->match(tid.s(), ipaddr, port)) {
|
||||
SharedHandle<DHTMessageTrackerEntry> entry = *i;
|
||||
_entries.erase(i);
|
||||
|
@ -113,12 +113,13 @@ DHTMessageTracker::messageArrived(const BDE& dict,
|
|||
|
||||
void DHTMessageTracker::handleTimeout()
|
||||
{
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i = _entries.begin();
|
||||
i != _entries.end();) {
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi;) {
|
||||
if((*i)->isTimeout()) {
|
||||
try {
|
||||
SharedHandle<DHTMessageTrackerEntry> entry = *i;
|
||||
i = _entries.erase(i);
|
||||
eoi = _entries.end();
|
||||
SharedHandle<DHTNode> node = entry->getTargetNode();
|
||||
if(_logger->debug()) {
|
||||
_logger->debug("Message timeout: To:%s:%u",
|
||||
|
@ -149,9 +150,11 @@ void DHTMessageTracker::handleTimeout()
|
|||
SharedHandle<DHTMessageTrackerEntry>
|
||||
DHTMessageTracker::getEntryFor(const SharedHandle<DHTMessage>& message) const
|
||||
{
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::const_iterator i = _entries.begin();
|
||||
i != _entries.end(); ++i) {
|
||||
if((*i)->match(message->getTransactionID(), message->getRemoteNode()->getIPAddress(), message->getRemoteNode()->getPort())) {
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::const_iterator i =
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
||||
if((*i)->match(message->getTransactionID(),
|
||||
message->getRemoteNode()->getIPAddress(),
|
||||
message->getRemoteNode()->getPort())) {
|
||||
return *i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ bool DHTPeerAnnounceEntry::empty() const
|
|||
void DHTPeerAnnounceEntry::getPeers
|
||||
(std::vector<SharedHandle<Peer> >& peers) const
|
||||
{
|
||||
for(std::vector<PeerAddrEntry>::const_iterator i = _peerAddrEntries.begin();
|
||||
i != _peerAddrEntries.end(); ++i) {
|
||||
for(std::vector<PeerAddrEntry>::const_iterator i = _peerAddrEntries.begin(),
|
||||
eoi = _peerAddrEntries.end(); i != eoi; ++i) {
|
||||
SharedHandle<Peer> peer(new Peer((*i).getIPAddress(), (*i).getPort()));
|
||||
peers.push_back(peer);
|
||||
}
|
||||
|
|
|
@ -145,10 +145,12 @@ void DHTPeerAnnounceStorage::announcePeer()
|
|||
if(_logger->debug()) {
|
||||
_logger->debug("Now announcing peer.");
|
||||
}
|
||||
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i = _entries.begin(); i != _entries.end(); ++i) {
|
||||
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi; ++i) {
|
||||
if((*i)->getLastUpdated().elapsed(DHT_PEER_ANNOUNCE_INTERVAL)) {
|
||||
(*i)->notifyUpdate();
|
||||
SharedHandle<DHTTask> task = _taskFactory->createPeerAnnounceTask((*i)->getInfoHash());
|
||||
SharedHandle<DHTTask> task =
|
||||
_taskFactory->createPeerAnnounceTask((*i)->getInfoHash());
|
||||
_taskQueue->addPeriodicTask2(task);
|
||||
if(_logger->debug()) {
|
||||
_logger->debug("Added 1 peer announce: infoHash=%s",
|
||||
|
|
|
@ -89,8 +89,9 @@ void DHTPeerLookupTask::onFinish()
|
|||
{
|
||||
// send announce_peer message to K closest nodes
|
||||
size_t num = DHTBucket::K;
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i = _entries.begin();
|
||||
i != _entries.end() && num > 0; ++i, --num) {
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
|
||||
_entries.begin(), eoi = _entries.end(); i != eoi && num > 0; ++i,
|
||||
--num) {
|
||||
if((*i)->_used) {
|
||||
const SharedHandle<DHTNode>& node = (*i)->_node;
|
||||
SharedHandle<DHTMessage> m =
|
||||
|
|
|
@ -101,8 +101,8 @@ void DHTRoutingTableSerializer::serialize(std::ostream& o)
|
|||
o.write(zero, 4);
|
||||
|
||||
// nodes
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i = _nodes.begin();
|
||||
i != _nodes.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i = _nodes.begin(),
|
||||
eoi = _nodes.end(); i != eoi; ++i) {
|
||||
const SharedHandle<DHTNode>& node = *i;
|
||||
// Currently, only IPv4 address and IPv4-mapped address are saved.
|
||||
// 6bytes: write IP address + port in Compact IP-address/port info form.
|
||||
|
|
|
@ -182,7 +182,7 @@ void DHTSetup::setup(std::vector<Command*>& commands,
|
|||
const std::vector<SharedHandle<DHTNode> >& desnodes =
|
||||
deserializer.getNodes();
|
||||
for(std::vector<SharedHandle<DHTNode> >::const_iterator i =
|
||||
desnodes.begin(); i != desnodes.end(); ++i) {
|
||||
desnodes.begin(), eoi = desnodes.end(); i != eoi; ++i) {
|
||||
routingTable->addNode(*i);
|
||||
}
|
||||
if(!desnodes.empty() && deserializer.getSerializedTime().elapsed(DHT_BUCKET_REFRESH_INTERVAL)) {
|
||||
|
|
|
@ -71,8 +71,8 @@ private:
|
|||
|
||||
std::vector<AddrEntry>::iterator find(const std::string& addr)
|
||||
{
|
||||
for(std::vector<AddrEntry>::iterator i = _addrEntries.begin();
|
||||
i != _addrEntries.end(); ++i) {
|
||||
for(std::vector<AddrEntry>::iterator i = _addrEntries.begin(),
|
||||
eoi = _addrEntries.end(); i != eoi; ++i) {
|
||||
if((*i)._addr == addr) {
|
||||
return i;
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ private:
|
|||
|
||||
std::vector<AddrEntry>::const_iterator find(const std::string& addr) const
|
||||
{
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin();
|
||||
i != _addrEntries.end(); ++i) {
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin(),
|
||||
eoi = _addrEntries.end(); i != eoi; ++i) {
|
||||
if((*i)._addr == addr) {
|
||||
return i;
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ private:
|
|||
|
||||
const std::string& getGoodAddr() const
|
||||
{
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin();
|
||||
i != _addrEntries.end(); ++i) {
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin(),
|
||||
eoi = _addrEntries.end(); i != eoi; ++i) {
|
||||
if((*i)._good) {
|
||||
return (*i)._addr;
|
||||
}
|
||||
|
@ -110,8 +110,8 @@ private:
|
|||
template<typename OutputIterator>
|
||||
void getAllGoodAddrs(OutputIterator out) const
|
||||
{
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin();
|
||||
i != _addrEntries.end(); ++i) {
|
||||
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin(),
|
||||
eoi = _addrEntries.end(); i != eoi; ++i) {
|
||||
if((*i)._good) {
|
||||
*out++ = (*i)._addr;
|
||||
}
|
||||
|
|
|
@ -206,8 +206,8 @@ void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
|||
_downloadContext->getNumPieces(),
|
||||
bittorrent::getInfoHash(_downloadContext),
|
||||
allowedFastSetSize);
|
||||
for(std::vector<size_t>::const_iterator itr = fastSet.begin();
|
||||
itr != fastSet.end(); ++itr) {
|
||||
for(std::vector<size_t>::const_iterator itr = fastSet.begin(),
|
||||
eoi = fastSet.end(); itr != eoi; ++itr) {
|
||||
dispatcher->addMessageToQueue
|
||||
(messageFactory->createAllowedFastMessage(*itr));
|
||||
}
|
||||
|
@ -237,8 +237,8 @@ void DefaultBtInteractive::checkHave() {
|
|||
dispatcher->addMessageToQueue(messageFactory->createBitfieldMessage());
|
||||
}
|
||||
} else {
|
||||
for(std::vector<size_t>::iterator itr = indexes.begin();
|
||||
itr != indexes.end(); ++itr) {
|
||||
for(std::vector<size_t>::const_iterator itr = indexes.begin(),
|
||||
eoi = indexes.end(); itr != eoi; ++itr) {
|
||||
dispatcher->addMessageToQueue(messageFactory->createHaveMessage(*itr));
|
||||
}
|
||||
}
|
||||
|
@ -380,8 +380,8 @@ void DefaultBtInteractive::cancelAllPiece() {
|
|||
if(_metadataGetMode && _downloadContext->getTotalLength() > 0) {
|
||||
std::vector<size_t> metadataRequests =
|
||||
_utMetadataRequestTracker->getAllTrackedIndex();
|
||||
for(std::vector<size_t>::const_iterator i = metadataRequests.begin();
|
||||
i != metadataRequests.end(); ++i) {
|
||||
for(std::vector<size_t>::const_iterator i = metadataRequests.begin(),
|
||||
eoi = metadataRequests.end(); i != eoi; ++i) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("Cancel metadata: piece=%lu",
|
||||
static_cast<unsigned long>(*i));
|
||||
|
@ -441,7 +441,8 @@ void DefaultBtInteractive::addPeerExchangeMessage()
|
|||
const std::deque<SharedHandle<Peer> >& peers = _peerStorage->getPeers();
|
||||
{
|
||||
for(std::deque<SharedHandle<Peer> >::const_iterator i =
|
||||
peers.begin(); i != peers.end() && !m->freshPeersAreFull(); ++i) {
|
||||
peers.begin(), eoi = peers.end();
|
||||
i != eoi && !m->freshPeersAreFull(); ++i) {
|
||||
if(peer->ipaddr != (*i)->ipaddr) {
|
||||
m->addFreshPeer(*i);
|
||||
}
|
||||
|
@ -449,7 +450,8 @@ void DefaultBtInteractive::addPeerExchangeMessage()
|
|||
}
|
||||
{
|
||||
for(std::deque<SharedHandle<Peer> >::const_reverse_iterator i =
|
||||
peers.rbegin(); i != peers.rend() && !m->droppedPeersAreFull();
|
||||
peers.rbegin(), eoi = peers.rend();
|
||||
i != eoi && !m->droppedPeersAreFull();
|
||||
++i) {
|
||||
if(peer->ipaddr != (*i)->ipaddr) {
|
||||
m->addDroppedPeer(*i);
|
||||
|
@ -485,8 +487,8 @@ void DefaultBtInteractive::doInteractionProcessing() {
|
|||
// to other connection to request piece.
|
||||
std::vector<size_t> indexes =
|
||||
_utMetadataRequestTracker->removeTimeoutEntry();
|
||||
for(std::vector<size_t>::const_iterator i = indexes.begin();
|
||||
i != indexes.end(); ++i) {
|
||||
for(std::vector<size_t>::const_iterator i = indexes.begin(),
|
||||
eoi = indexes.end(); i != eoi; ++i) {
|
||||
_pieceStorage->cancelPiece(_pieceStorage->getPiece(*i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ void DefaultBtMessageDispatcher::addMessageToQueue
|
|||
(const std::vector<SharedHandle<BtMessage> >& btMessages)
|
||||
{
|
||||
for(std::vector<SharedHandle<BtMessage> >::const_iterator itr =
|
||||
btMessages.begin(); itr != btMessages.end(); ++itr) {
|
||||
btMessages.begin(), eoi = btMessages.end(); itr != eoi; ++itr) {
|
||||
addMessageToQueue(*itr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,8 +182,8 @@ void DefaultBtProgressInfoFile::save()
|
|||
std::vector<SharedHandle<Piece> > inFlightPieces;
|
||||
_pieceStorage->getInFlightPieces(inFlightPieces);
|
||||
for(std::vector<SharedHandle<Piece> >::const_iterator itr =
|
||||
inFlightPieces.begin();
|
||||
itr != inFlightPieces.end(); ++itr) {
|
||||
inFlightPieces.begin(), eoi = inFlightPieces.end();
|
||||
itr != eoi; ++itr) {
|
||||
uint32_t indexNL = htonl((*itr)->getIndex());
|
||||
o.write(reinterpret_cast<const char*>(&indexNL), sizeof(indexNL));
|
||||
uint32_t lengthNL = htonl((*itr)->getLength());
|
||||
|
|
|
@ -142,8 +142,8 @@ void DefaultBtRequestFactory::doChokedAction()
|
|||
}
|
||||
|
||||
void DefaultBtRequestFactory::removeAllTargetPiece() {
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin();
|
||||
itr != pieces.end(); ++itr) {
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin(),
|
||||
eoi = pieces.end(); itr != eoi; ++itr) {
|
||||
dispatcher->doAbortOutstandingRequestAction(*itr);
|
||||
_pieceStorage->cancelPiece(*itr);
|
||||
}
|
||||
|
@ -159,13 +159,13 @@ void DefaultBtRequestFactory::createRequestMessages
|
|||
size_t getnum = max-requests.size();
|
||||
std::vector<size_t> blockIndexes;
|
||||
blockIndexes.reserve(getnum);
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin();
|
||||
itr != pieces.end() && getnum; ++itr) {
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin(),
|
||||
eoi = pieces.end(); itr != eoi && getnum; ++itr) {
|
||||
SharedHandle<Piece>& piece = *itr;
|
||||
if(piece->getMissingUnusedBlockIndex(blockIndexes, getnum)) {
|
||||
getnum -= blockIndexes.size();
|
||||
for(std::vector<size_t>::const_iterator i = blockIndexes.begin();
|
||||
i != blockIndexes.end(); ++i) {
|
||||
for(std::vector<size_t>::const_iterator i = blockIndexes.begin(),
|
||||
eoi2 = blockIndexes.end(); i != eoi2; ++i) {
|
||||
if(_logger->debug()) {
|
||||
_logger->debug("Creating RequestMessage index=%u, begin=%u,"
|
||||
" blockIndex=%u",
|
||||
|
@ -184,8 +184,8 @@ void DefaultBtRequestFactory::createRequestMessages
|
|||
void DefaultBtRequestFactory::createRequestMessagesOnEndGame
|
||||
(std::vector<SharedHandle<BtMessage> >& requests, size_t max)
|
||||
{
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin();
|
||||
itr != pieces.end() && requests.size() < max; ++itr) {
|
||||
for(std::deque<SharedHandle<Piece> >::iterator itr = pieces.begin(),
|
||||
eoi = pieces.end(); itr != eoi && requests.size() < max; ++itr) {
|
||||
SharedHandle<Piece>& piece = *itr;
|
||||
const size_t mislen = piece->getBitfieldLength();
|
||||
array_ptr<unsigned char> misbitfield(new unsigned char[mislen]);
|
||||
|
@ -205,8 +205,9 @@ void DefaultBtRequestFactory::createRequestMessagesOnEndGame
|
|||
}
|
||||
std::random_shuffle(missingBlockIndexes.begin(), missingBlockIndexes.end(),
|
||||
*(SimpleRandomizer::getInstance().get()));
|
||||
for(std::vector<size_t>::const_iterator bitr = missingBlockIndexes.begin();
|
||||
bitr != missingBlockIndexes.end() && requests.size() < max; bitr++) {
|
||||
for(std::vector<size_t>::const_iterator bitr = missingBlockIndexes.begin(),
|
||||
eoi2 = missingBlockIndexes.end();
|
||||
bitr != eoi2 && requests.size() < max; ++bitr) {
|
||||
const size_t& blockIndex = *bitr;
|
||||
if(!dispatcher->isOutstandingRequest(piece->getIndex(),
|
||||
blockIndex)) {
|
||||
|
|
|
@ -112,8 +112,8 @@ bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer) {
|
|||
|
||||
void DefaultPeerStorage::addPeer(const std::vector<SharedHandle<Peer> >& peers)
|
||||
{
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin();
|
||||
itr != peers.end(); ++itr) {
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin(),
|
||||
eoi = peers.end(); itr != eoi; ++itr) {
|
||||
const SharedHandle<Peer>& peer = *itr;
|
||||
if(addPeer(peer)) {
|
||||
if(logger->debug()) {
|
||||
|
@ -224,7 +224,7 @@ TransferStat DefaultPeerStorage::calculateStat()
|
|||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator i =
|
||||
activePeers.begin(); i != activePeers.end(); ++i) {
|
||||
activePeers.begin(), eoi = activePeers.end(); i != eoi; ++i) {
|
||||
TransferStat s;
|
||||
s.downloadSpeed = (*i)->calculateDownloadSpeed(now);
|
||||
s.uploadSpeed = (*i)->calculateUploadSpeed(now);
|
||||
|
@ -267,8 +267,8 @@ TransferStat DefaultPeerStorage::getTransferStatFor
|
|||
|
||||
void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
|
||||
std::deque<SharedHandle<Peer> > temp;
|
||||
for(std::deque<SharedHandle<Peer> >::reverse_iterator itr = peers.rbegin();
|
||||
itr != peers.rend(); ++itr) {
|
||||
for(std::deque<SharedHandle<Peer> >::const_reverse_iterator itr =
|
||||
peers.rbegin(), eoi = peers.rend(); itr != eoi; ++itr) {
|
||||
const SharedHandle<Peer>& p = *itr;
|
||||
if(p->unused() && delSize > 0) {
|
||||
onErasingPeer(p);
|
||||
|
|
|
@ -206,8 +206,8 @@ void DefaultPieceStorage::createFastIndexBitfield
|
|||
(BitfieldMan& bitfield, const SharedHandle<Peer>& peer)
|
||||
{
|
||||
for(std::vector<size_t>::const_iterator itr =
|
||||
peer->getPeerAllowedIndexSet().begin();
|
||||
itr != peer->getPeerAllowedIndexSet().end(); ++itr) {
|
||||
peer->getPeerAllowedIndexSet().begin(),
|
||||
eoi = peer->getPeerAllowedIndexSet().end(); itr != eoi; ++itr) {
|
||||
if(!bitfieldMan->isBitSet(*itr) && peer->hasPiece(*itr)) {
|
||||
bitfield.setBit(*itr);
|
||||
}
|
||||
|
@ -429,7 +429,8 @@ void DefaultPieceStorage::setupFileFilter()
|
|||
downloadContext->getFileEntries();
|
||||
bool allSelected = true;
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
fileEntries.begin(), eoi = fileEntries.end();
|
||||
i != eoi; ++i) {
|
||||
if(!(*i)->isRequested()) {
|
||||
allSelected = false;
|
||||
break;
|
||||
|
@ -439,7 +440,7 @@ void DefaultPieceStorage::setupFileFilter()
|
|||
return;
|
||||
}
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||
if((*i)->isRequested()) {
|
||||
bitfieldMan->addFilter((*i)->getOffset(), (*i)->getLength());
|
||||
}
|
||||
|
@ -544,8 +545,8 @@ DefaultPieceStorage::getAdvertisedPieceIndexes(std::vector<size_t>& indexes,
|
|||
int32_t myCuid,
|
||||
const Time& lastCheckTime)
|
||||
{
|
||||
for(std::deque<HaveEntry>::const_iterator itr = haves.begin();
|
||||
itr != haves.end(); ++itr) {
|
||||
for(std::deque<HaveEntry>::const_iterator itr = haves.begin(),
|
||||
eoi = haves.end(); itr != eoi; ++itr) {
|
||||
const HaveEntry& have = *itr;
|
||||
if(have.getCuid() == myCuid) {
|
||||
continue;
|
||||
|
|
|
@ -129,7 +129,8 @@ void DownloadContext::setFileFilter(IntSequence seq)
|
|||
|
||||
int32_t index = 1;
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
_fileEntries.begin(); i != _fileEntries.end(); ++i, ++index) {
|
||||
_fileEntries.begin(), eoi = _fileEntries.end();
|
||||
i != eoi; ++i, ++index) {
|
||||
(*i)->setRequested
|
||||
(selectAll ||
|
||||
std::binary_search(fileIndexes.begin(), fileIndexes.end(), index));
|
||||
|
@ -171,7 +172,7 @@ bool DownloadContext::hasAttribute(const std::string& key) const
|
|||
void DownloadContext::releaseRuntimeResource()
|
||||
{
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
_fileEntries.begin(); i != _fileEntries.end(); ++i) {
|
||||
_fileEntries.begin(), eoi = _fileEntries.end(); i != eoi; ++i) {
|
||||
(*i)->releaseRuntimeResource();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ void DownloadEngine::poolSocket(const std::string& ipaddr,
|
|||
}
|
||||
_lastSocketPoolScan.reset();
|
||||
for(std::multimap<std::string, SocketPoolEntry>::iterator i =
|
||||
_socketPool.begin(); i != _socketPool.end(); ++i) {
|
||||
_socketPool.begin(), eoi = _socketPool.end(); i != eoi; ++i) {
|
||||
if(!(*i).second.isTimeout()) {
|
||||
newPool.insert(*i);
|
||||
}
|
||||
|
@ -357,8 +357,8 @@ DownloadEngine::findSocketPoolEntry(const std::string& ipaddr, uint16_t port)
|
|||
std::pair<std::multimap<std::string, SocketPoolEntry>::iterator,
|
||||
std::multimap<std::string, SocketPoolEntry>::iterator> range =
|
||||
_socketPool.equal_range(addr);
|
||||
for(std::multimap<std::string, SocketPoolEntry>::iterator i = range.first;
|
||||
i != range.second; ++i) {
|
||||
for(std::multimap<std::string, SocketPoolEntry>::iterator i =
|
||||
range.first, eoi = range.second; i != eoi; ++i) {
|
||||
const SocketPoolEntry& e = (*i).second;
|
||||
if(!e.isTimeout()) {
|
||||
logger->info("Found socket for %s", addr.c_str());
|
||||
|
@ -401,8 +401,8 @@ DownloadEngine::popPooledSocket
|
|||
(const std::vector<std::string>& ipaddrs, uint16_t port)
|
||||
{
|
||||
SharedHandle<SocketCore> s;
|
||||
for(std::vector<std::string>::const_iterator i = ipaddrs.begin();
|
||||
i != ipaddrs.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
|
||||
eoi = ipaddrs.end(); i != eoi; ++i) {
|
||||
s = popPooledSocket(*i, port);
|
||||
if(!s.isNull()) {
|
||||
break;
|
||||
|
@ -417,8 +417,8 @@ DownloadEngine::popPooledSocket
|
|||
const std::vector<std::string>& ipaddrs, uint16_t port)
|
||||
{
|
||||
SharedHandle<SocketCore> s;
|
||||
for(std::vector<std::string>::const_iterator i = ipaddrs.begin();
|
||||
i != ipaddrs.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = ipaddrs.begin(),
|
||||
eoi = ipaddrs.end(); i != eoi; ++i) {
|
||||
s = popPooledSocket(options, *i, port);
|
||||
if(!s.isNull()) {
|
||||
break;
|
||||
|
|
|
@ -347,7 +347,8 @@ void EpollEventPoll::poll(const struct timeval& tv)
|
|||
// their API. So we call ares_process_fd for all ares_channel and
|
||||
// re-register their sockets.
|
||||
for(std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator i =
|
||||
_nameResolverEntries.begin(); i != _nameResolverEntries.end(); ++i) {
|
||||
_nameResolverEntries.begin(), eoi = _nameResolverEntries.end();
|
||||
i != eoi; ++i) {
|
||||
(*i)->processTimeout();
|
||||
(*i)->removeSocketEvents(this);
|
||||
(*i)->addSocketEvents(this);
|
||||
|
|
|
@ -72,8 +72,8 @@ public:
|
|||
|
||||
const std::string& getExtensionName(uint8_t id) const
|
||||
{
|
||||
for(Extensions::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
for(Extensions::const_iterator itr = _extensions.begin(),
|
||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||
const Extensions::value_type& p = *itr;
|
||||
if(p.second == id) {
|
||||
return p.first;
|
||||
|
|
|
@ -151,8 +151,8 @@ bool FeatureConfig::isSupported(const std::string& feature) const
|
|||
std::string FeatureConfig::featureSummary() const
|
||||
{
|
||||
std::string s;
|
||||
for(FeatureMap::const_iterator i = _features.begin();
|
||||
i != _features.end(); ++i) {
|
||||
for(FeatureMap::const_iterator i = _features.begin(), eoi = _features.end();
|
||||
i != eoi; ++i) {
|
||||
if((*i).second) {
|
||||
s += (*i).first;
|
||||
s += ", ";
|
||||
|
|
|
@ -73,8 +73,8 @@ std::string FeedbackURISelector::select(FileEntry* fileEntry)
|
|||
size_t max = std::min(uris.size(), static_cast<size_t>(NUM_URI));
|
||||
std::deque<std::string>::iterator urisLast = uris.begin()+max;
|
||||
std::deque<std::pair<SharedHandle<ServerStat>, std::string> > cands;
|
||||
for(std::deque<std::string>::iterator i = uris.begin();
|
||||
i != urisLast; ++i) {
|
||||
for(std::deque<std::string>::iterator i = uris.begin(), eoi = urisLast;
|
||||
i != eoi; ++i) {
|
||||
Request r;
|
||||
r.setUrl(*i);
|
||||
SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(),
|
||||
|
@ -84,8 +84,8 @@ std::string FeedbackURISelector::select(FileEntry* fileEntry)
|
|||
}
|
||||
}
|
||||
if(cands.empty()) {
|
||||
for(std::deque<std::string>::iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::deque<std::string>::iterator i = uris.begin(), eoi = uris.end();
|
||||
i != eoi; ++i) {
|
||||
Request r;
|
||||
r.setUrl(*i);
|
||||
SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(),
|
||||
|
|
|
@ -115,8 +115,8 @@ bool File::mkdirs() {
|
|||
if(util::startsWith(name, A2STR::SLASH_C)) {
|
||||
accDir = A2STR::SLASH_C;
|
||||
}
|
||||
for(std::vector<std::string>::const_iterator itr = dirs.begin();
|
||||
itr != dirs.end(); ++itr, accDir += A2STR::SLASH_C) {
|
||||
for(std::vector<std::string>::const_iterator itr = dirs.begin(),
|
||||
eoi = dirs.end(); itr != eoi; ++itr, accDir += A2STR::SLASH_C) {
|
||||
accDir += *itr;
|
||||
if(File(accDir).isDir()) {
|
||||
continue;
|
||||
|
|
|
@ -223,7 +223,8 @@ void FileEntry::poolRequest(const SharedHandle<Request>& request)
|
|||
bool FileEntry::removeRequest(const SharedHandle<Request>& request)
|
||||
{
|
||||
for(std::deque<SharedHandle<Request> >::iterator i =
|
||||
_inFlightRequests.begin(); i != _inFlightRequests.end(); ++i) {
|
||||
_inFlightRequests.begin(), eoi = _inFlightRequests.end();
|
||||
i != eoi; ++i) {
|
||||
if((*i).get() == request.get()) {
|
||||
_inFlightRequests.erase(i);
|
||||
return true;
|
||||
|
@ -236,7 +237,8 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
|||
{
|
||||
std::deque<std::string> newURIs;
|
||||
Request req;
|
||||
for(std::deque<std::string>::const_iterator itr = _uris.begin(); itr != _uris.end(); ++itr) {
|
||||
for(std::deque<std::string>::const_iterator itr = _uris.begin(),
|
||||
eoi = _uris.end(); itr != eoi; ++itr) {
|
||||
if(((*itr).find(hostname) == std::string::npos) ||
|
||||
(req.setUrl(*itr) && (req.getHost() != hostname))) {
|
||||
newURIs.push_back(*itr);
|
||||
|
|
|
@ -72,8 +72,8 @@ public:
|
|||
std::vector<SharedHandle<T> > getAll()
|
||||
{
|
||||
std::vector<SharedHandle<T> > l;
|
||||
for(typename HandleMap::const_iterator itr = handleMap.begin();
|
||||
itr != handleMap.end(); ++itr) {
|
||||
for(typename HandleMap::const_iterator itr = handleMap.begin(),
|
||||
eoi = handleMap.end(); itr != eoi; ++itr) {
|
||||
const typename HandleMap::value_type& p = *itr;
|
||||
l.push_back(p.second);
|
||||
}
|
||||
|
|
|
@ -67,8 +67,8 @@ std::string HandshakeExtensionMessage::getPayload()
|
|||
dict["p"] = _tcpPort;
|
||||
}
|
||||
BDE extDict = BDE::dict();
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin(),
|
||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
||||
extDict[vt.first] = vt.second;
|
||||
}
|
||||
|
@ -91,8 +91,8 @@ std::string HandshakeExtensionMessage::toString() const
|
|||
if(_metadataSize) {
|
||||
strappend(s, ", metadataSize=", util::uitos(_metadataSize));
|
||||
}
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin(),
|
||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
||||
strappend(s, ", ", vt.first, "=", util::uitos(vt.second));
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ void HandshakeExtensionMessage::doReceivedAction()
|
|||
_peer->port = _tcpPort;
|
||||
_peer->setIncomingPeer(false);
|
||||
}
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin(),
|
||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||
const std::map<std::string, uint8_t>::value_type& vt = *itr;
|
||||
_peer->setExtension(vt.first, vt.second);
|
||||
}
|
||||
|
@ -182,8 +182,8 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
|
|||
}
|
||||
const BDE& extDict = dict["m"];
|
||||
if(extDict.isDict()) {
|
||||
for(BDE::Dict::const_iterator i = extDict.dictBegin();
|
||||
i != extDict.dictEnd(); ++i) {
|
||||
for(BDE::Dict::const_iterator i = extDict.dictBegin(),
|
||||
eoi = extDict.dictEnd(); i != eoi; ++i) {
|
||||
if((*i).second.isInteger()) {
|
||||
msg->_extensions[(*i).first] = (*i).second.i();
|
||||
}
|
||||
|
|
|
@ -152,8 +152,8 @@ SharedHandle<HttpResponse> HttpConnection::receiveResponse()
|
|||
|
||||
bool HttpConnection::isIssued(const SharedHandle<Segment>& segment) const
|
||||
{
|
||||
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests.begin();
|
||||
itr != outstandingHttpRequests.end(); ++itr) {
|
||||
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests.begin(),
|
||||
eoi = outstandingHttpRequests.end(); itr != eoi; ++itr) {
|
||||
SharedHandle<HttpRequest> httpRequest = (*itr)->getHttpRequest();
|
||||
if(httpRequest->getSegment() == segment) {
|
||||
return true;
|
||||
|
|
|
@ -96,7 +96,8 @@ bool HttpHeader::defined(const std::string& name) const {
|
|||
}
|
||||
|
||||
const std::string& HttpHeader::getFirst(const std::string& name) const {
|
||||
std::multimap<std::string, std::string>::const_iterator itr = table.find(util::toLower(name));
|
||||
std::multimap<std::string, std::string>::const_iterator itr =
|
||||
table.find(util::toLower(name));
|
||||
if(itr == table.end()) {
|
||||
return A2STR::NIL;
|
||||
} else {
|
||||
|
|
|
@ -162,7 +162,7 @@ std::string HttpRequest::createRequest()
|
|||
builtinHds.push_back(std::make_pair("User-Agent:", userAgent));
|
||||
std::string acceptTypes = "*/*";
|
||||
for(std::vector<std::string>::const_iterator i = _acceptTypes.begin(),
|
||||
end = _acceptTypes.end(); i != end; ++i) {
|
||||
eoi = _acceptTypes.end(); i != eoi; ++i) {
|
||||
strappend(acceptTypes, ",", (*i));
|
||||
}
|
||||
builtinHds.push_back(std::make_pair("Accept:", acceptTypes));
|
||||
|
@ -223,15 +223,15 @@ std::string HttpRequest::createRequest()
|
|||
getProtocol() == Request::PROTO_HTTPS ?
|
||||
true : false);
|
||||
for(std::vector<Cookie>::const_iterator itr = cookies.begin(),
|
||||
end = cookies.end(); itr != end; ++itr) {
|
||||
eoi = cookies.end(); itr != eoi; ++itr) {
|
||||
strappend(cookiesValue, (*itr).toString(), ";");
|
||||
}
|
||||
if(!cookiesValue.empty()) {
|
||||
builtinHds.push_back(std::make_pair("Cookie:", cookiesValue));
|
||||
}
|
||||
}
|
||||
for(std::vector<std::pair<std::string, std::string> >::iterator i =
|
||||
builtinHds.begin(); i != builtinHds.end(); ++i) {
|
||||
for(std::vector<std::pair<std::string, std::string> >::const_iterator i =
|
||||
builtinHds.begin(), eoi = builtinHds.end(); i != eoi; ++i) {
|
||||
std::vector<std::string>::const_iterator j = _headers.begin();
|
||||
std::vector<std::string>::const_iterator jend = _headers.end();
|
||||
for(; j != jend; ++j) {
|
||||
|
@ -245,7 +245,7 @@ std::string HttpRequest::createRequest()
|
|||
}
|
||||
// append additional headers given by user.
|
||||
for(std::vector<std::string>::const_iterator i = _headers.begin(),
|
||||
end = _headers.end(); i != end; ++i) {
|
||||
eoi = _headers.end(); i != eoi; ++i) {
|
||||
strappend(requestLine, (*i), A2STR::CRLF);
|
||||
}
|
||||
requestLine += A2STR::CRLF;
|
||||
|
|
|
@ -134,8 +134,8 @@ bool HttpRequestCommand::executeInternal() {
|
|||
_proxyRequest));
|
||||
_httpConnection->sendRequest(httpRequest);
|
||||
} else {
|
||||
for(std::vector<SharedHandle<Segment> >::iterator itr = _segments.begin();
|
||||
itr != _segments.end(); ++itr) {
|
||||
for(std::vector<SharedHandle<Segment> >::const_iterator itr =
|
||||
_segments.begin(), eoi = _segments.end(); itr != eoi; ++itr) {
|
||||
const SharedHandle<Segment>& segment = *itr;
|
||||
if(!_httpConnection->isIssued(segment)) {
|
||||
SharedHandle<HttpRequest> httpRequest
|
||||
|
|
|
@ -114,8 +114,8 @@ std::string HttpResponse::determinFilename() const
|
|||
void HttpResponse::retrieveCookie()
|
||||
{
|
||||
std::vector<std::string> v = httpHeader->get(HttpHeader::SET_COOKIE);
|
||||
for(std::vector<std::string>::const_iterator itr = v.begin(); itr != v.end();
|
||||
++itr) {
|
||||
for(std::vector<std::string>::const_iterator itr = v.begin(), eoi = v.end();
|
||||
itr != eoi; ++itr) {
|
||||
httpRequest->getCookieStorage()->parseAndStore(*itr,
|
||||
httpRequest->getHost(),
|
||||
httpRequest->getDir());
|
||||
|
|
|
@ -107,8 +107,8 @@ bool InitiateConnectionCommand::executeInternal() {
|
|||
logger->info(MSG_NAME_RESOLUTION_COMPLETE, cuid,
|
||||
hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||
for(std::vector<std::string>::const_iterator i = addrs.begin();
|
||||
i != addrs.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = addrs.begin(),
|
||||
eoi = addrs.end(); i != eoi; ++i) {
|
||||
e->cacheIPAddress(hostname, *i, port);
|
||||
}
|
||||
ipaddr = e->findCachedIPAddress(hostname, port);
|
||||
|
|
|
@ -465,7 +465,8 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
|
|||
unsigned char* rbufptr = _rbuf;
|
||||
SharedHandle<DownloadContext> downloadContext;
|
||||
for(std::vector<SharedHandle<DownloadContext> >::const_iterator i =
|
||||
downloadContexts.begin(); i != downloadContexts.end(); ++i) {
|
||||
downloadContexts.begin(), eoi = downloadContexts.end();
|
||||
i != eoi; ++i) {
|
||||
unsigned char md[20];
|
||||
const BDE& torrentAttrs = (*i)->getAttribute(bittorrent::BITTORRENT);
|
||||
createReq23Hash(md, torrentAttrs[bittorrent::INFO_HASH].uc());
|
||||
|
|
|
@ -128,8 +128,9 @@ namespace {
|
|||
void removeMetalinkContentTypes(const SharedHandle<RequestGroup>& group)
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator i =
|
||||
DownloadHandlerConstants::getMetalinkContentTypes().begin();
|
||||
i != DownloadHandlerConstants::getMetalinkContentTypes().end(); ++i) {
|
||||
DownloadHandlerConstants::getMetalinkContentTypes().begin(),
|
||||
eoi = DownloadHandlerConstants::getMetalinkContentTypes().end();
|
||||
i != eoi; ++i) {
|
||||
group->removeAcceptType(*i);
|
||||
}
|
||||
}
|
||||
|
@ -148,9 +149,6 @@ Metalink2RequestGroup::createRequestGroup
|
|||
std::vector<int32_t> selectIndexes =
|
||||
util::parseIntRange(option->get(PREF_SELECT_FILE)).flush();
|
||||
std::sort(selectIndexes.begin(), selectIndexes.end());
|
||||
std::vector<SharedHandle<MetalinkEntry> > selectedEntries;
|
||||
selectedEntries.reserve(entries.size());
|
||||
|
||||
std::vector<std::string> locations;
|
||||
if(option->defined(PREF_METALINK_LOCATION)) {
|
||||
util::split(option->get(PREF_METALINK_LOCATION),
|
||||
|
@ -162,10 +160,12 @@ Metalink2RequestGroup::createRequestGroup
|
|||
if(option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
|
||||
preferredProtocol = option->get(PREF_METALINK_PREFERRED_PROTOCOL);
|
||||
}
|
||||
std::vector<SharedHandle<MetalinkEntry> > selectedEntries;
|
||||
selectedEntries.reserve(entries.size());
|
||||
{
|
||||
int32_t count = 1;
|
||||
for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
|
||||
entries.begin(); i != entries.end(); ++i, ++count) {
|
||||
entries.begin(), eoi = entries.end(); i != eoi; ++i, ++count) {
|
||||
(*i)->dropUnsupportedResource();
|
||||
if((*i)->resources.empty() && (*i)->metaurls.empty()) {
|
||||
continue;
|
||||
|
@ -189,7 +189,7 @@ Metalink2RequestGroup::createRequestGroup
|
|||
MetalinkHelper::groupEntryByMetaurlName(entryGroups, selectedEntries);
|
||||
for(std::vector<std::pair<std::string,
|
||||
std::vector<SharedHandle<MetalinkEntry> > > >::const_iterator itr =
|
||||
entryGroups.begin(); itr != entryGroups.end(); ++itr) {
|
||||
entryGroups.begin(), eoi = entryGroups.end(); itr != eoi; ++itr) {
|
||||
const std::string& metaurl = (*itr).first;
|
||||
const std::vector<SharedHandle<MetalinkEntry> >& mes = (*itr).second;
|
||||
_logger->info("Processing metaurl group metaurl=%s", metaurl.c_str());
|
||||
|
@ -279,7 +279,7 @@ Metalink2RequestGroup::createRequestGroup
|
|||
std::vector<SharedHandle<FileEntry> > fileEntries;
|
||||
off_t offset = 0;
|
||||
for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
|
||||
mes.begin(); i != mes.end(); ++i) {
|
||||
mes.begin(), eoi = mes.end(); i != eoi; ++i) {
|
||||
_logger->info("Metalink: Queueing %s for download as a member.",
|
||||
(*i)->getPath().c_str());
|
||||
_logger->debug("originalName = %s", (*i)->metaurls[0]->name.c_str());
|
||||
|
|
|
@ -86,7 +86,7 @@ void MetalinkHelper::groupEntryByMetaurlName
|
|||
const std::vector<SharedHandle<MetalinkEntry> >& entries)
|
||||
{
|
||||
for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator eiter =
|
||||
entries.begin(); eiter != entries.end(); ++eiter) {
|
||||
entries.begin(), eoi = entries.end(); eiter != eoi; ++eiter) {
|
||||
if((*eiter)->metaurls.empty()) {
|
||||
std::pair<std::string, std::vector<SharedHandle<MetalinkEntry> > > p;
|
||||
p.second.push_back(*eiter);
|
||||
|
|
|
@ -167,7 +167,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
}
|
||||
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||
diskWriterEntries.push_back
|
||||
(createDiskWriterEntry(*i, (*i)->isRequested()));
|
||||
}
|
||||
|
@ -176,10 +176,11 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
|
||||
// TODO Currently, pieceLength == 0 is used for unit testing only.
|
||||
if(pieceLength > 0) {
|
||||
std::vector<SharedHandle<DiskWriterEntry> >::iterator done =
|
||||
std::vector<SharedHandle<DiskWriterEntry> >::const_iterator done =
|
||||
diskWriterEntries.begin();
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator itr =
|
||||
diskWriterEntries.begin(); itr != diskWriterEntries.end();) {
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator itr =
|
||||
diskWriterEntries.begin(), eoi = diskWriterEntries.end();
|
||||
itr != eoi;) {
|
||||
const SharedHandle<FileEntry>& fileEntry = (*itr)->getFileEntry();
|
||||
|
||||
if(!fileEntry->isRequested()) {
|
||||
|
@ -189,7 +190,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
off_t pieceStartOffset =
|
||||
(fileEntry->getOffset()/pieceLength)*pieceLength;
|
||||
if(itr != diskWriterEntries.begin()) {
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||
itr-1; true; --i) {
|
||||
const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
|
||||
if(pieceStartOffset <= fileEntry->getOffset() ||
|
||||
|
@ -217,7 +218,7 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
++itr;
|
||||
// adjacent backward files are not needed to be allocated. They
|
||||
// just requre DiskWriter
|
||||
for(; itr != diskWriterEntries.end() &&
|
||||
for(; itr != eoi &&
|
||||
(!(*itr)->getFileEntry()->isRequested() ||
|
||||
(*itr)->getFileEntry()->getLength() == 0); ++itr) {
|
||||
if(logger->debug()) {
|
||||
|
@ -244,8 +245,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
}
|
||||
}
|
||||
DefaultDiskWriterFactory dwFactory;
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||
diskWriterEntries.begin(), eoi = diskWriterEntries.end();
|
||||
i != eoi; ++i) {
|
||||
if((*i)->needsFileAllocation() ||
|
||||
dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
|
||||
(*i)->fileExists()) {
|
||||
|
@ -267,7 +269,8 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
|
|||
void MultiDiskAdaptor::mkdir() const
|
||||
{
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||
diskWriterEntries.begin(), eoi = diskWriterEntries.end();
|
||||
i != eoi; ++i) {
|
||||
(*i)->getFileEntry()->setupDir();
|
||||
}
|
||||
}
|
||||
|
@ -305,8 +308,8 @@ void MultiDiskAdaptor::openFile()
|
|||
mkdir();
|
||||
// Call DiskWriterEntry::openFile to make sure that zero-length files are
|
||||
// created.
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end(); ++itr) {
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(),
|
||||
eoi = diskWriterEntries.end(); itr != eoi; ++itr) {
|
||||
openIfNot(*itr, &DiskWriterEntry::openFile);
|
||||
}
|
||||
}
|
||||
|
@ -316,8 +319,8 @@ void MultiDiskAdaptor::initAndOpenFile()
|
|||
resetDiskWriterEntries();
|
||||
mkdir();
|
||||
// Call DiskWriterEntry::initAndOpenFile to make files truncated.
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end(); ++itr) {
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(),
|
||||
eoi = diskWriterEntries.end(); itr != eoi; ++itr) {
|
||||
openIfNot(*itr, &DiskWriterEntry::initAndOpenFile);
|
||||
}
|
||||
}
|
||||
|
@ -330,8 +333,8 @@ void MultiDiskAdaptor::openExistingFile()
|
|||
|
||||
void MultiDiskAdaptor::closeFile()
|
||||
{
|
||||
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end(); ++itr) {
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(),
|
||||
eoi = diskWriterEntries.end(); itr != eoi; ++itr) {
|
||||
(*itr)->closeFile();
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +399,8 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
|||
|
||||
size_t rem = len;
|
||||
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
||||
for(DiskWriterEntries::const_iterator i = first; i != diskWriterEntries.end(); ++i) {
|
||||
for(DiskWriterEntries::const_iterator i = first,
|
||||
eoi = diskWriterEntries.end(); i != eoi; ++i) {
|
||||
size_t writeLength = calculateLength(*i, fileOffset, rem);
|
||||
|
||||
openIfNot(*i, &DiskWriterEntry::openFile);
|
||||
|
@ -416,12 +420,14 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
|||
|
||||
ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset)
|
||||
{
|
||||
DiskWriterEntries::const_iterator first = findFirstDiskWriterEntry(diskWriterEntries, offset);
|
||||
DiskWriterEntries::const_iterator first =
|
||||
findFirstDiskWriterEntry(diskWriterEntries, offset);
|
||||
|
||||
size_t rem = len;
|
||||
size_t totalReadLength = 0;
|
||||
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
||||
for(DiskWriterEntries::const_iterator i = first; i != diskWriterEntries.end(); ++i) {
|
||||
for(DiskWriterEntries::const_iterator i = first,
|
||||
eoi = diskWriterEntries.end(); i != eoi; ++i) {
|
||||
size_t readLength = calculateLength(*i, fileOffset, rem);
|
||||
|
||||
openIfNot(*i, &DiskWriterEntry::openFile);
|
||||
|
@ -443,8 +449,8 @@ ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset
|
|||
|
||||
bool MultiDiskAdaptor::fileExists()
|
||||
{
|
||||
for(std::vector<SharedHandle<FileEntry> >::iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||
if((*i)->exists()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -455,8 +461,8 @@ bool MultiDiskAdaptor::fileExists()
|
|||
uint64_t MultiDiskAdaptor::size()
|
||||
{
|
||||
uint64_t size = 0;
|
||||
for(std::vector<SharedHandle<FileEntry> >::iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||
size += File((*i)->getPath()).size();
|
||||
}
|
||||
return size;
|
||||
|
@ -469,16 +475,16 @@ FileAllocationIteratorHandle MultiDiskAdaptor::fileAllocationIterator()
|
|||
|
||||
void MultiDiskAdaptor::enableDirectIO()
|
||||
{
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end(); ++itr) {
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(),
|
||||
eoi = diskWriterEntries.end(); itr != eoi; ++itr) {
|
||||
(*itr)->enableDirectIO();
|
||||
}
|
||||
}
|
||||
|
||||
void MultiDiskAdaptor::disableDirectIO()
|
||||
{
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin();
|
||||
itr != diskWriterEntries.end(); ++itr) {
|
||||
for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(),
|
||||
eoi = diskWriterEntries.end(); itr != eoi; ++itr) {
|
||||
(*itr)->disableDirectIO();
|
||||
}
|
||||
}
|
||||
|
@ -496,7 +502,8 @@ void MultiDiskAdaptor::disableReadOnly()
|
|||
void MultiDiskAdaptor::cutTrailingGarbage()
|
||||
{
|
||||
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
||||
diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
|
||||
diskWriterEntries.begin(), eoi = diskWriterEntries.end();
|
||||
i != eoi; ++i) {
|
||||
uint64_t length = (*i)->getFileEntry()->getLength();
|
||||
if(File((*i)->getFilePath()).size() > length) {
|
||||
// We need open file before calling DiskWriter::truncate(uint64_t)
|
||||
|
@ -515,7 +522,7 @@ size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
|
|||
{
|
||||
size_t numOK = 0;
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries.begin(); i != fileEntries.end(); ++i) {
|
||||
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||
if((*i)->isRequested()) {
|
||||
File f((*i)->getPath());
|
||||
if(f.isFile() && f.utime(actime, modtime)) {
|
||||
|
|
|
@ -93,8 +93,8 @@ void Netrc::parse(const std::string& path)
|
|||
}
|
||||
std::vector<std::string> tokens;
|
||||
util::split(line, std::back_inserter(tokens), " \t", true);
|
||||
for(std::vector<std::string>::const_iterator iter = tokens.begin();
|
||||
iter != tokens.end(); ++iter) {
|
||||
for(std::vector<std::string>::const_iterator iter = tokens.begin(),
|
||||
eoi = tokens.end(); iter != eoi; ++iter) {
|
||||
const std::string& token = *iter;
|
||||
if(state == GET_TOKEN) {
|
||||
if(token == Netrc::MACHINE) {
|
||||
|
|
|
@ -480,8 +480,8 @@ public:
|
|||
msg += "''";
|
||||
} else {
|
||||
for(std::vector<std::string>::const_iterator itr =
|
||||
_validParamValues.begin();
|
||||
itr != _validParamValues.end(); ++itr) {
|
||||
_validParamValues.begin(), eoi = _validParamValues.end();
|
||||
itr != eoi; ++itr) {
|
||||
strappend(msg, "'", *itr, "' ");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,8 +209,9 @@ void OptionParser::setOptionHandlers
|
|||
(const std::vector<SharedHandle<OptionHandler> >& optionHandlers)
|
||||
{
|
||||
_optionHandlers = optionHandlers;
|
||||
for(std::vector<SharedHandle<OptionHandler> >::iterator i =
|
||||
_optionHandlers.begin(); i != _optionHandlers.end(); ++i) {
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
_optionHandlers.begin(), eoi = _optionHandlers.end();
|
||||
i != eoi; ++i) {
|
||||
(*i)->setOptionID(++_idCounter);
|
||||
}
|
||||
std::sort(_optionHandlers.begin(), _optionHandlers.end(),
|
||||
|
@ -230,7 +231,8 @@ void OptionParser::addOptionHandler
|
|||
void OptionParser::parseDefaultValues(Option& option) const
|
||||
{
|
||||
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
|
||||
_optionHandlers.begin(); i != _optionHandlers.end(); ++i) {
|
||||
_optionHandlers.begin(), eoi = _optionHandlers.end();
|
||||
i != eoi; ++i) {
|
||||
if(!(*i)->getDefaultValue().empty()) {
|
||||
(*i)->parse(option, (*i)->getDefaultValue());
|
||||
}
|
||||
|
|
|
@ -75,8 +75,8 @@ void PStringBuildVisitor::visit(PStringNumLoop& s)
|
|||
void PStringBuildVisitor::visit(PStringSelect& s)
|
||||
{
|
||||
const std::vector<std::string>& values = s.getValues();
|
||||
for(std::vector<std::string>::const_iterator i = values.begin();
|
||||
i != values.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = values.begin(),
|
||||
eoi = values.end(); i != eoi; ++i) {
|
||||
PStringSegment(*i, s.getNext()).accept(*this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ public:
|
|||
template<typename OutputIterator>
|
||||
void extractPeerFromList(const BDE& peerData, OutputIterator dest)
|
||||
{
|
||||
for(BDE::List::const_iterator itr = peerData.listBegin();
|
||||
itr != peerData.listEnd(); ++itr) {
|
||||
for(BDE::List::const_iterator itr = peerData.listBegin(),
|
||||
eoi = peerData.listEnd(); itr != eoi; ++itr) {
|
||||
const BDE& peerDict = *itr;
|
||||
if(!peerDict.isDict()) {
|
||||
continue;
|
||||
|
|
|
@ -75,8 +75,8 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
|||
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||
*SimpleRandomizer::getInstance().get());
|
||||
|
||||
for(std::vector<int32_t>::const_iterator portItr = randPorts.begin();
|
||||
portItr != randPorts.end(); ++portItr) {
|
||||
for(std::vector<int32_t>::const_iterator portItr = randPorts.begin(),
|
||||
eoi = randPorts.end(); portItr != eoi; ++portItr) {
|
||||
if(!(0 < (*portItr) && (*portItr) <= 65535)) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -213,8 +213,8 @@ PeerSessionResource::getExtensionMessageID(const std::string& name) const
|
|||
|
||||
std::string PeerSessionResource::getExtensionName(uint8_t id) const
|
||||
{
|
||||
for(Extensions::const_iterator itr = _extensions.begin();
|
||||
itr != _extensions.end(); ++itr) {
|
||||
for(Extensions::const_iterator itr = _extensions.begin(),
|
||||
eoi = _extensions.end(); itr != eoi; ++itr) {
|
||||
const Extensions::value_type& p = *itr;
|
||||
if(p.second == id) {
|
||||
return p.first;
|
||||
|
|
|
@ -176,8 +176,8 @@ size_t Piece::getMissingUnusedBlockIndex
|
|||
{
|
||||
size_t num = bitfield->getFirstNMissingUnusedIndex(indexes, n);
|
||||
if(num) {
|
||||
for(std::vector<size_t>::const_iterator i = indexes.end()-num;
|
||||
i != indexes.end(); ++i) {
|
||||
for(std::vector<size_t>::const_iterator i = indexes.end()-num,
|
||||
eoi = indexes.end(); i != eoi; ++i) {
|
||||
bitfield->setUseBit(*i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,9 @@ PieceStatMan::PieceStatMan(size_t pieceNum, bool randomShuffle):
|
|||
}
|
||||
{
|
||||
size_t order = 0;
|
||||
for(std::vector<SharedHandle<PieceStat> >::iterator i =
|
||||
sortedPieceStats.begin(); i != sortedPieceStats.end(); ++i) {
|
||||
for(std::vector<SharedHandle<PieceStat> >::const_iterator i =
|
||||
sortedPieceStats.begin(), eoi = sortedPieceStats.end();
|
||||
i != eoi; ++i) {
|
||||
_sortedPieceStatIndexes[order] = (*i)->getIndex();
|
||||
(*i)->setOrder(order++);
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ PriorityPieceSelector::PriorityPieceSelector
|
|||
bool PriorityPieceSelector::select
|
||||
(size_t& index, const unsigned char* bitfield, size_t nbits) const
|
||||
{
|
||||
for(std::vector<size_t>::const_iterator i = _prioritizedPieces.begin();
|
||||
i != _prioritizedPieces.end(); ++i) {
|
||||
for(std::vector<size_t>::const_iterator i = _prioritizedPieces.begin(),
|
||||
eoi = _prioritizedPieces.end(); i != eoi; ++i) {
|
||||
if(bitfield::test(bitfield, nbits, *i)) {
|
||||
index = *i;
|
||||
return true;
|
||||
|
|
|
@ -339,8 +339,8 @@ void RequestGroup::createInitialCommand
|
|||
if(!torrentAttrs[bittorrent::NODES].empty() && DHTSetup::initialized()) {
|
||||
std::vector<std::pair<std::string, uint16_t> > entryPoints;
|
||||
const BDE& nodes = torrentAttrs[bittorrent::NODES];
|
||||
for(BDE::List::const_iterator i = nodes.listBegin();
|
||||
i != nodes.listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = nodes.listBegin(),
|
||||
eoi = nodes.listEnd(); i != eoi; ++i) {
|
||||
std::pair<std::string, uint16_t> addr
|
||||
((*i)[bittorrent::HOSTNAME].s(), (*i)[bittorrent::PORT].i());
|
||||
entryPoints.push_back(addr);
|
||||
|
@ -854,8 +854,8 @@ void RequestGroup::preDownloadProcessing()
|
|||
}
|
||||
try {
|
||||
for(std::vector<SharedHandle<PreDownloadHandler> >::const_iterator itr =
|
||||
_preDownloadHandlers.begin();
|
||||
itr != _preDownloadHandlers.end(); ++itr) {
|
||||
_preDownloadHandlers.begin(), eoi = _preDownloadHandlers.end();
|
||||
itr != eoi; ++itr) {
|
||||
if((*itr)->canHandle(this)) {
|
||||
(*itr)->execute(this);
|
||||
return;
|
||||
|
@ -880,8 +880,8 @@ void RequestGroup::postDownloadProcessing
|
|||
}
|
||||
try {
|
||||
for(std::vector<SharedHandle<PostDownloadHandler> >::const_iterator itr =
|
||||
_postDownloadHandlers.begin();
|
||||
itr != _postDownloadHandlers.end(); ++itr) {
|
||||
_postDownloadHandlers.begin(), eoi = _postDownloadHandlers.end();
|
||||
itr != eoi; ++itr) {
|
||||
if((*itr)->canHandle(this)) {
|
||||
(*itr)->getNextRequestGroups(groups, this);
|
||||
return;
|
||||
|
|
|
@ -389,7 +389,7 @@ public:
|
|||
const std::vector<SharedHandle<PeerStat> >& peerStats =
|
||||
group->getSegmentMan()->getFastestPeerStats();
|
||||
for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
|
||||
peerStats.begin(); i != peerStats.end(); ++i) {
|
||||
peerStats.begin(), eoi = peerStats.end(); i != eoi; ++i) {
|
||||
if((*i)->getHostname().empty() || (*i)->getProtocol().empty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -529,8 +529,8 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|||
|
||||
void RequestGroupMan::save()
|
||||
{
|
||||
for(std::deque<SharedHandle<RequestGroup> >::iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); itr != eoi; ++itr) {
|
||||
if((*itr)->allDownloadFinished()) {
|
||||
(*itr)->removeControlFile();
|
||||
} else {
|
||||
|
@ -545,8 +545,8 @@ void RequestGroupMan::save()
|
|||
|
||||
void RequestGroupMan::closeFile()
|
||||
{
|
||||
for(std::deque<SharedHandle<RequestGroup> >::iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); itr != eoi; ++itr) {
|
||||
(*itr)->closeFile();
|
||||
}
|
||||
}
|
||||
|
@ -558,7 +558,8 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
|
|||
size_t inprogress = 0;
|
||||
downloadresultcode::RESULT lastError = downloadresultcode::FINISHED;
|
||||
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr =
|
||||
_downloadResults.begin(); itr != _downloadResults.end(); ++itr) {
|
||||
_downloadResults.begin(), eoi = _downloadResults.end();
|
||||
itr != eoi; ++itr) {
|
||||
if((*itr)->result == downloadresultcode::FINISHED) {
|
||||
++finished;
|
||||
} else {
|
||||
|
@ -567,7 +568,7 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
|
|||
}
|
||||
}
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); itr != eoi; ++itr) {
|
||||
DownloadResultHandle result = (*itr)->createDownloadResult();
|
||||
if(result->result == downloadresultcode::FINISHED) {
|
||||
++finished;
|
||||
|
@ -602,8 +603,9 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
|
|||
int err = 0;
|
||||
int inpr = 0;
|
||||
|
||||
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin();
|
||||
itr != _downloadResults.end(); ++itr) {
|
||||
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr =
|
||||
_downloadResults.begin(), eoi = _downloadResults.end();
|
||||
itr != eoi; ++itr) {
|
||||
std::string status;
|
||||
if((*itr)->result == downloadresultcode::FINISHED) {
|
||||
status = MARK_OK;
|
||||
|
@ -618,7 +620,7 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
|
|||
o << formatDownloadResult(status, *itr) << "\n";
|
||||
}
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); itr != eoi; ++itr) {
|
||||
DownloadResultHandle result = (*itr)->createDownloadResult();
|
||||
std::string status;
|
||||
if(result->result == downloadresultcode::FINISHED) {
|
||||
|
@ -697,7 +699,7 @@ bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) cons
|
|||
}
|
||||
std::vector<std::string> files;
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); itr != eoi; ++itr) {
|
||||
if((*itr).get() != requestGroup) {
|
||||
const std::vector<SharedHandle<FileEntry> >& entries =
|
||||
(*itr)->getDownloadContext()->getFileEntries();
|
||||
|
@ -715,17 +717,17 @@ bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) cons
|
|||
|
||||
void RequestGroupMan::halt()
|
||||
{
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
(*itr)->setHaltRequested(true);
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); i != eoi; ++i) {
|
||||
(*i)->setHaltRequested(true);
|
||||
}
|
||||
}
|
||||
|
||||
void RequestGroupMan::forceHalt()
|
||||
{
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
|
||||
_requestGroups.begin(); itr != _requestGroups.end(); ++itr) {
|
||||
(*itr)->setForceHaltRequested(true);
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); i != eoi; ++i) {
|
||||
(*i)->setForceHaltRequested(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -733,7 +735,7 @@ TransferStat RequestGroupMan::calculateStat()
|
|||
{
|
||||
TransferStat s;
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
_requestGroups.begin(); i != _requestGroups.end(); ++i) {
|
||||
_requestGroups.begin(), eoi = _requestGroups.end(); i != eoi; ++i) {
|
||||
s += (*i)->calculateStat();
|
||||
}
|
||||
return s;
|
||||
|
@ -743,7 +745,7 @@ SharedHandle<DownloadResult>
|
|||
RequestGroupMan::findDownloadResult(int32_t gid) const
|
||||
{
|
||||
for(std::deque<SharedHandle<DownloadResult> >::const_iterator i =
|
||||
_downloadResults.begin(); i != _downloadResults.end(); ++i) {
|
||||
_downloadResults.begin(), eoi = _downloadResults.end(); i != eoi; ++i) {
|
||||
if((*i)->gid == gid) {
|
||||
return *i;
|
||||
}
|
||||
|
|
|
@ -158,8 +158,8 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
|
|||
void SegmentMan::getInFlightSegment
|
||||
(std::vector<SharedHandle<Segment> >& segments, cuid_t cuid)
|
||||
{
|
||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
|
||||
itr != usedSegmentEntries.end(); ++itr) {
|
||||
for(SegmentEntries::const_iterator itr = usedSegmentEntries.begin(),
|
||||
eoi = usedSegmentEntries.end(); itr != eoi; ++itr) {
|
||||
const SegmentEntryHandle& segmentEntry = *itr;
|
||||
if(segmentEntry->cuid == cuid) {
|
||||
segments.push_back(segmentEntry->segment);
|
||||
|
@ -199,8 +199,8 @@ void SegmentMan::getSegment
|
|||
segments.push_back(segment);
|
||||
}
|
||||
}
|
||||
for(std::vector<SharedHandle<Segment> >::const_iterator i = pending.begin();
|
||||
i != pending.end(); ++i) {
|
||||
for(std::vector<SharedHandle<Segment> >::const_iterator i = pending.begin(),
|
||||
eoi = pending.end(); i != eoi; ++i) {
|
||||
cancelSegment(cuid, *i);
|
||||
}
|
||||
}
|
||||
|
@ -223,11 +223,12 @@ void SegmentMan::cancelSegment(const SharedHandle<Segment>& segment)
|
|||
}
|
||||
|
||||
void SegmentMan::cancelSegment(cuid_t cuid) {
|
||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
|
||||
itr != usedSegmentEntries.end();) {
|
||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin(),
|
||||
eoi = usedSegmentEntries.end(); itr != eoi;) {
|
||||
if((*itr)->cuid == cuid) {
|
||||
cancelSegment((*itr)->segment);
|
||||
itr = usedSegmentEntries.erase(itr);
|
||||
eoi = usedSegmentEntries.end();
|
||||
} else {
|
||||
++itr;
|
||||
}
|
||||
|
@ -237,11 +238,12 @@ void SegmentMan::cancelSegment(cuid_t cuid) {
|
|||
void SegmentMan::cancelSegment
|
||||
(cuid_t cuid, const SharedHandle<Segment>& segment)
|
||||
{
|
||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin();
|
||||
itr != usedSegmentEntries.end();) {
|
||||
for(SegmentEntries::iterator itr = usedSegmentEntries.begin(),
|
||||
eoi = usedSegmentEntries.end(); itr != eoi;) {
|
||||
if((*itr)->cuid == cuid && (*itr)->segment == segment) {
|
||||
cancelSegment((*itr)->segment);
|
||||
itr = usedSegmentEntries.erase(itr);
|
||||
//eoi = usedSegmentEntries.end();
|
||||
break;
|
||||
} else {
|
||||
++itr;
|
||||
|
@ -290,8 +292,8 @@ uint64_t SegmentMan::getDownloadLength() const {
|
|||
|
||||
void SegmentMan::registerPeerStat(const SharedHandle<PeerStat>& peerStat)
|
||||
{
|
||||
for(std::vector<SharedHandle<PeerStat> >::iterator i = peerStats.begin();
|
||||
i != peerStats.end(); ++i) {
|
||||
for(std::vector<SharedHandle<PeerStat> >::iterator i = peerStats.begin(),
|
||||
eoi = peerStats.end(); i != eoi; ++i) {
|
||||
if((*i)->getStatus() == PeerStat::IDLE) {
|
||||
*i = peerStat;
|
||||
return;
|
||||
|
@ -338,7 +340,7 @@ unsigned int SegmentMan::calculateDownloadSpeed()
|
|||
_lastPeerStatDlspdMapUpdated.reset();
|
||||
_peerStatDlspdMap.clear();
|
||||
for(std::vector<SharedHandle<PeerStat> >::const_iterator i =
|
||||
peerStats.begin(); i != peerStats.end(); ++i) {
|
||||
peerStats.begin(), eoi = peerStats.end(); i != eoi; ++i) {
|
||||
if((*i)->getStatus() == PeerStat::ACTIVE) {
|
||||
unsigned int s = (*i)->calculateDownloadSpeed();
|
||||
_peerStatDlspdMap[(*i)->getCuid()] = s;
|
||||
|
|
|
@ -179,10 +179,10 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
|||
#endif // __MINGW32__
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
|
||||
for(std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator itr =
|
||||
_nameResolverEntries.begin(); itr != _nameResolverEntries.end();
|
||||
++itr) {
|
||||
SharedHandle<AsyncNameResolverEntry>& entry = *itr;
|
||||
for(std::deque<SharedHandle<AsyncNameResolverEntry> >::const_iterator itr =
|
||||
_nameResolverEntries.begin(), eoi = _nameResolverEntries.end();
|
||||
itr != eoi; ++itr) {
|
||||
const SharedHandle<AsyncNameResolverEntry>& entry = *itr;
|
||||
int fd = entry->getFds(&rfds, &wfds);
|
||||
// TODO force error if fd == 0
|
||||
if(_fdmax < fd) {
|
||||
|
@ -201,8 +201,8 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
|||
#endif // !__MINGW32__
|
||||
} while(retval == -1 && errno == EINTR);
|
||||
if(retval > 0) {
|
||||
for(std::deque<SharedHandle<SocketEntry> >::iterator i =
|
||||
_socketEntries.begin(); i != _socketEntries.end(); ++i) {
|
||||
for(std::deque<SharedHandle<SocketEntry> >::const_iterator i =
|
||||
_socketEntries.begin(), eoi = _socketEntries.end(); i != eoi; ++i) {
|
||||
int events = 0;
|
||||
if(FD_ISSET((*i)->getSocket(), &rfds)) {
|
||||
events |= EventPoll::EVENT_READ;
|
||||
|
@ -215,8 +215,9 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
|||
}
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
|
||||
for(std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator i =
|
||||
_nameResolverEntries.begin(); i != _nameResolverEntries.end(); ++i) {
|
||||
for(std::deque<SharedHandle<AsyncNameResolverEntry> >::const_iterator i =
|
||||
_nameResolverEntries.begin(), eoi = _nameResolverEntries.end();
|
||||
i != eoi; ++i) {
|
||||
(*i)->process(&rfds, &wfds);
|
||||
}
|
||||
|
||||
|
@ -232,8 +233,8 @@ void SelectEventPoll::updateFdSet()
|
|||
#endif // !__MINGW32__
|
||||
FD_ZERO(&_rfdset);
|
||||
FD_ZERO(&_wfdset);
|
||||
for(std::deque<SharedHandle<SocketEntry> >::iterator i =
|
||||
_socketEntries.begin(); i != _socketEntries.end(); ++i) {
|
||||
for(std::deque<SharedHandle<SocketEntry> >::const_iterator i =
|
||||
_socketEntries.begin(), eoi = _socketEntries.end(); i != eoi; ++i) {
|
||||
sock_t fd = (*i)->getSocket();
|
||||
int events = (*i)->getEvents();
|
||||
if(events&EventPoll::EVENT_READ) {
|
||||
|
|
|
@ -105,8 +105,8 @@ bool ServerStatMan::load(std::istream& in)
|
|||
std::vector<std::string> items;
|
||||
util::split(line, std::back_inserter(items), ",");
|
||||
std::map<std::string, std::string> m;
|
||||
for(std::vector<std::string>::const_iterator i = items.begin();
|
||||
i != items.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = items.begin(),
|
||||
eoi = items.end(); i != eoi; ++i) {
|
||||
std::pair<std::string, std::string> p = util::split(*i, "=");
|
||||
util::trimSelf(p.first);
|
||||
util::trimSelf(p.second);
|
||||
|
|
|
@ -307,7 +307,8 @@ void SocketCore::bind(uint16_t port, int flags)
|
|||
}
|
||||
} else {
|
||||
for(std::vector<std::pair<struct sockaddr_storage, socklen_t> >::
|
||||
const_iterator i = _bindAddrs.begin(); i != _bindAddrs.end(); ++i) {
|
||||
const_iterator i = _bindAddrs.begin(), eoi = _bindAddrs.end();
|
||||
i != eoi; ++i) {
|
||||
char host[NI_MAXHOST];
|
||||
int s;
|
||||
s = getnameinfo(reinterpret_cast<const struct sockaddr*>(&(*i).first),
|
||||
|
@ -410,7 +411,8 @@ void SocketCore::establishConnection(const std::string& host, uint16_t port)
|
|||
if(!_bindAddrs.empty()) {
|
||||
bool bindSuccess = false;
|
||||
for(std::vector<std::pair<struct sockaddr_storage, socklen_t> >::
|
||||
const_iterator i = _bindAddrs.begin(); i != _bindAddrs.end(); ++i) {
|
||||
const_iterator i = _bindAddrs.begin(), eoi = _bindAddrs.end();
|
||||
i != eoi; ++i) {
|
||||
if(::bind(fd,reinterpret_cast<const struct sockaddr*>(&(*i).first),
|
||||
(*i).second) == -1) {
|
||||
if(LogFactory::getInstance()->debug()) {
|
||||
|
@ -1249,7 +1251,8 @@ void SocketCore::bindAddress(const std::string& iface)
|
|||
} else {
|
||||
_bindAddrs = bindAddrs;
|
||||
for(std::vector<std::pair<struct sockaddr_storage, socklen_t> >::
|
||||
const_iterator i = _bindAddrs.begin(); i != _bindAddrs.end(); ++i) {
|
||||
const_iterator i = _bindAddrs.begin(), eoi = _bindAddrs.end();
|
||||
i != eoi; ++i) {
|
||||
char host[NI_MAXHOST];
|
||||
int s;
|
||||
s = getnameinfo(reinterpret_cast<const struct sockaddr*>(&(*i).first),
|
||||
|
|
|
@ -68,8 +68,8 @@ std::vector<size_t> UTMetadataRequestTracker::removeTimeoutEntry()
|
|||
{
|
||||
std::vector<size_t> indexes;
|
||||
const time_t TIMEOUT = 20;
|
||||
for(std::vector<RequestEntry>::iterator i = _trackedRequests.begin();
|
||||
i != _trackedRequests.end();) {
|
||||
for(std::vector<RequestEntry>::iterator i = _trackedRequests.begin(),
|
||||
eoi = _trackedRequests.end(); i != eoi;) {
|
||||
if((*i).elapsed(TIMEOUT)) {
|
||||
if(_logger->debug()) {
|
||||
_logger->debug("ut_metadata request timeout. index=%lu",
|
||||
|
@ -77,6 +77,7 @@ std::vector<size_t> UTMetadataRequestTracker::removeTimeoutEntry()
|
|||
}
|
||||
indexes.push_back((*i)._index);
|
||||
i = _trackedRequests.erase(i);
|
||||
eoi = _trackedRequests.end();
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
|
@ -97,8 +98,8 @@ size_t UTMetadataRequestTracker::avail() const
|
|||
std::vector<size_t> UTMetadataRequestTracker::getAllTrackedIndex() const
|
||||
{
|
||||
std::vector<size_t> indexes;
|
||||
for(std::vector<RequestEntry>::const_iterator i = _trackedRequests.begin();
|
||||
i != _trackedRequests.end(); ++i) {
|
||||
for(std::vector<RequestEntry>::const_iterator i = _trackedRequests.begin(),
|
||||
eoi = _trackedRequests.end(); i != eoi; ++i) {
|
||||
indexes.push_back((*i)._index);
|
||||
}
|
||||
return indexes;
|
||||
|
|
|
@ -76,8 +76,8 @@ UTPexExtensionMessage::createCompactPeerListAndFlag
|
|||
{
|
||||
std::string addrstring;
|
||||
std::string flagstring;
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin();
|
||||
itr != peers.end(); ++itr) {
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin(),
|
||||
eoi = peers.end(); itr != eoi; ++itr) {
|
||||
unsigned char compact[6];
|
||||
if(bittorrent::createcompact(compact, (*itr)->ipaddr, (*itr)->port)) {
|
||||
addrstring.append(&compact[0], &compact[6]);
|
||||
|
|
|
@ -103,8 +103,8 @@ static void gatherOption
|
|||
const BDE& value = (*first).second;
|
||||
if((optionName == PREF_HEADER || optionName == PREF_INDEX_OUT) &&
|
||||
value.isList()){
|
||||
for(BDE::List::const_iterator argiter = value.listBegin();
|
||||
argiter != value.listEnd(); ++argiter) {
|
||||
for(BDE::List::const_iterator argiter = value.listBegin(),
|
||||
eoi = value.listEnd(); argiter != eoi; ++argiter) {
|
||||
if((*argiter).isString()) {
|
||||
optionHandler->parse(*option.get(), (*argiter).s());
|
||||
}
|
||||
|
|
|
@ -168,8 +168,8 @@ static void getPosParam(const BDE& params, size_t posParamIndex,
|
|||
template<typename OutputIterator>
|
||||
static void extractUris(OutputIterator out, const BDE& src)
|
||||
{
|
||||
for(BDE::List::const_iterator i = src.listBegin(), end = src.listEnd();
|
||||
i != end; ++i) {
|
||||
for(BDE::List::const_iterator i = src.listBegin(), eoi = src.listEnd();
|
||||
i != eoi; ++i) {
|
||||
if((*i).isString()) {
|
||||
out++ = (*i).s();
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ BDE AddMetalinkXmlRpcMethod::process
|
|||
}
|
||||
BDE gids = BDE::list();
|
||||
for(std::vector<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
result.begin(); i != result.end(); ++i) {
|
||||
result.begin(), eoi = result.end(); i != eoi; ++i) {
|
||||
gids << BDE(util::itos((*i)->getGID()));
|
||||
}
|
||||
return gids;
|
||||
|
@ -325,8 +325,8 @@ static void createFileEntry(BDE& files, InputIterator first, InputIterator last)
|
|||
BDE uriList = BDE::list();
|
||||
std::vector<std::string> uris;
|
||||
(*first)->getUris(uris);
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
BDE uriEntry = BDE::dict();
|
||||
uriEntry[KEY_URI] = *i;
|
||||
uriList << uriEntry;
|
||||
|
@ -362,8 +362,8 @@ void gatherProgressCommon
|
|||
if(!group->followedBy().empty()) {
|
||||
BDE list = BDE::list();
|
||||
// The element is GID.
|
||||
for(std::vector<int32_t>::const_iterator i = group->followedBy().begin();
|
||||
i != group->followedBy().end(); ++i) {
|
||||
for(std::vector<int32_t>::const_iterator i = group->followedBy().begin(),
|
||||
eoi = group->followedBy().end(); i != eoi; ++i) {
|
||||
list << util::itos(*i);
|
||||
}
|
||||
entryDict[KEY_FOLLOWED_BY] = list;
|
||||
|
@ -395,11 +395,11 @@ void gatherBitTorrentMetadata(BDE& btDict, const BDE& torrentAttrs)
|
|||
// TODO Would it be good to add copy() method in BDE?
|
||||
const BDE& announceList = torrentAttrs[bittorrent::ANNOUNCE_LIST];
|
||||
BDE destAnnounceList = BDE::list();
|
||||
for(BDE::List::const_iterator l = announceList.listBegin();
|
||||
l != announceList.listEnd(); ++l) {
|
||||
for(BDE::List::const_iterator l = announceList.listBegin(),
|
||||
eoi = announceList.listEnd(); l != eoi; ++l) {
|
||||
BDE destAnnounceTier = BDE::list();
|
||||
for(BDE::List::const_iterator t = (*l).listBegin();
|
||||
t != (*l).listEnd(); ++t) {
|
||||
for(BDE::List::const_iterator t = (*l).listBegin(),
|
||||
eoi2 = (*l).listEnd(); t != eoi2; ++t) {
|
||||
destAnnounceTier << (*t);
|
||||
}
|
||||
destAnnounceList << destAnnounceTier;
|
||||
|
@ -435,7 +435,7 @@ static void gatherPeer(BDE& peers, const SharedHandle<PeerStorage>& ps)
|
|||
std::vector<SharedHandle<Peer> > activePeers;
|
||||
ps->getActivePeers(activePeers);
|
||||
for(std::vector<SharedHandle<Peer> >::const_iterator i =
|
||||
activePeers.begin(); i != activePeers.end(); ++i) {
|
||||
activePeers.begin(), eoi = activePeers.end(); i != eoi; ++i) {
|
||||
BDE peerEntry = BDE::dict();
|
||||
peerEntry[KEY_PEER_ID] = util::torrentUrlencode((*i)->getPeerId(),
|
||||
PEER_ID_LENGTH);
|
||||
|
@ -483,8 +483,8 @@ void gatherStoppedDownload
|
|||
if(!ds->followedBy.empty()) {
|
||||
BDE list = BDE::list();
|
||||
// The element is GID.
|
||||
for(std::vector<int32_t>::const_iterator i = ds->followedBy.begin();
|
||||
i != ds->followedBy.end(); ++i) {
|
||||
for(std::vector<int32_t>::const_iterator i = ds->followedBy.begin(),
|
||||
eoi = ds->followedBy.end(); i != eoi; ++i) {
|
||||
list << util::itos(*i);
|
||||
}
|
||||
entryDict[KEY_FOLLOWED_BY] = list;
|
||||
|
@ -561,8 +561,8 @@ BDE GetUrisXmlRpcMethod::process
|
|||
if(!group->getDownloadContext()->getFileEntries().empty()) {
|
||||
std::vector<std::string> uris;
|
||||
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
BDE entry = BDE::dict();
|
||||
entry[KEY_URI] = *i;
|
||||
uriList << entry;
|
||||
|
@ -642,7 +642,7 @@ BDE TellActiveXmlRpcMethod::process
|
|||
const std::deque<SharedHandle<RequestGroup> >& groups =
|
||||
e->_requestGroupMan->getRequestGroups();
|
||||
for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
|
||||
groups.begin(); i != groups.end(); ++i) {
|
||||
groups.begin(), eoi = groups.end(); i != eoi; ++i) {
|
||||
BDE entryDict = BDE::dict();
|
||||
entryDict[KEY_STATUS] = BDE_ACTIVE;
|
||||
gatherProgress(entryDict, *i, e);
|
||||
|
@ -757,7 +757,8 @@ BDE GetVersionXmlRpcMethod::process
|
|||
result[KEY_VERSION] = std::string(PACKAGE_VERSION);
|
||||
BDE featureList = BDE::list();
|
||||
const FeatureMap& features = FeatureConfig::getInstance()->getFeatures();
|
||||
for(FeatureMap::const_iterator i = features.begin(); i != features.end();++i){
|
||||
for(FeatureMap::const_iterator i = features.begin(), eoi = features.end();
|
||||
i != eoi;++i){
|
||||
if((*i).second) {
|
||||
featureList << (*i).first;
|
||||
}
|
||||
|
@ -803,8 +804,8 @@ BDE GetGlobalOptionXmlRpcMethod::process
|
|||
(const XmlRpcRequest& req, DownloadEngine* e)
|
||||
{
|
||||
BDE result = BDE::dict();
|
||||
for(std::map<std::string, std::string>::const_iterator i = e->option->begin();
|
||||
i != e->option->end(); ++i) {
|
||||
for(std::map<std::string, std::string>::const_iterator i = e->option->begin(),
|
||||
eoi = e->option->end(); i != eoi; ++i) {
|
||||
SharedHandle<OptionHandler> h = _optionParser->findByName((*i).first);
|
||||
if(!h.isNull() && !h->isHidden()) {
|
||||
result[(*i).first] = (*i).second;
|
||||
|
@ -861,8 +862,8 @@ BDE SystemMulticallXmlRpcMethod::process
|
|||
}
|
||||
const BDE& methodSpecs = params[0];
|
||||
BDE list = BDE::list();
|
||||
for(BDE::List::const_iterator i = methodSpecs.listBegin();
|
||||
i != methodSpecs.listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = methodSpecs.listBegin(),
|
||||
eoi = methodSpecs.listEnd(); i != eoi; ++i) {
|
||||
if(!(*i).isDict()) {
|
||||
list << createErrorResponse
|
||||
(DL_ABORT_EX("system.multicall expected struct."));
|
||||
|
|
|
@ -212,7 +212,8 @@ static void encodeIter(std::ostream& o, const BDE& bde)
|
|||
o.write(s.data(), s.size());
|
||||
} else if(bde.isDict()) {
|
||||
o << "d";
|
||||
for(BDE::Dict::const_iterator i = bde.dictBegin(); i != bde.dictEnd(); ++i){
|
||||
for(BDE::Dict::const_iterator i = bde.dictBegin(), eoi = bde.dictEnd();
|
||||
i != eoi; ++i){
|
||||
const std::string& key = (*i).first;
|
||||
o << key.size() << ":";
|
||||
o.write(key.data(), key.size());
|
||||
|
@ -221,7 +222,8 @@ static void encodeIter(std::ostream& o, const BDE& bde)
|
|||
o << "e";
|
||||
} else if(bde.isList()) {
|
||||
o << "l";
|
||||
for(BDE::List::const_iterator i = bde.listBegin(); i != bde.listEnd(); ++i){
|
||||
for(BDE::List::const_iterator i = bde.listBegin(), eoi = bde.listEnd();
|
||||
i != eoi; ++i){
|
||||
encodeIter(o, *i);
|
||||
}
|
||||
o << "e";
|
||||
|
|
|
@ -150,8 +150,8 @@ static void extractUrlList
|
|||
(BDE& torrent, std::vector<std::string>& uris, const BDE& bde)
|
||||
{
|
||||
if(bde.isList()) {
|
||||
for(BDE::List::const_iterator itr = bde.listBegin();
|
||||
itr != bde.listEnd(); ++itr) {
|
||||
for(BDE::List::const_iterator itr = bde.listBegin(), eoi = bde.listEnd();
|
||||
itr != eoi; ++itr) {
|
||||
if((*itr).isString()) {
|
||||
uris.push_back((*itr).s());
|
||||
}
|
||||
|
@ -221,8 +221,8 @@ static void extractFileEntries
|
|||
off_t offset = 0;
|
||||
// multi-file mode
|
||||
torrent[MODE] = MULTI;
|
||||
for(BDE::List::const_iterator itr = filesList.listBegin();
|
||||
itr != filesList.listEnd(); ++itr) {
|
||||
for(BDE::List::const_iterator itr = filesList.listBegin(),
|
||||
eoi = filesList.listEnd(); itr != eoi; ++itr) {
|
||||
const BDE& fileDict = *itr;
|
||||
if(!fileDict.isDict()) {
|
||||
continue;
|
||||
|
@ -277,8 +277,8 @@ static void extractFileEntries
|
|||
// For each uri in urlList, if it ends with '/', then
|
||||
// concatenate name to it. Specification just says so.
|
||||
std::vector<std::string> uris;
|
||||
for(std::vector<std::string>::const_iterator i = urlList.begin();
|
||||
i != urlList.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = urlList.begin(),
|
||||
eoi = urlList.end(); i != eoi; ++i) {
|
||||
if(util::endsWith(*i, A2STR::SLASH_C)) {
|
||||
uris.push_back((*i)+name);
|
||||
} else {
|
||||
|
@ -305,10 +305,10 @@ static void extractAnnounce(BDE& torrent, const BDE& rootDict)
|
|||
if(announceList.isList()) {
|
||||
torrent[ANNOUNCE_LIST] = announceList;
|
||||
BDE& tiers = torrent[ANNOUNCE_LIST];
|
||||
for(BDE::List::iterator tieriter = tiers.listBegin();
|
||||
tieriter != tiers.listEnd(); ++tieriter) {
|
||||
for(BDE::List::iterator uriiter = (*tieriter).listBegin();
|
||||
uriiter != (*tieriter).listEnd(); ++uriiter) {
|
||||
for(BDE::List::iterator tieriter = tiers.listBegin(),
|
||||
eoi = tiers.listEnd(); tieriter != eoi; ++tieriter) {
|
||||
for(BDE::List::iterator uriiter = (*tieriter).listBegin(),
|
||||
eoi2 = (*tieriter).listEnd(); uriiter != eoi2; ++uriiter) {
|
||||
if((*uriiter).isString()) {
|
||||
*uriiter = util::trim((*uriiter).s());
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ static void extractNodes(BDE& torrent, const BDE& nodesList)
|
|||
{
|
||||
BDE nodes = BDE::list();
|
||||
if(nodesList.isList()) {
|
||||
for(BDE::List::const_iterator i = nodesList.listBegin();
|
||||
i != nodesList.listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = nodesList.listBegin(),
|
||||
eoi = nodesList.listEnd(); i != eoi; ++i) {
|
||||
const BDE& addrPairList = (*i);
|
||||
if(!addrPairList.isList() || addrPairList.size() != 2) {
|
||||
continue;
|
||||
|
@ -567,13 +567,13 @@ void print(std::ostream& o, const SharedHandle<DownloadContext>& dctx)
|
|||
o << "Mode: " << torrentAttrs[MODE].s() << "\n";
|
||||
o << "Announce:" << "\n";
|
||||
const BDE& announceList = torrentAttrs[ANNOUNCE_LIST];
|
||||
for(BDE::List::const_iterator tieritr = announceList.listBegin();
|
||||
tieritr != announceList.listEnd(); ++tieritr) {
|
||||
for(BDE::List::const_iterator tieritr = announceList.listBegin(),
|
||||
eoi = announceList.listEnd(); tieritr != eoi; ++tieritr) {
|
||||
if(!(*tieritr).isList()) {
|
||||
continue;
|
||||
}
|
||||
for(BDE::List::const_iterator i = (*tieritr).listBegin();
|
||||
i != (*tieritr).listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = (*tieritr).listBegin(),
|
||||
eoi2 = (*tieritr).listEnd(); i != eoi2; ++i) {
|
||||
o << " " << (*i).s();
|
||||
}
|
||||
o << "\n";
|
||||
|
@ -586,8 +586,8 @@ void print(std::ostream& o, const SharedHandle<DownloadContext>& dctx)
|
|||
if(!torrentAttrs[URL_LIST].empty()) {
|
||||
const BDE& urlList = torrentAttrs[URL_LIST];
|
||||
o << "URL List: " << "\n";
|
||||
for(BDE::List::const_iterator i = urlList.listBegin();
|
||||
i != urlList.listEnd(); ++i) {
|
||||
for(BDE::List::const_iterator i = urlList.listBegin(),
|
||||
eoi = urlList.listEnd(); i != eoi; ++i) {
|
||||
o << " " << (*i).s() << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -886,8 +886,8 @@ BDE parseMagnet(const std::string& magnet)
|
|||
BDE announceList = BDE::list();
|
||||
if(r.containsKey("tr")) {
|
||||
const BDE& uris = r["tr"];
|
||||
for(BDE::List::const_iterator i = uris.listBegin(); i != uris.listEnd();
|
||||
++i) {
|
||||
for(BDE::List::const_iterator i = uris.listBegin(), eoi = uris.listEnd();
|
||||
i != eoi; ++i) {
|
||||
BDE tier = BDE::list();
|
||||
tier << *i;
|
||||
announceList << tier;
|
||||
|
@ -944,10 +944,10 @@ std::string torrent2Magnet(const BDE& attrs)
|
|||
}
|
||||
if(attrs.containsKey(ANNOUNCE_LIST)) {
|
||||
const BDE& tiers = attrs[ANNOUNCE_LIST];
|
||||
for(BDE::List::const_iterator tieriter = tiers.listBegin();
|
||||
tieriter != tiers.listEnd(); ++tieriter) {
|
||||
for(BDE::List::const_iterator uriiter = (*tieriter).listBegin();
|
||||
uriiter != (*tieriter).listEnd(); ++uriiter) {
|
||||
for(BDE::List::const_iterator tieriter = tiers.listBegin(),
|
||||
eoi = tiers.listEnd(); tieriter != eoi; ++tieriter) {
|
||||
for(BDE::List::const_iterator uriiter = (*tieriter).listBegin(),
|
||||
eoi2 = (*tieriter).listEnd(); uriiter != eoi2; ++uriiter) {
|
||||
uri += "&tr=";
|
||||
uri += util::urlencode((*uriiter).s());
|
||||
}
|
||||
|
|
|
@ -156,8 +156,8 @@ static void unfoldURI
|
|||
{
|
||||
ParameterizedStringParser p;
|
||||
PStringBuildVisitor v;
|
||||
for(std::vector<std::string>::const_iterator itr = args.begin();
|
||||
itr != args.end(); ++itr) {
|
||||
for(std::vector<std::string>::const_iterator itr = args.begin(),
|
||||
eoi = args.end(); itr != eoi; ++itr) {
|
||||
v.reset();
|
||||
p.parse(*itr)->accept(v);
|
||||
result.insert(result.end(), v.getURIs().begin(), v.getURIs().end());
|
||||
|
@ -221,8 +221,8 @@ createBtRequestGroup(const std::string& torrentFilePath,
|
|||
std::istringstream indexOutIn(option->get(PREF_INDEX_OUT));
|
||||
std::map<size_t, std::string> indexPathMap =
|
||||
util::createIndexPathMap(indexOutIn);
|
||||
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin();
|
||||
i != indexPathMap.end(); ++i) {
|
||||
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin(),
|
||||
eoi = indexPathMap.end(); i != eoi; ++i) {
|
||||
dctx->setFilePathWithIndex
|
||||
((*i).first, util::applyDir(dctx->getDir(), (*i).second));
|
||||
}
|
||||
|
@ -431,7 +431,8 @@ static void createRequestGroupForUriList
|
|||
|
||||
SharedHandle<Option> requestOption(new Option(*option.get()));
|
||||
for(std::set<std::string>::const_iterator i =
|
||||
listRequestOptions().begin(); i != listRequestOptions().end(); ++i) {
|
||||
listRequestOptions().begin(), eoi = listRequestOptions().end();
|
||||
i != eoi; ++i) {
|
||||
if(tempOption->defined(*i)) {
|
||||
requestOption->put(*i, tempOption->get(*i));
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ BDE parse(const std::string& magnet)
|
|||
util::split(std::string(magnet.begin()+8, magnet.end()),
|
||||
std::back_inserter(queries), "&");
|
||||
BDE dict = BDE::dict();
|
||||
for(std::vector<std::string>::const_iterator i = queries.begin();
|
||||
i != queries.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = queries.begin(),
|
||||
eoi = queries.end(); i != eoi; ++i) {
|
||||
std::pair<std::string, std::string> kv;
|
||||
util::split(kv, *i, '=');
|
||||
std::string value = util::urldecode(kv.second);
|
||||
|
|
|
@ -135,8 +135,8 @@ static void showFiles
|
|||
(const std::vector<std::string>& uris, const SharedHandle<Option>& op)
|
||||
{
|
||||
ProtocolDetector dt;
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin();
|
||||
i != uris.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
printf(">>> ");
|
||||
printf(MSG_SHOW_FILES, (*i).c_str());
|
||||
printf("\n");
|
||||
|
|
|
@ -132,8 +132,8 @@ std::string MessageDigestContext::getSupportedAlgoString()
|
|||
{
|
||||
const DigestAlgoMap& allAlgos = getDigestAlgos();
|
||||
std::string algos;
|
||||
for(DigestAlgoMap::const_iterator itr = allAlgos.begin();
|
||||
itr != allAlgos.end(); ++itr) {
|
||||
for(DigestAlgoMap::const_iterator itr = allAlgos.begin(),
|
||||
eoi = allAlgos.end(); itr != eoi; ++itr) {
|
||||
algos += (*itr).first;
|
||||
algos += ", ";
|
||||
}
|
||||
|
|
38
src/util.cc
38
src/util.cc
|
@ -295,8 +295,8 @@ std::string torrentUrlencode(const std::string& target)
|
|||
|
||||
std::string urldecode(const std::string& target) {
|
||||
std::string result;
|
||||
for(std::string::const_iterator itr = target.begin();
|
||||
itr != target.end(); ++itr) {
|
||||
for(std::string::const_iterator itr = target.begin(), eoi = target.end();
|
||||
itr != eoi; ++itr) {
|
||||
if(*itr == '%') {
|
||||
if(itr+1 != target.end() && itr+2 != target.end() &&
|
||||
isHexDigit(*(itr+1)) && isHexDigit(*(itr+2))) {
|
||||
|
@ -543,7 +543,7 @@ static void computeHeadPieces
|
|||
return;
|
||||
}
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator fi =
|
||||
fileEntries.begin(); fi != fileEntries.end(); ++fi) {
|
||||
fileEntries.begin(), eoi = fileEntries.end(); fi != eoi; ++fi) {
|
||||
if((*fi)->getLength() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ static void computeTailPieces
|
|||
return;
|
||||
}
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator fi =
|
||||
fileEntries.begin(); fi != fileEntries.end(); ++fi) {
|
||||
fileEntries.begin(), eoi = fileEntries.end(); fi != eoi; ++fi) {
|
||||
if((*fi)->getLength() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -589,8 +589,8 @@ void parsePrioritizePieceRange
|
|||
std::vector<size_t> indexes;
|
||||
std::vector<std::string> parts;
|
||||
split(src, std::back_inserter(parts), ",", true);
|
||||
for(std::vector<std::string>::const_iterator i = parts.begin();
|
||||
i != parts.end(); ++i) {
|
||||
for(std::vector<std::string>::const_iterator i = parts.begin(),
|
||||
eoi = parts.end(); i != eoi; ++i) {
|
||||
if((*i) == "head") {
|
||||
computeHeadPieces(indexes, fileEntries, pieceLength, defaultSize);
|
||||
} else if(util::startsWith(*i, "head=")) {
|
||||
|
@ -632,7 +632,8 @@ static std::string trimBasename(const std::string& src)
|
|||
std::string iso8859ToUtf8(const std::string& src)
|
||||
{
|
||||
std::string dest;
|
||||
for(std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr) {
|
||||
for(std::string::const_iterator itr = src.begin(), eoi = src.end();
|
||||
itr != eoi; ++itr) {
|
||||
unsigned char c = *itr;
|
||||
if(0xa0 <= c) {
|
||||
if(c <= 0xbf) {
|
||||
|
@ -655,14 +656,14 @@ std::string getContentDispositionFilename(const std::string& header)
|
|||
std::string filename;
|
||||
std::vector<std::string> params;
|
||||
split(header, std::back_inserter(params), A2STR::SEMICOLON_C, true);
|
||||
for(std::vector<std::string>::iterator i = params.begin();
|
||||
i != params.end(); ++i) {
|
||||
std::string& param = *i;
|
||||
for(std::vector<std::string>::const_iterator i = params.begin(),
|
||||
eoi = params.end(); i != eoi; ++i) {
|
||||
const std::string& param = *i;
|
||||
static const std::string keyName = "filename";
|
||||
if(!startsWith(toLower(param), keyName) || param.size() == keyName.size()) {
|
||||
continue;
|
||||
}
|
||||
std::string::iterator markeritr = param.begin()+keyName.size();
|
||||
std::string::const_iterator markeritr = param.begin()+keyName.size();
|
||||
if(*markeritr == '*') {
|
||||
// See RFC2231 Section4 and draft-reschke-rfc2231-in-http.
|
||||
// Please note that this function doesn't do charset conversion
|
||||
|
@ -683,8 +684,8 @@ std::string getContentDispositionFilename(const std::string& header)
|
|||
}
|
||||
bool bad = false;
|
||||
const std::string& charset = extValues[0];
|
||||
for(std::string::const_iterator j = charset.begin(); j != charset.end();
|
||||
++j) {
|
||||
for(std::string::const_iterator j = charset.begin(), eoi = charset.end();
|
||||
j != eoi; ++j) {
|
||||
// Since we first split parameter by ', we can safely assume
|
||||
// that ' is not included in charset.
|
||||
if(!inRFC2978MIMECharset(*j)) {
|
||||
|
@ -697,7 +698,8 @@ std::string getContentDispositionFilename(const std::string& header)
|
|||
}
|
||||
bad = false;
|
||||
value = extValues[2];
|
||||
for(std::string::const_iterator j = value.begin(); j != value.end(); ++j){
|
||||
for(std::string::const_iterator j = value.begin(), eoi = value.end();
|
||||
j != eoi; ++j){
|
||||
if(*j == '%') {
|
||||
if(j+1 != value.end() && isHexDigit(*(j+1)) &&
|
||||
j+2 != value.end() && isHexDigit(*(j+2))) {
|
||||
|
@ -909,7 +911,8 @@ bool isNumber(const std::string& what)
|
|||
if(what.empty()) {
|
||||
return false;
|
||||
}
|
||||
for(std::string::const_iterator i = what.begin(); i != what.end(); ++i) {
|
||||
for(std::string::const_iterator i = what.begin(), eoi = what.end();
|
||||
i != eoi; ++i) {
|
||||
if(!isDigit(*i)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1040,7 +1043,8 @@ getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
|||
std::string htmlEscape(const std::string& src)
|
||||
{
|
||||
std::string dest;
|
||||
for(std::string::const_iterator i = src.begin(); i != src.end(); ++i) {
|
||||
for(std::string::const_iterator i = src.begin(), eoi = src.end();
|
||||
i != eoi; ++i) {
|
||||
char ch = *i;
|
||||
if(ch == '<') {
|
||||
dest += "<";
|
||||
|
@ -1168,7 +1172,7 @@ bool inPrivateAddress(const std::string& ipv4addr)
|
|||
|
||||
bool detectDirTraversal(const std::string& s)
|
||||
{
|
||||
for(std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
|
||||
for(std::string::const_iterator i = s.begin(), eoi = s.end(); i != eoi; ++i) {
|
||||
if(0x00 <= (*i) && (*i) <= 0x1f) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue