From 198b87fa3e564f6df1df8cbf961d655a59216d78 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 22 Mar 2006 16:21:11 +0000 Subject: [PATCH] * replaced std::vector with std::deque. --- ChangeLog | 1 + src/BitfieldMan.cc | 4 ++-- src/BitfieldMan.h | 6 ++++-- src/CookieBox.cc | 10 +++++----- src/CookieBox.h | 8 +++++--- src/Dictionary.cc | 2 +- src/Dictionary.h | 7 ++++--- src/Directory.h | 4 ++-- src/DownloadEngine.cc | 21 ++++++++++----------- src/DownloadEngine.h | 15 +++++++++------ src/HttpConnection.cc | 4 ++-- src/HttpHeader.cc | 4 ++-- src/HttpHeader.h | 4 ++-- src/HttpResponseCommand.cc | 4 ++-- src/List.h | 4 ++-- src/PeerInteractionCommand.cc | 10 +++++----- src/PeerInteractionCommand.h | 1 - src/PendingMessage.h | 4 ++-- src/Piece.cc | 2 +- src/Piece.h | 2 +- src/RequestSlotMan.h | 4 ++-- src/Segment.h | 4 ++-- src/SegmentMan.cc | 16 ++++++++-------- src/SegmentMan.h | 1 - src/ShaVisitor.cc | 4 ++-- src/SplitFirstSegmentSplitter.cc | 2 +- src/SplitSlowestSegmentSplitter.cc | 4 ++-- src/TorrentMan.h | 10 +++++----- src/Util.cc | 2 +- src/Util.h | 4 ++-- src/common.h | 4 ++++ src/main.cc | 8 +++++--- 32 files changed, 96 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a1c20d7..4663bb10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ * AbstractDiskWriter.{h,cc}: moved digest context initialization to Constructor. Also, moved digest cleanup to Destructor. * MetaFileUtil.cc: fixed memory leak + * replaced std::vector with std::deque. 2006-03-22 Tatsuhiro Tsujikawa diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index d0041fe6..66f89205 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -185,8 +185,8 @@ int BitfieldMan::getFirstMissingUnusedIndex() const { return -1; } -vector BitfieldMan::getAllMissingIndexes() const { - vector missingIndexes; +BlockIndexes BitfieldMan::getAllMissingIndexes() const { + BlockIndexes missingIndexes; for(int i = 0; i < bitfieldLength; i++) { unsigned char bit = ~bitfield[i]; for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) { diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h index 28f2f026..ec8dcafc 100644 --- a/src/BitfieldMan.h +++ b/src/BitfieldMan.h @@ -23,7 +23,9 @@ #define _D_BITFIELD_MAN_H_ #include "common.h" -#include +#include + +typedef deque BlockIndexes; class BitfieldMan { private: @@ -63,7 +65,7 @@ public: int getFirstMissingUnusedIndex(const unsigned char* bitfield, int len) const; int getFirstMissingUnusedIndex() const; int getMissingUnusedIndex(const unsigned char* bitfield, int len) const; - vector getAllMissingIndexes() const; + BlockIndexes getAllMissingIndexes() const; int countMissingBlock() const; bool setUseBit(int index); bool unsetUseBit(int index); diff --git a/src/CookieBox.cc b/src/CookieBox.cc index 96d6e24c..1371afb0 100644 --- a/src/CookieBox.cc +++ b/src/CookieBox.cc @@ -54,18 +54,18 @@ void CookieBox::setField(Cookie& cookie, string name, string value) const { void CookieBox::parse(Cookie& cookie, string cookieStr) const { cookie.clear(); - vector terms; + Strings terms; Util::slice(terms, cookieStr, ';'); - for(vector::iterator itr = terms.begin(); itr != terms.end(); itr++) { + for(Strings::iterator itr = terms.begin(); itr != terms.end(); itr++) { pair nv; Util::split(nv, *itr, '='); setField(cookie, nv.first, nv.second); } } -vector CookieBox::criteriaFind(string host, string dir, bool secure) const { - vector result; - for(vector::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) { +Cookies CookieBox::criteriaFind(string host, string dir, bool secure) const { + Cookies result; + for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) { const Cookie& c = *itr; if((secure || !c.secure && !secure) && Util::endsWith(host, c.domain) && diff --git a/src/CookieBox.h b/src/CookieBox.h index 12c1f442..6892670a 100644 --- a/src/CookieBox.h +++ b/src/CookieBox.h @@ -24,7 +24,7 @@ #include "common.h" #include -#include +#include using namespace std; @@ -49,9 +49,11 @@ public: } }; +typedef deque Cookies; + class CookieBox { private: - vector cookies; + Cookies cookies; void setField(Cookie& cookie, string name, string value) const; public: CookieBox(); @@ -60,7 +62,7 @@ public: void add(const Cookie& cookie); void add(string cookieStr); void parse(Cookie& cookie, string cookieStr) const; - vector criteriaFind(string host, string dir, bool secure) const; + Cookies criteriaFind(string host, string dir, bool secure) const; }; #endif // _D_COOKIE_BOX_H_ diff --git a/src/Dictionary.cc b/src/Dictionary.cc index 1c46323c..418979cd 100644 --- a/src/Dictionary.cc +++ b/src/Dictionary.cc @@ -52,6 +52,6 @@ void Dictionary::accept(MetaEntryVisitor* v) const { v->visit(this); } -const vector& Dictionary::getOrder() const { +const Order& Dictionary::getOrder() const { return order; } diff --git a/src/Dictionary.h b/src/Dictionary.h index 07837741..1bbb3c1f 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -24,17 +24,18 @@ #include "MetaEntry.h" #include -#include +#include #include using namespace std; typedef map MetaTable; +typedef deque Order; class Dictionary : public MetaEntry { private: MetaTable table; - vector order; + Order order; void clearTable(); public: Dictionary(); @@ -44,7 +45,7 @@ public: void put(string name, MetaEntry* entry); void accept(MetaEntryVisitor* v) const; - const vector& getOrder() const; + const Order& getOrder() const; }; diff --git a/src/Directory.h b/src/Directory.h index 700aa441..784c9e2e 100644 --- a/src/Directory.h +++ b/src/Directory.h @@ -24,11 +24,11 @@ #include "common.h" #include -#include +#include class Directory { -typedef vector Files; +typedef deque Files; private: string name; diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 57bdb831..42059e0f 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -75,14 +75,13 @@ void DownloadEngine::waitData() { FD_ZERO(&rfds); FD_ZERO(&wfds); int max = 0; - for(vector::iterator itr = rsockets.begin(); itr != rsockets.end(); itr++) { + for(Sockets::iterator itr = rsockets.begin(); itr != rsockets.end(); itr++) { FD_SET((*itr)->getSockfd(), &rfds); if(max < (*itr)->getSockfd()) { max = (*itr)->getSockfd(); } } - for(vector::iterator itr = wsockets.begin(); itr != wsockets.end(); itr++) { - + for(Sockets::iterator itr = wsockets.begin(); itr != wsockets.end(); itr++) { FD_SET((*itr)->getSockfd(), &wfds); if(max < (*itr)->getSockfd()) { max = (*itr)->getSockfd(); @@ -94,10 +93,10 @@ void DownloadEngine::waitData() { retval = select(max+1, &rfds, /*&wfds*/NULL, NULL, &tv); } -bool DownloadEngine::addSocket(vector& sockets, Socket* socket) { - vector::iterator itr = find(sockets.begin(), - sockets.end(), - socket); +bool DownloadEngine::addSocket(Sockets& sockets, Socket* socket) { + Sockets::iterator itr = find(sockets.begin(), + sockets.end(), + socket); if(itr == sockets.end()) { sockets.push_back(socket); return true; @@ -106,10 +105,10 @@ bool DownloadEngine::addSocket(vector& sockets, Socket* socket) { } } -bool DownloadEngine::deleteSocket(vector& sockets, Socket* socket) { - vector::iterator itr = find(sockets.begin(), - sockets.end(), - socket); +bool DownloadEngine::deleteSocket(Sockets& sockets, Socket* socket) { + Sockets::iterator itr = find(sockets.begin(), + sockets.end(), + socket); if(itr != sockets.end()) { sockets.erase(itr); return true; diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index 1a9fc742..10e9dffa 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -23,7 +23,7 @@ #define _D_DOWNLOAD_ENGINE_H_ #include -#include +#include #include "Command.h" #include "Socket.h" #include "SegmentMan.h" @@ -35,22 +35,25 @@ using namespace std; +typedef deque Sockets; +typedef queue Commands; + class DownloadEngine { private: void waitData(); - vector rsockets; - vector wsockets; + Sockets rsockets; + Sockets wsockets; void shortSleep() const; - bool addSocket(vector& sockets, Socket* socket); - bool deleteSocket(vector& sockets, Socket* socket); + bool addSocket(Sockets& sockets, Socket* socket); + bool deleteSocket(Sockets& sockets, Socket* socket); protected: virtual void initStatistics() = 0; virtual void calculateStatistics() = 0; virtual void onEndOfRun() = 0; public: bool noWait; - queue commands; + Commands commands; SegmentMan* segmentMan; DiskWriter* diskWriter; const Logger* logger; diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index f93faead..db6b1848 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -90,8 +90,8 @@ string HttpConnection::createRequest(const Segment& segment) const { } string cookiesValue; - vector cookies = req->cookieBox->criteriaFind(req->getHost(), req->getDir(), req->getProtocol() == "https" ? true : false); - for(vector::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) { + Cookies cookies = req->cookieBox->criteriaFind(req->getHost(), req->getDir(), req->getProtocol() == "https" ? true : false); + for(Cookies::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) { cookiesValue += (*itr).toString()+";"; } if(cookiesValue.size()) { diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index eb80cf5b..fa61056c 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -39,8 +39,8 @@ string HttpHeader::getFirst(const string& name) const { } } -vector HttpHeader::get(const string& name) const { - vector v; +Strings HttpHeader::get(const string& name) const { + Strings v; for(multimap::const_iterator itr = table.find(name); itr != table.end(); itr++) { v.push_back((*itr).second); } diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 3f7fc550..20be3098 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -24,7 +24,7 @@ #include "common.h" #include -#include +#include #include using namespace std; @@ -39,7 +39,7 @@ public: void put(const string& name, const string& value); bool defined(const string& name) const; string getFirst(const string& name) const; - vector get(const string& name) const; + Strings get(const string& name) const; int getFirstAsInt(const string& name) const; long long int getFirstAsLLInt(const string& name) const; }; diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 48783d24..d6717d15 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -159,8 +159,8 @@ void HttpResponseCommand::createHttpDownloadCommand(string transferEncoding) { } void HttpResponseCommand::retrieveCookie(const HttpHeader& headers) { - vector v = headers.get("Set-Cookie"); - for(vector::const_iterator itr = v.begin(); itr != v.end(); itr++) { + Strings v = headers.get("Set-Cookie"); + for(Strings::const_iterator itr = v.begin(); itr != v.end(); itr++) { Cookie c; req->cookieBox->parse(c, *itr); req->cookieBox->add(c); diff --git a/src/List.h b/src/List.h index 64c2a462..dee96a8c 100644 --- a/src/List.h +++ b/src/List.h @@ -23,11 +23,11 @@ #define _D_LIST_H_ #include "MetaEntry.h" -#include +#include using namespace std; -typedef vector MetaList; +typedef deque MetaList; class List : public MetaEntry { private: diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 5b0174ee..0b5a2b8a 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -317,9 +317,9 @@ void PeerInteractionCommand::createRequestPendingMessage(int blockIndex) { void PeerInteractionCommand::sendMessages() { if(!Piece::isNull(piece) && !peer->peerChoking) { if(e->torrentMan->isEndGame()) { - vector missingBlockIndexes = piece.getAllMissingBlockIndexes(); + BlockIndexes missingBlockIndexes = piece.getAllMissingBlockIndexes(); if(requestSlotMan->isEmpty()) { - for(vector::const_iterator itr = missingBlockIndexes.begin(); + for(PieceIndexes::const_iterator itr = missingBlockIndexes.begin(); itr != missingBlockIndexes.end(); itr++) { createRequestPendingMessage(*itr); } @@ -374,17 +374,17 @@ void PeerInteractionCommand::beforeSocketCheck() { if(sequence == WIRED) { e->torrentMan->unadvertisePiece(cuid); - vector indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid); + PieceIndexes indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid); if(indexes.size() >= 20) { PendingMessage pendingMessage(PeerMessage::BITFIELD, peerConnection); pendingMessages.push_back(pendingMessage); } else { if(pendingMessages.size() == 0) { - for(vector::iterator itr = indexes.begin(); itr != indexes.end(); itr++) { + for(PieceIndexes::iterator itr = indexes.begin(); itr != indexes.end(); itr++) { peerConnection->sendHave(*itr); } } else { - for(vector::iterator itr = indexes.begin(); itr != indexes.end(); itr++) { + for(PieceIndexes::iterator itr = indexes.begin(); itr != indexes.end(); itr++) { PendingMessage pendingMessage = PendingMessage::createHaveMessage(*itr, peerConnection); pendingMessages.push_back(pendingMessage); } diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h index 0bfe7e97..92f390df 100644 --- a/src/PeerInteractionCommand.h +++ b/src/PeerInteractionCommand.h @@ -26,7 +26,6 @@ #include "PeerConnection.h" #include "PendingMessage.h" #include "RequestSlotMan.h" -#include using namespace std; diff --git a/src/PendingMessage.h b/src/PendingMessage.h index da877748..3b542282 100644 --- a/src/PendingMessage.h +++ b/src/PendingMessage.h @@ -24,7 +24,7 @@ #include "common.h" #include "PeerConnection.h" -#include +#include class PendingMessage { private: @@ -66,6 +66,6 @@ public: static PendingMessage createHaveMessage(int index, PeerConnection* peerConnectioin); }; -typedef vector PendingMessages; +typedef deque PendingMessages; #endif // _D_PENDING_MESSAGE_H_ diff --git a/src/Piece.cc b/src/Piece.cc index b27cc621..d4a36972 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -79,6 +79,6 @@ int Piece::getMissingUnusedBlockIndex() const { return blockIndex; } -vector Piece::getAllMissingBlockIndexes() const { +BlockIndexes Piece::getAllMissingBlockIndexes() const { return bitfield->getAllMissingIndexes(); } diff --git a/src/Piece.h b/src/Piece.h index f12dcf15..d8d7d95d 100644 --- a/src/Piece.h +++ b/src/Piece.h @@ -45,7 +45,7 @@ public: Piece& operator=(const Piece& piece); int getMissingUnusedBlockIndex() const; - vector getAllMissingBlockIndexes() const; + BlockIndexes getAllMissingBlockIndexes() const; void completeBlock(int blockIndex); void cancelBlock(int blockIndex); int countCompleteBlock() const { diff --git a/src/RequestSlotMan.h b/src/RequestSlotMan.h index f0c1f008..2269651d 100644 --- a/src/RequestSlotMan.h +++ b/src/RequestSlotMan.h @@ -29,11 +29,11 @@ #include "PeerConnection.h" #include "PendingMessage.h" #include "TorrentMan.h" -#include +#include #define DEFAULT_TIME_OUT 120 -typedef vector RequestSlots; +typedef deque RequestSlots; class RequestSlotMan { private: diff --git a/src/Segment.h b/src/Segment.h index 21db6de3..dc2ea084 100644 --- a/src/Segment.h +++ b/src/Segment.h @@ -23,7 +23,7 @@ #define _D_SEGMENT_H_ #include "common.h" -#include +#include using namespace std; @@ -45,7 +45,7 @@ typedef struct { bool finish; } Segment; -typedef vector Segments; +typedef deque Segments; #define SEGMENT_EQUAL(X, Y) (X.cuid == Y.cuid && X.sp == Y.sp && X.ep == Y.ep && X.ds == Y.ds && X.finish == Y.finish ? true : false) diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc index 57accd15..c2761796 100644 --- a/src/SegmentMan.cc +++ b/src/SegmentMan.cc @@ -35,7 +35,7 @@ SegmentMan::SegmentMan():totalSize(0),isSplittable(true),downloadStarted(false), SegmentMan::~SegmentMan() {} void SegmentMan::unregisterId(int cuid) { - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { if((*itr).cuid == cuid) { cuid = 0; } @@ -57,7 +57,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) { segments.push_back(seg); return true; } - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { if((*itr).cuid == cuid && !(*itr).finish) { // logger->debug("return an existing segment { " // "sp = "+Util::ulitos((*itr).sp)+", "+ @@ -71,7 +71,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) { if(!isSplittable) { return false; } - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { Segment& s = *itr; if(s.finish) { continue; @@ -86,7 +86,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) { } void SegmentMan::updateSegment(const Segment& segment) { - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { if((*itr).cuid == segment.cuid && (*itr).sp == segment.sp && (*itr).ep == segment.ep) { @@ -122,7 +122,7 @@ void SegmentMan::load() { read(segFile); fclose(segFile); logger->info(MSG_LOADED_SEGMENT_FILE); - for(vector::iterator itr = segments.begin(); itr != segments.end(); + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { (*itr).cuid = 0; } @@ -138,7 +138,7 @@ void SegmentMan::save() const { if(fwrite(&totalSize, sizeof(totalSize), 1, segFile) < 1) { throw new DlAbortEx(strerror(errno)); } - for(vector::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { if(fwrite(&*itr, sizeof(Segment), 1, segFile) < 1) { throw new DlAbortEx(strerror(errno)); } @@ -187,7 +187,7 @@ bool SegmentMan::finished() const { if(!downloadStarted || segments.size() == 0) { return false; } - for(vector::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { if(!(*itr).finish) { return false; } @@ -203,7 +203,7 @@ void SegmentMan::removeIfFinished() const { long long int SegmentMan::getDownloadedSize() const { long long int size = 0; - for(vector::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::const_iterator itr = segments.begin(); itr != segments.end(); itr++) { size += (*itr).ds; } return size; diff --git a/src/SegmentMan.h b/src/SegmentMan.h index 970a4fd0..857a38f7 100644 --- a/src/SegmentMan.h +++ b/src/SegmentMan.h @@ -22,7 +22,6 @@ #ifndef _D_SEGMENT_MAN_H_ #define _D_SEGMENT_MAN_H_ -#include #include "common.h" #include "Logger.h" #include "Segment.h" diff --git a/src/ShaVisitor.cc b/src/ShaVisitor.cc index b568051d..c443a869 100644 --- a/src/ShaVisitor.cc +++ b/src/ShaVisitor.cc @@ -54,8 +54,8 @@ void ShaVisitor::visit(const Data* d) { void ShaVisitor::visit(const Dictionary* d) { #ifdef HAVE_LIBSSL EVP_DigestUpdate(&ctx, "d", 1); - const vector& v = d->getOrder(); - for(vector::const_iterator itr = v.begin(); itr != v.end(); itr++) { + const Order& v = d->getOrder(); + for(Order::const_iterator itr = v.begin(); itr != v.end(); itr++) { string lenStr = Util::llitos(itr->size()); EVP_DigestUpdate(&ctx, lenStr.c_str(), lenStr.size()); EVP_DigestUpdate(&ctx, ":", 1); diff --git a/src/SplitFirstSegmentSplitter.cc b/src/SplitFirstSegmentSplitter.cc index 72a3f2d1..22e02da0 100644 --- a/src/SplitFirstSegmentSplitter.cc +++ b/src/SplitFirstSegmentSplitter.cc @@ -22,7 +22,7 @@ #include "SplitFirstSegmentSplitter.h" bool SplitFirstSegmentSplitter::splitSegment(Segment& seg, int cuid, Segments& segments) { - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { Segment& s = *itr; if(s.finish) { continue; diff --git a/src/SplitSlowestSegmentSplitter.cc b/src/SplitSlowestSegmentSplitter.cc index 47c571bf..1be620e8 100644 --- a/src/SplitSlowestSegmentSplitter.cc +++ b/src/SplitSlowestSegmentSplitter.cc @@ -22,8 +22,8 @@ #include "SplitSlowestSegmentSplitter.h" bool SplitSlowestSegmentSplitter::splitSegment(Segment& seg, int cuid, Segments& segments) { - vector::iterator slowest = segments.end();; - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { + Segments::iterator slowest = segments.end();; + for(Segments::iterator itr = segments.begin(); itr != segments.end(); itr++) { Segment& s = *itr; if(s.finish) { continue; diff --git a/src/TorrentMan.h b/src/TorrentMan.h index 2d25c250..92221293 100644 --- a/src/TorrentMan.h +++ b/src/TorrentMan.h @@ -30,7 +30,6 @@ #include "Piece.h" #include "Directory.h" #include -#include #include #include @@ -59,15 +58,16 @@ public: typedef deque Peers; typedef multimap Haves; -typedef vector MultiFileEntries; +typedef deque MultiFileEntries; typedef deque UsedPieces; +typedef deque PieceIndexes; class TorrentMan { private: Peers peers; BitfieldMan* bitfield; unsigned char infoHash[INFO_HASH_LENGTH]; - vector pieceHashes; + deque pieceHashes; int peerEntryIdCounter; int cuidCounter; long long int downloadedSize; @@ -151,8 +151,8 @@ public: haves.insert(vt); } - vector getAdvertisedPieceIndexes(int myCuid) const { - vector indexes; + PieceIndexes getAdvertisedPieceIndexes(int myCuid) const { + PieceIndexes indexes; for(Haves::const_iterator itr = haves.begin(); itr != haves.end(); itr++) { const Haves::value_type& have = *itr; if(have.first == myCuid) { diff --git a/src/Util.cc b/src/Util.cc index b0a03f51..bd18037d 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -89,7 +89,7 @@ long long int Util::difftv(struct timeval tv1, struct timeval tv2) { tv1.tv_usec-tv2.tv_usec); } -void Util::slice(vector& result, string src, char delim) { +void Util::slice(Strings& result, string src, char delim) { string::size_type p = 0; while(1) { string::size_type np = src.find(delim, p); diff --git a/src/Util.h b/src/Util.h index f8e50932..b3244df6 100644 --- a/src/Util.h +++ b/src/Util.h @@ -25,7 +25,7 @@ #include "common.h" #include #include -#include +#include #include using namespace std; @@ -47,7 +47,7 @@ public: * Take a string src which is a deliminated list and add its elements * into result. result is not cleared before conversion begins. */ - static void slice(vector& result, string src, char delim); + static void slice(Strings& result, string src, char delim); static string trim(string src); diff --git a/src/common.h b/src/common.h index 1260edf5..af36936c 100644 --- a/src/common.h +++ b/src/common.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #if ENABLE_NLS # include # define _(String) gettext (String) @@ -45,4 +47,6 @@ using namespace std; +typedef deque Strings; + #endif // _D_COMMON_H_ diff --git a/src/main.cc b/src/main.cc index 58257eaf..27987f00 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,7 +35,7 @@ #include "PeerListenCommand.h" #include "TorrentAutoSaveCommand.h" #include "SleepCommand.h" -#include +#include #include #include #include @@ -54,6 +54,8 @@ extern int optind, opterr, optopt; using namespace std; +typedef deque Requests; + void printDownloadCompeleteMessage(string filename) { printf(_("\nThe download was complete. <%s>\n"), filename.c_str()); } @@ -94,7 +96,7 @@ void torrentHandler(int signal) { exit(0); } -void addCommand(int cuid, const char* url, string referer, vector requests) { +void addCommand(int cuid, const char* url, string referer, Requests requests) { Request* req = new Request(); req->setReferer(referer); if(req->setUrl(url)) { @@ -520,7 +522,7 @@ int main(int argc, char* argv[]) { e->segmentMan->option = op; e->segmentMan->splitter = splitter; - vector requests; + Requests requests; for(int i = 1; optind+i-1 < argc; i++) { for(int s = 1; s <= split; s++) { addCommand(split*(i-1)+s, argv[optind+i-1], referer, requests);