mirror of https://github.com/aria2/aria2
More auto-converts by cpp11-migrate
parent
a76eeb2b81
commit
3590077d5c
|
@ -94,35 +94,34 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
size_t buffoffset = 0;
|
size_t buffoffset = 0;
|
||||||
const WrDiskCacheEntry::DataCellSet& dataSet = entry->getDataSet();
|
const WrDiskCacheEntry::DataCellSet& dataSet = entry->getDataSet();
|
||||||
for(WrDiskCacheEntry::DataCellSet::const_iterator i = dataSet.begin(),
|
for(auto & d : dataSet) {
|
||||||
eoi = dataSet.end(); i != eoi; ++i) {
|
if(start+static_cast<ssize_t>(buflen) < d->goff) {
|
||||||
if(start+static_cast<ssize_t>(buflen) < (*i)->goff) {
|
|
||||||
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
||||||
start, static_cast<unsigned long>(buflen)));
|
start, static_cast<unsigned long>(buflen)));
|
||||||
writeData(buf+buffoffset, buflen-buffoffset, start);
|
writeData(buf+buffoffset, buflen-buffoffset, start);
|
||||||
start = (*i)->goff;
|
start = d->goff;
|
||||||
buflen = buffoffset = 0;
|
buflen = buffoffset = 0;
|
||||||
}
|
}
|
||||||
if(buflen == 0 && ((*i)->goff & 0xfff) == 0 && ((*i)->len & 0xfff) == 0) {
|
if(buflen == 0 && (d->goff & 0xfff) == 0 && (d->len & 0xfff) == 0) {
|
||||||
// Already aligned. Write it without copy.
|
// Already aligned. Write it without copy.
|
||||||
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
||||||
start, static_cast<unsigned long>((*i)->len)));
|
start, static_cast<unsigned long>(d->len)));
|
||||||
writeData((*i)->data + (*i)->offset, (*i)->len, start);
|
writeData(d->data + d->offset, d->len, start);
|
||||||
start += (*i)->len;
|
start += d->len;
|
||||||
} else {
|
} else {
|
||||||
if(buflen == 0) {
|
if(buflen == 0) {
|
||||||
buflen = buffoffset = (*i)->goff & 0xfff;
|
buflen = buffoffset = d->goff & 0xfff;
|
||||||
}
|
}
|
||||||
size_t wlen = std::min(sizeof(buf) - buflen, (*i)->len);
|
size_t wlen = std::min(sizeof(buf) - buflen, d->len);
|
||||||
memcpy(buf+buflen, (*i)->data+(*i)->offset, wlen);
|
memcpy(buf+buflen, d->data + d->offset, wlen);
|
||||||
buflen += wlen;
|
buflen += wlen;
|
||||||
if(buflen == sizeof(buf)) {
|
if(buflen == sizeof(buf)) {
|
||||||
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
|
||||||
start, static_cast<unsigned long>(buflen)));
|
start, static_cast<unsigned long>(buflen)));
|
||||||
writeData(buf+buffoffset, buflen-buffoffset, start);
|
writeData(buf+buffoffset, buflen-buffoffset, start);
|
||||||
memcpy(buf, (*i)->data + (*i)->offset + wlen, (*i)->len - wlen);
|
memcpy(buf, d->data + d->offset + wlen, d->len - wlen);
|
||||||
start += sizeof(buf) - buffoffset;
|
start += sizeof(buf) - buffoffset;
|
||||||
buflen = (*i)->len - wlen;
|
buflen = d->len - wlen;
|
||||||
buffoffset = 0;
|
buffoffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,18 +263,18 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
|
||||||
{
|
{
|
||||||
int max = -1;
|
int max = -1;
|
||||||
std::string uri = A2STR::NIL;
|
std::string uri = A2STR::NIL;
|
||||||
for(auto i = uris.begin(), eoi = uris.end(); i != eoi; ++i) {
|
for(auto& u : uris) {
|
||||||
std::shared_ptr<ServerStat> ss = getServerStats(*i);
|
std::shared_ptr<ServerStat> ss = getServerStats(u);
|
||||||
if(!ss)
|
if(!ss)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if((int)ss->getSingleConnectionAvgSpeed() > max) {
|
if((int)ss->getSingleConnectionAvgSpeed() > max) {
|
||||||
max = ss->getSingleConnectionAvgSpeed();
|
max = ss->getSingleConnectionAvgSpeed();
|
||||||
uri = (*i);
|
uri = u;
|
||||||
}
|
}
|
||||||
if((int)ss->getMultiConnectionAvgSpeed() > max) {
|
if((int)ss->getMultiConnectionAvgSpeed() > max) {
|
||||||
max = ss->getMultiConnectionAvgSpeed();
|
max = ss->getMultiConnectionAvgSpeed();
|
||||||
uri = (*i);
|
uri = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uri;
|
return uri;
|
||||||
|
@ -284,13 +284,13 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
|
||||||
(const std::deque<std::string>& uris, int min) const
|
(const std::deque<std::string>& uris, int min) const
|
||||||
{
|
{
|
||||||
std::deque<std::string> bests;
|
std::deque<std::string> bests;
|
||||||
for(auto i = uris.begin(), eoi = uris.end(); i != eoi; ++i) {
|
for(auto& uri : uris) {
|
||||||
std::shared_ptr<ServerStat> ss = getServerStats(*i);
|
std::shared_ptr<ServerStat> ss = getServerStats(uri);
|
||||||
if(!ss)
|
if(!ss)
|
||||||
continue;
|
continue;
|
||||||
if(ss->getSingleConnectionAvgSpeed() > min ||
|
if(ss->getSingleConnectionAvgSpeed() > min ||
|
||||||
ss->getMultiConnectionAvgSpeed() > min) {
|
ss->getMultiConnectionAvgSpeed() > min) {
|
||||||
bests.push_back(*i);
|
bests.push_back(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bests;
|
return bests;
|
||||||
|
|
|
@ -230,9 +230,9 @@ namespace {
|
||||||
|
|
||||||
static inline const char* suiteToString(const SSLCipherSuite suite)
|
static inline const char* suiteToString(const SSLCipherSuite suite)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < nSuites; ++i) {
|
for (auto & s : kSuites) {
|
||||||
if (kSuites[i].suite == suite) {
|
if (s.suite == suite) {
|
||||||
return kSuites[i].name;
|
return s.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "Unknown suite";
|
return "Unknown suite";
|
||||||
|
@ -246,8 +246,8 @@ namespace {
|
||||||
static inline bool isBlockedSuite(SSLCipherSuite suite)
|
static inline bool isBlockedSuite(SSLCipherSuite suite)
|
||||||
{
|
{
|
||||||
const char* name = suiteToString(suite);
|
const char* name = suiteToString(suite);
|
||||||
for (size_t i = 0; i < nBlocked; ++i) {
|
for (auto& blocked : kBlocked) {
|
||||||
if (strstr(name, kBlocked[i])) {
|
if (strstr(name, blocked)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,8 @@ void BtAllowedFastMessage::doReceivedAction() {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct ThisProgressUpdate : public ProgressUpdate {
|
struct ThisProgressUpdate : public ProgressUpdate {
|
||||||
ThisProgressUpdate(const std::shared_ptr<Peer>& peer, size_t index)
|
ThisProgressUpdate(std::shared_ptr<Peer> peer, size_t index)
|
||||||
: peer(peer), index(index) {}
|
: peer(std::move(peer)), index(index) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(complete) {
|
if(complete) {
|
||||||
|
|
|
@ -67,9 +67,9 @@ bool BtChokeMessage::sendPredicate() const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct ThisProgressUpdate : public ProgressUpdate {
|
struct ThisProgressUpdate : public ProgressUpdate {
|
||||||
ThisProgressUpdate(const std::shared_ptr<Peer>& peer,
|
ThisProgressUpdate(std::shared_ptr<Peer> peer,
|
||||||
BtMessageDispatcher* disp)
|
BtMessageDispatcher* disp)
|
||||||
: peer(peer), disp(disp) {}
|
: peer(std::move(peer)), disp(disp) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(complete) {
|
if(complete) {
|
||||||
|
|
|
@ -72,8 +72,8 @@ bool BtInterestedMessage::sendPredicate() const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct ThisProgressUpdate : public ProgressUpdate {
|
struct ThisProgressUpdate : public ProgressUpdate {
|
||||||
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
|
ThisProgressUpdate(std::shared_ptr<Peer> peer)
|
||||||
: peer(peer) {}
|
: peer(std::move(peer)) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(complete) {
|
if(complete) {
|
||||||
|
|
|
@ -201,11 +201,10 @@ void BtLeecherStateChoke::executeChoke(const PeerSet& peerSet)
|
||||||
lastRound_ = global::wallclock();
|
lastRound_ = global::wallclock();
|
||||||
|
|
||||||
std::vector<PeerEntry> peerEntries;
|
std::vector<PeerEntry> peerEntries;
|
||||||
for(PeerSet::const_iterator i = peerSet.begin(), eoi = peerSet.end();
|
for (const auto& p : peerSet) {
|
||||||
i != eoi; ++i) {
|
if(p->isActive() && !p->snubbing()) {
|
||||||
if((*i)->isActive() && !(*i)->snubbing()) {
|
p->chokingRequired(true);
|
||||||
(*i)->chokingRequired(true);
|
peerEntries.push_back(PeerEntry(p));
|
||||||
peerEntries.push_back(PeerEntry(*i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@ bool BtNotInterestedMessage::sendPredicate() const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct ThisProgressUpdate : public ProgressUpdate {
|
struct ThisProgressUpdate : public ProgressUpdate {
|
||||||
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
|
ThisProgressUpdate(std::shared_ptr<Peer> peer)
|
||||||
: peer(peer) {}
|
: peer(std::move(peer)) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(complete) {
|
if(complete) {
|
||||||
|
|
|
@ -180,8 +180,8 @@ size_t BtPieceMessage::getMessageHeaderLength()
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct PieceSendUpdate : public ProgressUpdate {
|
struct PieceSendUpdate : public ProgressUpdate {
|
||||||
PieceSendUpdate(const std::shared_ptr<Peer>& peer, size_t headerLength)
|
PieceSendUpdate(std::shared_ptr<Peer> peer, size_t headerLength)
|
||||||
: peer(peer), headerLength(headerLength) {}
|
: peer(std::move(peer)), headerLength(headerLength) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(headerLength > 0) {
|
if(headerLength > 0) {
|
||||||
|
|
|
@ -151,11 +151,10 @@ void BtSeederStateChoke::executeChoke(const PeerSet& peerSet)
|
||||||
lastRound_ = global::wallclock();
|
lastRound_ = global::wallclock();
|
||||||
|
|
||||||
std::vector<PeerEntry> peerEntries;
|
std::vector<PeerEntry> peerEntries;
|
||||||
for(PeerSet::const_iterator i = peerSet.begin(), eoi = peerSet.end();
|
for(const auto& p : peerSet) {
|
||||||
i != eoi; ++i) {
|
if(p->isActive() && p->peerInterested()) {
|
||||||
if((*i)->isActive() && (*i)->peerInterested()) {
|
p->chokingRequired(true);
|
||||||
(*i)->chokingRequired(true);
|
peerEntries.push_back(PeerEntry(p));
|
||||||
peerEntries.push_back(PeerEntry(*i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ bool BtUnchokeMessage::sendPredicate() const
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct ThisProgressUpdate : public ProgressUpdate {
|
struct ThisProgressUpdate : public ProgressUpdate {
|
||||||
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
|
ThisProgressUpdate(std::shared_ptr<Peer> peer)
|
||||||
: peer(peer) {}
|
: peer(std::move(peer)) {}
|
||||||
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if(complete) {
|
if(complete) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ DHTPeerAnnounceStorage::getPeerAnnounceEntry(const unsigned char* infoHash)
|
||||||
{
|
{
|
||||||
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
|
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
|
||||||
|
|
||||||
DHTPeerAnnounceEntrySet::iterator i = entries_.lower_bound(entry);
|
auto i = entries_.lower_bound(entry);
|
||||||
|
|
||||||
if(i != entries_.end() &&
|
if(i != entries_.end() &&
|
||||||
memcmp(infoHash, (*i)->getInfoHash(), DHT_ID_LENGTH) == 0) {
|
memcmp(infoHash, (*i)->getInfoHash(), DHT_ID_LENGTH) == 0) {
|
||||||
|
@ -102,7 +102,7 @@ void DHTPeerAnnounceStorage::getPeers(std::vector<std::shared_ptr<Peer> >& peers
|
||||||
{
|
{
|
||||||
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
|
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
|
||||||
|
|
||||||
DHTPeerAnnounceEntrySet::iterator i = entries_.find(entry);
|
auto i = entries_.find(entry);
|
||||||
if(i != entries_.end()) {
|
if(i != entries_.end()) {
|
||||||
(*i)->getPeers(peers);
|
(*i)->getPeers(peers);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ void DHTPeerAnnounceStorage::handleTimeout()
|
||||||
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
|
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
|
||||||
static_cast<unsigned long>(entries_.size())));
|
static_cast<unsigned long>(entries_.size())));
|
||||||
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
|
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
|
||||||
for(DHTPeerAnnounceEntrySet::iterator i = entries_.begin(),
|
for(auto i = entries_.begin(),
|
||||||
eoi = entries_.end(); i != eoi;) {
|
eoi = entries_.end(); i != eoi;) {
|
||||||
if((*i)->empty()) {
|
if((*i)->empty()) {
|
||||||
entries_.erase(i++);
|
entries_.erase(i++);
|
||||||
|
|
|
@ -165,7 +165,7 @@ const std::string& DNSCache::find
|
||||||
(const std::string& hostname, uint16_t port) const
|
(const std::string& hostname, uint16_t port) const
|
||||||
{
|
{
|
||||||
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
||||||
CacheEntrySet::iterator i = entries_.find(target);
|
auto i = entries_.find(target);
|
||||||
if(i == entries_.end()) {
|
if(i == entries_.end()) {
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -177,7 +177,7 @@ void DNSCache::put
|
||||||
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
||||||
CacheEntrySet::iterator i = entries_.lower_bound(target);
|
auto i = entries_.lower_bound(target);
|
||||||
if(i != entries_.end() && *(*i) == *target) {
|
if(i != entries_.end() && *(*i) == *target) {
|
||||||
(*i)->add(ipaddr);
|
(*i)->add(ipaddr);
|
||||||
} else {
|
} else {
|
||||||
|
@ -190,7 +190,7 @@ void DNSCache::markBad
|
||||||
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
|
||||||
CacheEntrySet::iterator i = entries_.find(target);
|
auto i = entries_.find(target);
|
||||||
if(i != entries_.end()) {
|
if(i != entries_.end()) {
|
||||||
(*i)->markBad(ipaddr);
|
(*i)->markBad(ipaddr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,10 @@ private:
|
||||||
PieceStorage* pieceStorage_;
|
PieceStorage* pieceStorage_;
|
||||||
cuid_t cuid_;
|
cuid_t cuid_;
|
||||||
public:
|
public:
|
||||||
ProcessChokedPiece(const std::shared_ptr<Peer>& peer,
|
ProcessChokedPiece(std::shared_ptr<Peer> peer,
|
||||||
PieceStorage* pieceStorage,
|
PieceStorage* pieceStorage,
|
||||||
cuid_t cuid):
|
cuid_t cuid):
|
||||||
peer_(peer),
|
peer_(std::move(peer)),
|
||||||
pieceStorage_(pieceStorage),
|
pieceStorage_(pieceStorage),
|
||||||
cuid_(cuid)
|
cuid_(cuid)
|
||||||
{}
|
{}
|
||||||
|
@ -131,7 +131,7 @@ class FindChokedPiece {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Peer> peer_;
|
std::shared_ptr<Peer> peer_;
|
||||||
public:
|
public:
|
||||||
FindChokedPiece(const std::shared_ptr<Peer>& peer):peer_(peer) {}
|
FindChokedPiece(std::shared_ptr<Peer> peer):peer_(std::move(peer)) {}
|
||||||
|
|
||||||
bool operator()(const std::shared_ptr<Piece>& piece)
|
bool operator()(const std::shared_ptr<Piece>& piece)
|
||||||
{
|
{
|
||||||
|
|
|
@ -163,7 +163,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
|
||||||
std::shared_ptr<Piece> p(new Piece());
|
std::shared_ptr<Piece> p(new Piece());
|
||||||
p->setIndex(index);
|
p->setIndex(index);
|
||||||
|
|
||||||
UsedPieceSet::iterator i = usedPieces_.find(p);
|
auto i = usedPieces_.find(p);
|
||||||
if(i == usedPieces_.end()) {
|
if(i == usedPieces_.end()) {
|
||||||
p.reset();
|
p.reset();
|
||||||
return p;
|
return p;
|
||||||
|
|
|
@ -54,7 +54,7 @@ void splitNsName(const char** localname, const char** nsUri, const char* src)
|
||||||
if(sep) {
|
if(sep) {
|
||||||
*localname = sep+1;
|
*localname = sep+1;
|
||||||
size_t nsUriLen = sep-src;
|
size_t nsUriLen = sep-src;
|
||||||
char* temp = new char[nsUriLen+1];
|
auto temp = new char[nsUriLen + 1];
|
||||||
memcpy(temp, src, nsUriLen);
|
memcpy(temp, src, nsUriLen);
|
||||||
temp[nsUriLen] = '\0';
|
temp[nsUriLen] = '\0';
|
||||||
*nsUri = temp;
|
*nsUri = temp;
|
||||||
|
@ -71,10 +71,10 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
|
||||||
std::vector<XmlAttr> xmlAttrs;
|
std::vector<XmlAttr> xmlAttrs;
|
||||||
if(attrs) {
|
if(attrs) {
|
||||||
const char** p = attrs;
|
const char** p = attrs;
|
||||||
while(*p != 0) {
|
while(*p) {
|
||||||
XmlAttr xa;
|
XmlAttr xa;
|
||||||
const char* attrNsName = *p++;
|
const char* attrNsName = *p++;
|
||||||
if(*p == 0) {
|
if(!*p) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
splitNsName(&xa.localname, &xa.nsUri, attrNsName);
|
splitNsName(&xa.localname, &xa.nsUri, attrNsName);
|
||||||
|
@ -84,15 +84,14 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
|
||||||
xmlAttrs.push_back(xa);
|
xmlAttrs.push_back(xa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char* localname = 0;
|
const char* localname = nullptr;
|
||||||
const char* prefix = 0;
|
const char* prefix = nullptr;
|
||||||
const char* nsUri = 0;
|
const char* nsUri = nullptr;
|
||||||
splitNsName(&localname, &nsUri, nsName);
|
splitNsName(&localname, &nsUri, nsName);
|
||||||
sd->psm->beginElement(localname, prefix, nsUri, xmlAttrs);
|
sd->psm->beginElement(localname, prefix, nsUri, xmlAttrs);
|
||||||
delete [] nsUri;
|
delete [] nsUri;
|
||||||
for(std::vector<XmlAttr>::iterator i = xmlAttrs.begin(),
|
for(auto& a: xmlAttrs) {
|
||||||
eoi = xmlAttrs.end(); i != eoi; ++i) {
|
delete [] a.nsUri;
|
||||||
delete [] (*i).nsUri;
|
|
||||||
}
|
}
|
||||||
if(sd->psm->needsCharactersBuffering()) {
|
if(sd->psm->needsCharactersBuffering()) {
|
||||||
sd->charactersStack.push_front(A2STR::NIL);
|
sd->charactersStack.push_front(A2STR::NIL);
|
||||||
|
@ -103,9 +102,9 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
|
||||||
namespace {
|
namespace {
|
||||||
void mlEndElement(void* userData, const char* nsName)
|
void mlEndElement(void* userData, const char* nsName)
|
||||||
{
|
{
|
||||||
const char* localname = 0;
|
const char* localname = nullptr;
|
||||||
const char* prefix = 0;
|
const char* prefix = nullptr;
|
||||||
const char* nsUri = 0;
|
const char* nsUri = nullptr;
|
||||||
splitNsName(&localname, &nsUri, nsName);
|
splitNsName(&localname, &nsUri, nsName);
|
||||||
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
SessionData* sd = reinterpret_cast<SessionData*>(userData);
|
||||||
std::string characters;
|
std::string characters;
|
||||||
|
@ -140,7 +139,7 @@ void setupParser(XML_Parser parser, SessionData *sd)
|
||||||
XmlParser::XmlParser(ParserStateMachine* psm)
|
XmlParser::XmlParser(ParserStateMachine* psm)
|
||||||
: psm_(psm),
|
: psm_(psm),
|
||||||
sessionData_(psm_),
|
sessionData_(psm_),
|
||||||
ctx_(XML_ParserCreateNS(0, static_cast<const XML_Char>('\t'))),
|
ctx_(XML_ParserCreateNS(nullptr, static_cast<const XML_Char>('\t'))),
|
||||||
lastError_(0)
|
lastError_(0)
|
||||||
{
|
{
|
||||||
setupParser(ctx_, &sessionData_);
|
setupParser(ctx_, &sessionData_);
|
||||||
|
@ -181,7 +180,7 @@ int XmlParser::reset()
|
||||||
{
|
{
|
||||||
psm_->reset();
|
psm_->reset();
|
||||||
sessionData_.reset();
|
sessionData_.reset();
|
||||||
XML_Bool rv = XML_ParserReset(ctx_, 0);
|
XML_Bool rv = XML_ParserReset(ctx_, nullptr);
|
||||||
if(rv == XML_FALSE) {
|
if(rv == XML_FALSE) {
|
||||||
return lastError_ = ERR_RESET;
|
return lastError_ = ERR_RESET;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -197,8 +197,8 @@ FileEntry::getRequest
|
||||||
// sleeping(Request::getWakeTime() < global::wallclock()). If all
|
// sleeping(Request::getWakeTime() < global::wallclock()). If all
|
||||||
// pooled objects are sleeping, return first one. Caller should
|
// pooled objects are sleeping, return first one. Caller should
|
||||||
// inspect returned object's getWakeTime().
|
// inspect returned object's getWakeTime().
|
||||||
RequestPool::iterator i = requestPool_.begin();
|
auto i = requestPool_.begin();
|
||||||
RequestPool::iterator eoi = requestPool_.end();
|
auto eoi = requestPool_.end();
|
||||||
for(; i != eoi; ++i) {
|
for(; i != eoi; ++i) {
|
||||||
if((*i)->getWakeTime() <= global::wallclock()) {
|
if((*i)->getWakeTime() <= global::wallclock()) {
|
||||||
break;
|
break;
|
||||||
|
@ -494,10 +494,10 @@ bool FileEntry::removeUri(const std::string& uri)
|
||||||
}
|
}
|
||||||
spentUris_.erase(itr);
|
spentUris_.erase(itr);
|
||||||
std::shared_ptr<Request> req;
|
std::shared_ptr<Request> req;
|
||||||
InFlightRequestSet::iterator riter =
|
auto riter =
|
||||||
findRequestByUri(inFlightRequests_.begin(), inFlightRequests_.end(), uri);
|
findRequestByUri(inFlightRequests_.begin(), inFlightRequests_.end(), uri);
|
||||||
if(riter == inFlightRequests_.end()) {
|
if(riter == inFlightRequests_.end()) {
|
||||||
RequestPool::iterator riter = findRequestByUri(requestPool_.begin(),
|
auto riter = findRequestByUri(requestPool_.begin(),
|
||||||
requestPool_.end(), uri);
|
requestPool_.end(), uri);
|
||||||
if(riter == requestPool_.end()) {
|
if(riter == requestPool_.end()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
* files in the program, then also delete it here.
|
* files in the program, then also delete it here.
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
|
|
||||||
#include "HttpDownloadCommand.h"
|
#include "HttpDownloadCommand.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
|
|
|
@ -441,10 +441,9 @@ bool HttpRequest::conditionalRequest() const
|
||||||
if(!ifModSinceHeader_.empty()) {
|
if(!ifModSinceHeader_.empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(auto i = headers_.begin(),
|
for(auto& h : headers_) {
|
||||||
eoi = headers_.end(); i != eoi; ++i) {
|
if(util::istartsWith(h, "if-modified-since") ||
|
||||||
if(util::istartsWith(*i, "if-modified-since") ||
|
util::istartsWith(h, "if-none-match")) {
|
||||||
util::istartsWith(*i, "if-none-match")) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,11 +141,10 @@ void KqueueEventPoll::poll(const struct timeval& tv)
|
||||||
// own timeout and ares may create new sockets or closes socket in
|
// own timeout and ares may create new sockets or closes socket in
|
||||||
// their API. So we call ares_process_fd for all ares_channel and
|
// their API. So we call ares_process_fd for all ares_channel and
|
||||||
// re-register their sockets.
|
// re-register their sockets.
|
||||||
for(KAsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
|
for(auto & r : nameResolverEntries_) {
|
||||||
eoi = nameResolverEntries_.end(); i != eoi; ++i) {
|
r->processTimeout();
|
||||||
(*i)->processTimeout();
|
r->removeSocketEvents(this);
|
||||||
(*i)->removeSocketEvents(this);
|
r->addSocketEvents(this);
|
||||||
(*i)->addSocketEvents(this);
|
|
||||||
}
|
}
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ bool KqueueEventPoll::addEvents
|
||||||
(sock_t socket, const KqueueEventPoll::KEvent& event)
|
(sock_t socket, const KqueueEventPoll::KEvent& event)
|
||||||
{
|
{
|
||||||
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
||||||
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
|
auto i = socketEntries_.lower_bound(socketEntry);
|
||||||
int r = 0;
|
int r = 0;
|
||||||
struct timespec zeroTimeout = { 0, 0 };
|
struct timespec zeroTimeout = { 0, 0 };
|
||||||
struct kevent changelist[2];
|
struct kevent changelist[2];
|
||||||
|
@ -220,7 +219,7 @@ bool KqueueEventPoll::deleteEvents(sock_t socket,
|
||||||
const KqueueEventPoll::KEvent& event)
|
const KqueueEventPoll::KEvent& event)
|
||||||
{
|
{
|
||||||
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
||||||
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
|
auto i = socketEntries_.find(socketEntry);
|
||||||
if(i == socketEntries_.end()) {
|
if(i == socketEntries_.end()) {
|
||||||
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
||||||
return false;
|
return false;
|
||||||
|
@ -266,7 +265,7 @@ bool KqueueEventPoll::addNameResolver
|
||||||
{
|
{
|
||||||
std::shared_ptr<KAsyncNameResolverEntry> entry
|
std::shared_ptr<KAsyncNameResolverEntry> entry
|
||||||
(new KAsyncNameResolverEntry(resolver, command));
|
(new KAsyncNameResolverEntry(resolver, command));
|
||||||
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
|
auto itr = nameResolverEntries_.find(entry);
|
||||||
if(itr == nameResolverEntries_.end()) {
|
if(itr == nameResolverEntries_.end()) {
|
||||||
nameResolverEntries_.insert(entry);
|
nameResolverEntries_.insert(entry);
|
||||||
entry->addSocketEvents(this);
|
entry->addSocketEvents(this);
|
||||||
|
@ -281,7 +280,7 @@ bool KqueueEventPoll::deleteNameResolver
|
||||||
{
|
{
|
||||||
std::shared_ptr<KAsyncNameResolverEntry> entry
|
std::shared_ptr<KAsyncNameResolverEntry> entry
|
||||||
(new KAsyncNameResolverEntry(resolver, command));
|
(new KAsyncNameResolverEntry(resolver, command));
|
||||||
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
|
auto itr = nameResolverEntries_.find(entry);
|
||||||
if(itr == nameResolverEntries_.end()) {
|
if(itr == nameResolverEntries_.end()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ bool LibuvEventPoll::addEvents(sock_t socket,
|
||||||
|
|
||||||
if (i != socketEntries_.end() && **i == *socketEntry) {
|
if (i != socketEntries_.end() && **i == *socketEntry) {
|
||||||
event.addSelf(*i);
|
event.addSelf(*i);
|
||||||
KPolls::iterator poll = polls_.find(socket);
|
auto poll = polls_.find(socket);
|
||||||
if (poll == polls_.end()) {
|
if (poll == polls_.end()) {
|
||||||
throw std::logic_error("Invalid socket");
|
throw std::logic_error("Invalid socket");
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ namespace {
|
||||||
struct HashTypeEntry {
|
struct HashTypeEntry {
|
||||||
std::string hashType;
|
std::string hashType;
|
||||||
int strength;
|
int strength;
|
||||||
HashTypeEntry(const std::string& hashType, int strength):
|
HashTypeEntry(std::string hashType, int strength):
|
||||||
hashType(hashType), strength(strength) {}
|
hashType(std::move(hashType)), strength(strength) {}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -247,14 +247,13 @@ void OptionParser::parse(Option& option, std::istream& is) const
|
||||||
|
|
||||||
void OptionParser::parse(Option& option, const KeyVals& options) const
|
void OptionParser::parse(Option& option, const KeyVals& options) const
|
||||||
{
|
{
|
||||||
for(KeyVals::const_iterator i = options.begin(), eoi = options.end();
|
for(const auto& o : options) {
|
||||||
i != eoi; ++i) {
|
auto pref = option::k2p(o.first);
|
||||||
PrefPtr pref = option::k2p((*i).first);
|
|
||||||
const OptionHandler* handler = find(pref);
|
const OptionHandler* handler = find(pref);
|
||||||
if(handler) {
|
if(handler) {
|
||||||
handler->parse(option, (*i).second);
|
handler->parse(option, o.second);
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_WARN(fmt("Unknown option: %s", (*i).first.c_str()));
|
A2_LOG_WARN(fmt("Unknown option: %s", o.first.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/Piece.cc
11
src/Piece.cc
|
@ -279,13 +279,12 @@ std::string Piece::getDigestWithWrCache
|
||||||
int64_t goff = start;
|
int64_t goff = start;
|
||||||
if(wrCache_) {
|
if(wrCache_) {
|
||||||
const WrDiskCacheEntry::DataCellSet& dataSet = wrCache_->getDataSet();
|
const WrDiskCacheEntry::DataCellSet& dataSet = wrCache_->getDataSet();
|
||||||
for(WrDiskCacheEntry::DataCellSet::iterator i = dataSet.begin(),
|
for(auto& d : dataSet) {
|
||||||
eoi = dataSet.end(); i != eoi; ++i) {
|
if(goff < d->goff) {
|
||||||
if(goff < (*i)->goff) {
|
updateHashWithRead(mdctx.get(), adaptor, goff, d->goff - goff);
|
||||||
updateHashWithRead(mdctx.get(), adaptor, goff, (*i)->goff - goff);
|
|
||||||
}
|
}
|
||||||
mdctx->update((*i)->data+(*i)->offset, (*i)->len);
|
mdctx->update(d->data + d->offset, d->len);
|
||||||
goff = (*i)->goff + (*i)->len;
|
goff = d->goff + d->len;
|
||||||
}
|
}
|
||||||
updateHashWithRead(mdctx.get(), adaptor, goff, start+length_-goff);
|
updateHashWithRead(mdctx.get(), adaptor, goff, start+length_-goff);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -101,7 +101,7 @@ void PollEventPoll::poll(const struct timeval& tv)
|
||||||
first != last; ++first) {
|
first != last; ++first) {
|
||||||
if(first->revents) {
|
if(first->revents) {
|
||||||
se->setSocket(first->fd);
|
se->setSocket(first->fd);
|
||||||
KSocketEntrySet::iterator itr = socketEntries_.find(se);
|
auto itr = socketEntries_.find(se);
|
||||||
if(itr == socketEntries_.end()) {
|
if(itr == socketEntries_.end()) {
|
||||||
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.",
|
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.",
|
||||||
first->fd));
|
first->fd));
|
||||||
|
@ -119,11 +119,10 @@ void PollEventPoll::poll(const struct timeval& tv)
|
||||||
// own timeout and ares may create new sockets or closes socket in
|
// own timeout and ares may create new sockets or closes socket in
|
||||||
// their API. So we call ares_process_fd for all ares_channel and
|
// their API. So we call ares_process_fd for all ares_channel and
|
||||||
// re-register their sockets.
|
// re-register their sockets.
|
||||||
for(KAsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
|
for(auto& r : nameResolverEntries_) {
|
||||||
eoi = nameResolverEntries_.end(); i != eoi; ++i) {
|
r->processTimeout();
|
||||||
(*i)->processTimeout();
|
r->removeSocketEvents(this);
|
||||||
(*i)->removeSocketEvents(this);
|
r->addSocketEvents(this);
|
||||||
(*i)->addSocketEvents(this);
|
|
||||||
}
|
}
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
|
@ -153,7 +152,7 @@ bool PollEventPoll::addEvents
|
||||||
(sock_t socket, const PollEventPoll::KEvent& event)
|
(sock_t socket, const PollEventPoll::KEvent& event)
|
||||||
{
|
{
|
||||||
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
||||||
KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
|
auto i = socketEntries_.lower_bound(socketEntry);
|
||||||
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
|
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
|
||||||
event.addSelf(*i);
|
event.addSelf(*i);
|
||||||
for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_;
|
for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_;
|
||||||
|
@ -199,7 +198,7 @@ bool PollEventPoll::deleteEvents
|
||||||
(sock_t socket, const PollEventPoll::KEvent& event)
|
(sock_t socket, const PollEventPoll::KEvent& event)
|
||||||
{
|
{
|
||||||
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
|
||||||
KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
|
auto i = socketEntries_.find(socketEntry);
|
||||||
if(i == socketEntries_.end()) {
|
if(i == socketEntries_.end()) {
|
||||||
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
||||||
return false;
|
return false;
|
||||||
|
@ -245,8 +244,7 @@ bool PollEventPoll::addNameResolver
|
||||||
{
|
{
|
||||||
std::shared_ptr<KAsyncNameResolverEntry> entry
|
std::shared_ptr<KAsyncNameResolverEntry> entry
|
||||||
(new KAsyncNameResolverEntry(resolver, command));
|
(new KAsyncNameResolverEntry(resolver, command));
|
||||||
KAsyncNameResolverEntrySet::iterator itr =
|
auto itr = nameResolverEntries_.lower_bound(entry);
|
||||||
nameResolverEntries_.lower_bound(entry);
|
|
||||||
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
|
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -261,7 +259,7 @@ bool PollEventPoll::deleteNameResolver
|
||||||
{
|
{
|
||||||
std::shared_ptr<KAsyncNameResolverEntry> entry
|
std::shared_ptr<KAsyncNameResolverEntry> entry
|
||||||
(new KAsyncNameResolverEntry(resolver, command));
|
(new KAsyncNameResolverEntry(resolver, command));
|
||||||
KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
|
auto itr = nameResolverEntries_.find(entry);
|
||||||
if(itr == nameResolverEntries_.end()) {
|
if(itr == nameResolverEntries_.end()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -44,10 +44,9 @@ PriorityPieceSelector::PriorityPieceSelector
|
||||||
bool PriorityPieceSelector::select
|
bool PriorityPieceSelector::select
|
||||||
(size_t& index, const unsigned char* bitfield, size_t nbits) const
|
(size_t& index, const unsigned char* bitfield, size_t nbits) const
|
||||||
{
|
{
|
||||||
for(auto i = prioritizedPieces_.begin(), eoi = prioritizedPieces_.end();
|
for(auto& p : prioritizedPieces_) {
|
||||||
i != eoi; ++i) {
|
if(bitfield::test(bitfield, nbits, p)) {
|
||||||
if(bitfield::test(bitfield, nbits, *i)) {
|
index = p;
|
||||||
index = *i;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -574,8 +574,7 @@ void RequestGroup::initPieceStorage()
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
)) {
|
)) {
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
auto ps =
|
auto ps = new DefaultPieceStorage(downloadContext_, option_.get());
|
||||||
new DefaultPieceStorage(downloadContext_, option_.get());
|
|
||||||
std::shared_ptr<PieceStorage> psHolder(ps);
|
std::shared_ptr<PieceStorage> psHolder(ps);
|
||||||
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
|
||||||
if(isUriSuppliedForRequsetFileEntry
|
if(isUriSuppliedForRequsetFileEntry
|
||||||
|
@ -616,8 +615,7 @@ void RequestGroup::initPieceStorage()
|
||||||
}
|
}
|
||||||
tempPieceStorage.swap(psHolder);
|
tempPieceStorage.swap(psHolder);
|
||||||
} else {
|
} else {
|
||||||
auto ps =
|
auto ps = new UnknownLengthPieceStorage(downloadContext_);
|
||||||
new UnknownLengthPieceStorage(downloadContext_);
|
|
||||||
std::shared_ptr<PieceStorage> psHolder(ps);
|
std::shared_ptr<PieceStorage> psHolder(ps);
|
||||||
if(diskWriterFactory_) {
|
if(diskWriterFactory_) {
|
||||||
ps->setDiskWriterFactory(diskWriterFactory_);
|
ps->setDiskWriterFactory(diskWriterFactory_);
|
||||||
|
|
|
@ -76,9 +76,8 @@ void encodeValue(const ValueBase* value, OutputStream& o)
|
||||||
virtual void visit(const List& v) CXX11_OVERRIDE
|
virtual void visit(const List& v) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
o_ << "<value><array><data>";
|
o_ << "<value><array><data>";
|
||||||
for(List::ValueType::const_iterator i = v.begin(), eoi = v.end();
|
for(const auto& e: v) {
|
||||||
i != eoi; ++i) {
|
e->accept(*this);
|
||||||
(*i)->accept(*this);
|
|
||||||
}
|
}
|
||||||
o_ << "</data></array></value>";
|
o_ << "</data></array></value>";
|
||||||
}
|
}
|
||||||
|
@ -86,10 +85,9 @@ void encodeValue(const ValueBase* value, OutputStream& o)
|
||||||
virtual void visit(const Dict& v) CXX11_OVERRIDE
|
virtual void visit(const Dict& v) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
o_ << "<value><struct>";
|
o_ << "<value><struct>";
|
||||||
for(Dict::ValueType::const_iterator i = v.begin(), eoi = v.end();
|
for(const auto& e: v) {
|
||||||
i != eoi; ++i) {
|
o_ << "<member><name>" << util::htmlEscape(e.first) << "</name>";
|
||||||
o_ << "<member><name>" << util::htmlEscape((*i).first) << "</name>";
|
e.second->accept(*this);
|
||||||
(*i).second->accept(*this);
|
|
||||||
o_ << "</member>";
|
o_ << "</member>";
|
||||||
}
|
}
|
||||||
o_ << "</struct></value>";
|
o_ << "</struct></value>";
|
||||||
|
|
|
@ -302,8 +302,8 @@ void SegmentMan::cancelSegmentInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
void SegmentMan::cancelSegment(cuid_t cuid) {
|
void SegmentMan::cancelSegment(cuid_t cuid) {
|
||||||
for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(),
|
for(auto itr = usedSegmentEntries_.begin(), eoi = usedSegmentEntries_.end();
|
||||||
eoi = usedSegmentEntries_.end(); itr != eoi;) {
|
itr != eoi;) {
|
||||||
if((*itr)->cuid == cuid) {
|
if((*itr)->cuid == cuid) {
|
||||||
cancelSegmentInternal(cuid, (*itr)->segment);
|
cancelSegmentInternal(cuid, (*itr)->segment);
|
||||||
itr = usedSegmentEntries_.erase(itr);
|
itr = usedSegmentEntries_.erase(itr);
|
||||||
|
@ -317,7 +317,7 @@ void SegmentMan::cancelSegment(cuid_t cuid) {
|
||||||
void SegmentMan::cancelSegment
|
void SegmentMan::cancelSegment
|
||||||
(cuid_t cuid, const std::shared_ptr<Segment>& segment)
|
(cuid_t cuid, const std::shared_ptr<Segment>& segment)
|
||||||
{
|
{
|
||||||
for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(),
|
for(auto itr = usedSegmentEntries_.begin(),
|
||||||
eoi = usedSegmentEntries_.end(); itr != eoi;) {
|
eoi = usedSegmentEntries_.end(); itr != eoi;) {
|
||||||
if((*itr)->cuid == cuid && *(*itr)->segment == *segment) {
|
if((*itr)->cuid == cuid && *(*itr)->segment == *segment) {
|
||||||
cancelSegmentInternal(cuid, (*itr)->segment);
|
cancelSegmentInternal(cuid, (*itr)->segment);
|
||||||
|
@ -331,9 +331,8 @@ void SegmentMan::cancelSegment
|
||||||
|
|
||||||
void SegmentMan::cancelAllSegments()
|
void SegmentMan::cancelAllSegments()
|
||||||
{
|
{
|
||||||
for(auto itr = usedSegmentEntries_.begin(), eoi = usedSegmentEntries_.end();
|
for(auto& e: usedSegmentEntries_) {
|
||||||
itr != eoi; ++itr) {
|
cancelSegmentInternal(e->cuid, e->segment);
|
||||||
cancelSegmentInternal((*itr)->cuid, (*itr)->segment);
|
|
||||||
}
|
}
|
||||||
usedSegmentEntries_.clear();
|
usedSegmentEntries_.clear();
|
||||||
}
|
}
|
||||||
|
@ -361,7 +360,7 @@ bool SegmentMan::completeSegment
|
||||||
(cuid_t cuid, const std::shared_ptr<Segment>& segment) {
|
(cuid_t cuid, const std::shared_ptr<Segment>& segment) {
|
||||||
pieceStorage_->completePiece(segment->getPiece());
|
pieceStorage_->completePiece(segment->getPiece());
|
||||||
pieceStorage_->advertisePiece(cuid, segment->getPiece()->getIndex());
|
pieceStorage_->advertisePiece(cuid, segment->getPiece()->getIndex());
|
||||||
SegmentEntries::iterator itr = std::find_if(usedSegmentEntries_.begin(),
|
auto itr = std::find_if(usedSegmentEntries_.begin(),
|
||||||
usedSegmentEntries_.end(),
|
usedSegmentEntries_.end(),
|
||||||
FindSegmentEntry(segment));
|
FindSegmentEntry(segment));
|
||||||
if(itr == usedSegmentEntries_.end()) {
|
if(itr == usedSegmentEntries_.end()) {
|
||||||
|
@ -391,9 +390,9 @@ void SegmentMan::registerPeerStat(const std::shared_ptr<PeerStat>& peerStat)
|
||||||
|
|
||||||
std::shared_ptr<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
|
std::shared_ptr<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
|
||||||
{
|
{
|
||||||
for(auto i = peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
|
for(auto& e: peerStats_) {
|
||||||
if((*i)->getCuid() == cuid) {
|
if(e->getCuid() == cuid) {
|
||||||
return *i;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -177,9 +177,7 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
for(AsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.begin(),
|
for(auto& entry : nameResolverEntries_) {
|
||||||
eoi = nameResolverEntries_.end(); itr != eoi; ++itr) {
|
|
||||||
const std::shared_ptr<AsyncNameResolverEntry>& entry = *itr;
|
|
||||||
int fd = entry->getFds(&rfds, &wfds);
|
int fd = entry->getFds(&rfds, &wfds);
|
||||||
// TODO force error if fd == 0
|
// TODO force error if fd == 0
|
||||||
if(fdmax_ < fd) {
|
if(fdmax_ < fd) {
|
||||||
|
@ -198,16 +196,15 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
} while(retval == -1 && errno == EINTR);
|
} while(retval == -1 && errno == EINTR);
|
||||||
if(retval > 0) {
|
if(retval > 0) {
|
||||||
for(SocketEntrySet::iterator i = socketEntries_.begin(),
|
for(auto& e: socketEntries_) {
|
||||||
eoi = socketEntries_.end(); i != eoi; ++i) {
|
|
||||||
int events = 0;
|
int events = 0;
|
||||||
if(FD_ISSET((*i)->getSocket(), &rfds)) {
|
if(FD_ISSET(e->getSocket(), &rfds)) {
|
||||||
events |= EventPoll::EVENT_READ;
|
events |= EventPoll::EVENT_READ;
|
||||||
}
|
}
|
||||||
if(FD_ISSET((*i)->getSocket(), &wfds)) {
|
if(FD_ISSET(e->getSocket(), &wfds)) {
|
||||||
events |= EventPoll::EVENT_WRITE;
|
events |= EventPoll::EVENT_WRITE;
|
||||||
}
|
}
|
||||||
(*i)->processEvents(events);
|
e->processEvents(events);
|
||||||
}
|
}
|
||||||
} else if(retval == -1) {
|
} else if(retval == -1) {
|
||||||
int errNum = errno;
|
int errNum = errno;
|
||||||
|
@ -215,9 +212,8 @@ void SelectEventPoll::poll(const struct timeval& tv)
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
for(AsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
|
for(auto & e: nameResolverEntries_) {
|
||||||
eoi = nameResolverEntries_.end(); i != eoi; ++i) {
|
e->process(&rfds, &wfds);
|
||||||
(*i)->process(&rfds, &wfds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
@ -244,9 +240,8 @@ void SelectEventPoll::updateFdSet()
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
FD_ZERO(&rfdset_);
|
FD_ZERO(&rfdset_);
|
||||||
FD_ZERO(&wfdset_);
|
FD_ZERO(&wfdset_);
|
||||||
for(SocketEntrySet::iterator i = socketEntries_.begin(),
|
for(auto& e: socketEntries_) {
|
||||||
eoi = socketEntries_.end(); i != eoi; ++i) {
|
sock_t fd = e->getSocket();
|
||||||
sock_t fd = (*i)->getSocket();
|
|
||||||
#ifndef __MINGW32__
|
#ifndef __MINGW32__
|
||||||
if(fd < 0 || FD_SETSIZE <= fd) {
|
if(fd < 0 || FD_SETSIZE <= fd) {
|
||||||
A2_LOG_WARN("Detected file descriptor >= FD_SETSIZE or < 0. "
|
A2_LOG_WARN("Detected file descriptor >= FD_SETSIZE or < 0. "
|
||||||
|
@ -254,7 +249,7 @@ void SelectEventPoll::updateFdSet()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif // !__MINGW32__
|
#endif // !__MINGW32__
|
||||||
int events = (*i)->getEvents();
|
int events = e->getEvents();
|
||||||
if(events&EventPoll::EVENT_READ) {
|
if(events&EventPoll::EVENT_READ) {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
checkFdCountMingw(rfdset_);
|
checkFdCountMingw(rfdset_);
|
||||||
|
@ -277,7 +272,7 @@ bool SelectEventPoll::addEvents(sock_t socket, Command* command,
|
||||||
EventPoll::EventType events)
|
EventPoll::EventType events)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
|
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
|
||||||
SocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
|
auto i = socketEntries_.lower_bound(socketEntry);
|
||||||
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
|
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
|
||||||
(*i)->addCommandEvent(command, events);
|
(*i)->addCommandEvent(command, events);
|
||||||
} else {
|
} else {
|
||||||
|
@ -292,7 +287,7 @@ bool SelectEventPoll::deleteEvents(sock_t socket, Command* command,
|
||||||
EventPoll::EventType events)
|
EventPoll::EventType events)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
|
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
|
||||||
SocketEntrySet::iterator i = socketEntries_.find(socketEntry);
|
auto i = socketEntries_.find(socketEntry);
|
||||||
if(i == socketEntries_.end()) {
|
if(i == socketEntries_.end()) {
|
||||||
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
||||||
return false;
|
return false;
|
||||||
|
@ -312,8 +307,7 @@ bool SelectEventPoll::addNameResolver
|
||||||
{
|
{
|
||||||
std::shared_ptr<AsyncNameResolverEntry> entry
|
std::shared_ptr<AsyncNameResolverEntry> entry
|
||||||
(new AsyncNameResolverEntry(resolver, command));
|
(new AsyncNameResolverEntry(resolver, command));
|
||||||
AsyncNameResolverEntrySet::iterator itr =
|
auto itr = nameResolverEntries_.lower_bound(entry);
|
||||||
nameResolverEntries_.lower_bound(entry);
|
|
||||||
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
|
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,7 +60,7 @@ std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
|
||||||
const std::string& protocol) const
|
const std::string& protocol) const
|
||||||
{
|
{
|
||||||
std::shared_ptr<ServerStat> ss(new ServerStat(hostname, protocol));
|
std::shared_ptr<ServerStat> ss(new ServerStat(hostname, protocol));
|
||||||
ServerStatSet::iterator i = serverStats_.find(ss);
|
auto i = serverStats_.find(ss);
|
||||||
if(i == serverStats_.end()) {
|
if(i == serverStats_.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,7 +70,7 @@ std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
|
||||||
|
|
||||||
bool ServerStatMan::add(const std::shared_ptr<ServerStat>& serverStat)
|
bool ServerStatMan::add(const std::shared_ptr<ServerStat>& serverStat)
|
||||||
{
|
{
|
||||||
ServerStatSet::iterator i = serverStats_.lower_bound(serverStat);
|
auto i = serverStats_.lower_bound(serverStat);
|
||||||
if(i != serverStats_.end() && *(*i) == *serverStat) {
|
if(i != serverStats_.end() && *(*i) == *serverStat) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,9 +90,8 @@ bool ServerStatMan::save(const std::string& filename) const
|
||||||
filename.c_str()));
|
filename.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(ServerStatSet::iterator i = serverStats_.begin(),
|
for(auto& e: serverStats_) {
|
||||||
eoi = serverStats_.end(); i != eoi; ++i) {
|
std::string l = e->toString();
|
||||||
std::string l = (*i)->toString();
|
|
||||||
l += "\n";
|
l += "\n";
|
||||||
if(fp.write(l.data(), l.size()) != l.size()) {
|
if(fp.write(l.data(), l.size()) != l.size()) {
|
||||||
A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
|
A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
|
||||||
|
@ -252,8 +251,7 @@ public:
|
||||||
void ServerStatMan::removeStaleServerStat(time_t timeout)
|
void ServerStatMan::removeStaleServerStat(time_t timeout)
|
||||||
{
|
{
|
||||||
FindStaleServerStat finder(timeout);
|
FindStaleServerStat finder(timeout);
|
||||||
for(ServerStatSet::iterator i = serverStats_.begin(),
|
for(auto i = serverStats_.begin(), eoi = serverStats_.end(); i != eoi;) {
|
||||||
eoi = serverStats_.end(); i != eoi;) {
|
|
||||||
if(finder(*i)) {
|
if(finder(*i)) {
|
||||||
serverStats_.erase(i++);
|
serverStats_.erase(i++);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -266,9 +266,7 @@ bool SessionSerializer::save(IOFile& fp) const
|
||||||
{
|
{
|
||||||
std::set<a2_gid_t> metainfoCache;
|
std::set<a2_gid_t> metainfoCache;
|
||||||
const DownloadResultList& results = rgman_->getDownloadResults();
|
const DownloadResultList& results = rgman_->getDownloadResults();
|
||||||
for(DownloadResultList::const_iterator itr = results.begin(),
|
for(const auto& dr : results) {
|
||||||
eoi = results.end(); itr != eoi; ++itr) {
|
|
||||||
const std::shared_ptr<DownloadResult>& dr = *itr;
|
|
||||||
if(dr->result == error_code::FINISHED ||
|
if(dr->result == error_code::FINISHED ||
|
||||||
dr->result == error_code::REMOVED) {
|
dr->result == error_code::REMOVED) {
|
||||||
if(dr->option->getAsBool(PREF_FORCE_SAVE)) {
|
if(dr->option->getAsBool(PREF_FORCE_SAVE)) {
|
||||||
|
@ -296,9 +294,7 @@ bool SessionSerializer::save(IOFile& fp) const
|
||||||
{
|
{
|
||||||
// Save active downloads.
|
// Save active downloads.
|
||||||
const RequestGroupList& groups = rgman_->getRequestGroups();
|
const RequestGroupList& groups = rgman_->getRequestGroups();
|
||||||
for(RequestGroupList::const_iterator itr = groups.begin(),
|
for(const auto& rg : groups) {
|
||||||
eoi = groups.end(); itr != eoi; ++itr) {
|
|
||||||
const std::shared_ptr<RequestGroup>& rg = *itr;
|
|
||||||
std::shared_ptr<DownloadResult> dr = rg->createDownloadResult();
|
std::shared_ptr<DownloadResult> dr = rg->createDownloadResult();
|
||||||
bool stopped = dr->result == error_code::FINISHED ||
|
bool stopped = dr->result == error_code::FINISHED ||
|
||||||
dr->result == error_code::REMOVED;
|
dr->result == error_code::REMOVED;
|
||||||
|
@ -312,9 +308,7 @@ bool SessionSerializer::save(IOFile& fp) const
|
||||||
}
|
}
|
||||||
if(saveWaiting_) {
|
if(saveWaiting_) {
|
||||||
const RequestGroupList& groups = rgman_->getReservedGroups();
|
const RequestGroupList& groups = rgman_->getReservedGroups();
|
||||||
for(RequestGroupList::const_iterator itr = groups.begin(),
|
for(const auto& rg : groups) {
|
||||||
eoi = groups.end(); itr != eoi; ++itr) {
|
|
||||||
const std::shared_ptr<RequestGroup>& rg = *itr;
|
|
||||||
std::shared_ptr<DownloadResult> result = rg->createDownloadResult();
|
std::shared_ptr<DownloadResult> result = rg->createDownloadResult();
|
||||||
if(!writeDownloadResult(fp, metainfoCache, result)) {
|
if(!writeDownloadResult(fp, metainfoCache, result)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1175,9 +1175,9 @@ bool verifyHostname(const std::string& hostname,
|
||||||
if(addrLen == 0) {
|
if(addrLen == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(auto i = ipAddrs.begin(), eoi = ipAddrs.end(); i != eoi; ++i) {
|
for(auto& ipAddr : ipAddrs) {
|
||||||
if(addrLen == (*i).size() &&
|
if(addrLen == ipAddr.size() &&
|
||||||
memcmp(binAddr, (*i).c_str(), addrLen) == 0) {
|
memcmp(binAddr, ipAddr.c_str(), addrLen) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1187,8 +1187,8 @@ bool verifyHostname(const std::string& hostname,
|
||||||
if(dnsNames.empty()) {
|
if(dnsNames.empty()) {
|
||||||
return util::tlsHostnameMatch(commonName, hostname);
|
return util::tlsHostnameMatch(commonName, hostname);
|
||||||
}
|
}
|
||||||
for(auto i = dnsNames.begin(), eoi = dnsNames.end(); i != eoi; ++i) {
|
for(auto& dnsName : dnsNames) {
|
||||||
if(util::tlsHostnameMatch(*i, hostname)) {
|
if(util::tlsHostnameMatch(dnsName, hostname)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,11 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename):db_(0)
|
Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename) : db_(nullptr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef HAVE_SQLITE3_OPEN_V2
|
#ifdef HAVE_SQLITE3_OPEN_V2
|
||||||
ret = sqlite3_open_v2(filename.c_str(), &db_, SQLITE_OPEN_READONLY, 0);
|
ret = sqlite3_open_v2(filename.c_str(), &db_, SQLITE_OPEN_READONLY, nullptr);
|
||||||
#else // !HAVE_SQLITE3_OPEN_V2
|
#else // !HAVE_SQLITE3_OPEN_V2
|
||||||
if(!File(filename).isFile()) {
|
if(!File(filename).isFile()) {
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +61,7 @@ Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename):db_(0)
|
||||||
#endif // !HAVE_SQLITE3_OPEN_V2
|
#endif // !HAVE_SQLITE3_OPEN_V2
|
||||||
if(SQLITE_OK != ret) {
|
if(SQLITE_OK != ret) {
|
||||||
sqlite3_close(db_);
|
sqlite3_close(db_);
|
||||||
db_ = 0;
|
db_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ std::vector<std::unique_ptr<Cookie>> Sqlite3CookieParser::parse()
|
||||||
throw DL_ABORT_EX(fmt("SQLite3 database is not opened."));
|
throw DL_ABORT_EX(fmt("SQLite3 database is not opened."));
|
||||||
}
|
}
|
||||||
auto tcookies = std::vector<std::unique_ptr<Cookie>>{};
|
auto tcookies = std::vector<std::unique_ptr<Cookie>>{};
|
||||||
char* sqlite3ErrMsg = 0;
|
char* sqlite3ErrMsg = nullptr;
|
||||||
int ret = sqlite3_exec(db_, getQuery(), cookieRowMapper,
|
int ret = sqlite3_exec(db_, getQuery(), cookieRowMapper,
|
||||||
&tcookies, &sqlite3ErrMsg);
|
&tcookies, &sqlite3ErrMsg);
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
|
|
|
@ -108,8 +108,8 @@ size_t UTMetadataRequestTracker::avail() const
|
||||||
std::vector<size_t> UTMetadataRequestTracker::getAllTrackedIndex() const
|
std::vector<size_t> UTMetadataRequestTracker::getAllTrackedIndex() const
|
||||||
{
|
{
|
||||||
std::vector<size_t> indexes;
|
std::vector<size_t> indexes;
|
||||||
for(auto i = trackedRequests_.begin(), eoi = trackedRequests_.end(); i != eoi; ++i) {
|
for(auto& e: trackedRequests_) {
|
||||||
indexes.push_back((*i).index_);
|
indexes.push_back(e.index_);
|
||||||
}
|
}
|
||||||
return indexes;
|
return indexes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ bool WrDiskCache::update(WrDiskCacheEntry* ent, ssize_t delta)
|
||||||
void WrDiskCache::ensureLimit()
|
void WrDiskCache::ensureLimit()
|
||||||
{
|
{
|
||||||
while(total_ > limit_) {
|
while(total_ > limit_) {
|
||||||
EntrySet::iterator i = set_.begin();
|
auto i = set_.begin();
|
||||||
WrDiskCacheEntry* ent = *i;
|
WrDiskCacheEntry* ent = *i;
|
||||||
A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%" PRId64,
|
A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%" PRId64,
|
||||||
static_cast<unsigned long>(ent->getSizeKey()),
|
static_cast<unsigned long>(ent->getSizeKey()),
|
||||||
|
|
|
@ -65,10 +65,9 @@ WrDiskCacheEntry::~WrDiskCacheEntry()
|
||||||
|
|
||||||
void WrDiskCacheEntry::deleteDataCells()
|
void WrDiskCacheEntry::deleteDataCells()
|
||||||
{
|
{
|
||||||
for(DataCellSet::iterator i = set_.begin(), eoi = set_.end(); i != eoi;
|
for(auto& e: set_) {
|
||||||
++i) {
|
delete [] e->data;
|
||||||
delete [] (*i)->data;
|
delete e;
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
set_.clear();
|
set_.clear();
|
||||||
size_ = 0;
|
size_ = 0;
|
||||||
|
@ -109,7 +108,7 @@ size_t WrDiskCacheEntry::append(int64_t goff, const unsigned char *data,
|
||||||
if(set_.empty()) {
|
if(set_.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DataCellSet::iterator i = set_.end();
|
auto i = set_.end();
|
||||||
--i;
|
--i;
|
||||||
if(static_cast<int64_t>((*i)->goff + (*i)->len) == goff) {
|
if(static_cast<int64_t>((*i)->goff + (*i)->len) == goff) {
|
||||||
size_t wlen = std::min((*i)->capacity - (*i)->len, len);
|
size_t wlen = std::min((*i)->capacity - (*i)->len, len);
|
||||||
|
|
|
@ -53,9 +53,9 @@ std::string encode(const std::string& src)
|
||||||
std::string ret;
|
std::string ret;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
uint64_t buf = 0;
|
uint64_t buf = 0;
|
||||||
for(size_t i = 0; i < src.size(); ++i) {
|
for(const auto& ch: src) {
|
||||||
buf <<= 8;
|
buf <<= 8;
|
||||||
buf += src[i]&0xffu;
|
buf += ch & 0xffu;
|
||||||
++count;
|
++count;
|
||||||
if(count == 5) {
|
if(count == 5) {
|
||||||
char temp[8];
|
char temp[8];
|
||||||
|
|
|
@ -100,9 +100,8 @@ std::string encode(const ValueBase* vlb)
|
||||||
virtual void visit(const List& list) CXX11_OVERRIDE
|
virtual void visit(const List& list) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
out_ << "l";
|
out_ << "l";
|
||||||
for(List::ValueType::const_iterator i = list.begin(), eoi = list.end();
|
for(const auto& e: list){
|
||||||
i != eoi; ++i){
|
e->accept(*this);
|
||||||
(*i)->accept(*this);
|
|
||||||
}
|
}
|
||||||
out_ << "e";
|
out_ << "e";
|
||||||
}
|
}
|
||||||
|
@ -110,12 +109,11 @@ std::string encode(const ValueBase* vlb)
|
||||||
virtual void visit(const Dict& dict) CXX11_OVERRIDE
|
virtual void visit(const Dict& dict) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
out_ << "d";
|
out_ << "d";
|
||||||
for(Dict::ValueType::const_iterator i = dict.begin(), eoi = dict.end();
|
for(const auto& e: dict){
|
||||||
i != eoi; ++i){
|
auto& key = e.first;
|
||||||
const std::string& key = (*i).first;
|
|
||||||
out_ << key.size() << ":";
|
out_ << key.size() << ":";
|
||||||
out_.write(key.data(), key.size());
|
out_.write(key.data(), key.size());
|
||||||
(*i).second->accept(*this);
|
e.second->accept(*this);
|
||||||
}
|
}
|
||||||
out_ << "e";
|
out_ << "e";
|
||||||
}
|
}
|
||||||
|
|
|
@ -999,10 +999,9 @@ std::string torrent2Magnet(const TorrentAttribute* attrs)
|
||||||
uri += util::percentEncode(attrs->name);
|
uri += util::percentEncode(attrs->name);
|
||||||
}
|
}
|
||||||
for(auto & elem : attrs->announceList) {
|
for(auto & elem : attrs->announceList) {
|
||||||
for(auto uriIter = elem.begin(),
|
for(auto& e: elem) {
|
||||||
eoi2 = elem.end(); uriIter != eoi2; ++uriIter) {
|
|
||||||
uri += "&tr=";
|
uri += "&tr=";
|
||||||
uri += util::percentEncode(*uriIter);
|
uri += util::percentEncode(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uri;
|
return uri;
|
||||||
|
|
|
@ -1751,8 +1751,7 @@ std::string escapePath(const std::string& s)
|
||||||
{ '"', '*', ':', '<', '>', '?', '\\', '|' };
|
{ '"', '*', ':', '<', '>', '?', '\\', '|' };
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
std::string d;
|
std::string d;
|
||||||
for(std::string::const_iterator i = s.begin(), eoi = s.end(); i != eoi; ++i) {
|
for(const auto& c: s) {
|
||||||
unsigned char c = *i;
|
|
||||||
if(in(c, 0x00u, 0x1fu) || c == 0x7fu
|
if(in(c, 0x00u, 0x1fu) || c == 0x7fu
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|| std::find(std::begin(WIN_INVALID_PATH_CHARS),
|
|| std::find(std::begin(WIN_INVALID_PATH_CHARS),
|
||||||
|
@ -1762,7 +1761,7 @@ std::string escapePath(const std::string& s)
|
||||||
){
|
){
|
||||||
d += fmt("%%%02X", c);
|
d += fmt("%%%02X", c);
|
||||||
} else {
|
} else {
|
||||||
d += *i;
|
d += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
|
|
Loading…
Reference in New Issue