2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

To match the behavior of friend operator functions in
	SharedHandle.h to std::tr1::shared_ptr, we intentionally broke
	these functions and modified code so that our code does not depend
	on old behavior.
	* src/AbstractCommand.cc
	* src/DHTAbstractNodeLookupTask.h
	* src/DHTBucket.cc
	* src/DHTMessageReceiver.cc
	* src/DHTNodeLookupEntry.cc
	* src/DHTRoutingTable.cc
	* src/DefaultBtRequestFactory.cc
	* src/DefaultPeerStorage.cc
	* src/DefaultPieceStorage.cc
	* src/DownloadContext.cc
	* src/EpollEventPoll.cc
	* src/Event.h
	* src/HttpConnection.cc
	* src/KqueueEventPoll.cc
	* src/MultiDiskAdaptor.cc
	* src/PeerAbstractCommand.cc
	* src/PieceStatMan.cc
	* src/PollEventPoll.cc
	* src/PortEventPoll.cc
	* src/SegmentMan.cc
	* src/SelectEventPoll.cc
	* src/SelectEventPoll.h
	* src/ServerStatMan.cc
	* src/SharedHandle.h
	* src/UnknownLengthPieceStorage.cc
	* src/a2functional.h
	* src/option_processing.cc
	* src/version_usage.cc
	* test/BNodeTest.cc
	* test/DHTAnnouncePeerMessageTest.cc
	* test/DHTBucketTest.cc
	* test/DHTFindNodeMessageTest.cc
	* test/DHTGetPeersMessageTest.cc
	* test/DHTIDCloserTest.cc
	* test/DHTMessageFactoryImplTest.cc
	* test/DHTPingMessageTest.cc
	* test/DefaultBtRequestFactoryTest.cc
	* test/DefaultPeerStorageTest.cc
	* test/SequentialPickerTest.cc
	* test/SingletonHolderTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2010-11-11 07:33:43 +00:00
parent bcf4593bda
commit bc98e39fe5
41 changed files with 306 additions and 167 deletions

View file

@ -1,3 +1,50 @@
2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
To match the behavior of friend operator functions in
SharedHandle.h to std::tr1::shared_ptr, we intentionally broke
these functions and modified code so that our code does not depend
on old behavior.
* src/AbstractCommand.cc
* src/DHTAbstractNodeLookupTask.h
* src/DHTBucket.cc
* src/DHTMessageReceiver.cc
* src/DHTNodeLookupEntry.cc
* src/DHTRoutingTable.cc
* src/DefaultBtRequestFactory.cc
* src/DefaultPeerStorage.cc
* src/DefaultPieceStorage.cc
* src/DownloadContext.cc
* src/EpollEventPoll.cc
* src/Event.h
* src/HttpConnection.cc
* src/KqueueEventPoll.cc
* src/MultiDiskAdaptor.cc
* src/PeerAbstractCommand.cc
* src/PieceStatMan.cc
* src/PollEventPoll.cc
* src/PortEventPoll.cc
* src/SegmentMan.cc
* src/SelectEventPoll.cc
* src/SelectEventPoll.h
* src/ServerStatMan.cc
* src/SharedHandle.h
* src/UnknownLengthPieceStorage.cc
* src/a2functional.h
* src/option_processing.cc
* src/version_usage.cc
* test/BNodeTest.cc
* test/DHTAnnouncePeerMessageTest.cc
* test/DHTBucketTest.cc
* test/DHTFindNodeMessageTest.cc
* test/DHTGetPeersMessageTest.cc
* test/DHTIDCloserTest.cc
* test/DHTMessageFactoryImplTest.cc
* test/DHTPingMessageTest.cc
* test/DefaultBtRequestFactoryTest.cc
* test/DefaultPeerStorageTest.cc
* test/SequentialPickerTest.cc
* test/SingletonHolderTest.cc
2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-11-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Create SharedHandle outside of function call to avoid unexpected Create SharedHandle outside of function call to avoid unexpected

View file

@ -462,7 +462,7 @@ void AbstractCommand::setReadCheckSocket(const SocketHandle& socket) {
disableReadCheckSocket(); disableReadCheckSocket();
} else { } else {
if(checkSocketIsReadable_) { if(checkSocketIsReadable_) {
if(readCheckTarget_ != socket) { if(*readCheckTarget_ != *socket) {
e_->deleteSocketForReadCheck(readCheckTarget_, this); e_->deleteSocketForReadCheck(readCheckTarget_, this);
e_->addSocketForReadCheck(socket, this); e_->addSocketForReadCheck(socket, this);
readCheckTarget_ = socket; readCheckTarget_ = socket;
@ -498,7 +498,7 @@ void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
disableWriteCheckSocket(); disableWriteCheckSocket();
} else { } else {
if(checkSocketIsWritable_) { if(checkSocketIsWritable_) {
if(writeCheckTarget_ != socket) { if(*writeCheckTarget_ != *socket) {
e_->deleteSocketForWriteCheck(writeCheckTarget_, this); e_->deleteSocketForWriteCheck(writeCheckTarget_, this);
e_->addSocketForWriteCheck(socket, this); e_->addSocketForWriteCheck(socket, this);
writeCheckTarget_ = socket; writeCheckTarget_ = socket;

View file

@ -54,6 +54,7 @@
#include "Logger.h" #include "Logger.h"
#include "util.h" #include "util.h"
#include "DHTIDCloser.h" #include "DHTIDCloser.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -203,7 +204,10 @@ public:
static_cast<unsigned long>(count)); static_cast<unsigned long>(count));
} }
std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_)); std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
entries_.erase(std::unique(entries_.begin(), entries_.end()), entries_.end()); entries_.erase
(std::unique(entries_.begin(), entries_.end(),
DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()),
entries_.end());
if(getLogger()->debug()) { if(getLogger()->debug()) {
getLogger()->debug("%lu node lookup entries are unique.", getLogger()->debug("%lu node lookup entries are unique.",
static_cast<unsigned long>(entries_.size())); static_cast<unsigned long>(entries_.size()));
@ -223,7 +227,7 @@ public:
--inFlightMessage_; --inFlightMessage_;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i = for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) { entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->node == node) { if(*(*i)->node == *node) {
entries_.erase(i); entries_.erase(i);
break; break;
} }

View file

@ -111,7 +111,7 @@ bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
{ {
notifyUpdate(); notifyUpdate();
std::deque<SharedHandle<DHTNode> >::iterator itr = std::deque<SharedHandle<DHTNode> >::iterator itr =
std::find(nodes_.begin(), nodes_.end(), node); std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr == nodes_.end()) { if(itr == nodes_.end()) {
if(nodes_.size() < K) { if(nodes_.size() < K) {
nodes_.push_back(node); nodes_.push_back(node);
@ -145,7 +145,7 @@ void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
{ {
if(cachedNodes_.size()) { if(cachedNodes_.size()) {
std::deque<SharedHandle<DHTNode> >::iterator itr = std::deque<SharedHandle<DHTNode> >::iterator itr =
find(nodes_.begin(), nodes_.end(), node); std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) { if(itr != nodes_.end()) {
nodes_.erase(itr); nodes_.erase(itr);
nodes_.push_back(cachedNodes_.front()); nodes_.push_back(cachedNodes_.front());
@ -157,7 +157,7 @@ void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node) void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
{ {
std::deque<SharedHandle<DHTNode> >::iterator itr = std::deque<SharedHandle<DHTNode> >::iterator itr =
std::find(nodes_.begin(), nodes_.end(), node); std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) { if(itr != nodes_.end()) {
nodes_.erase(itr); nodes_.erase(itr);
nodes_.push_front(node); nodes_.push_front(node);
@ -167,7 +167,7 @@ void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
void DHTBucket::moveToTail(const SharedHandle<DHTNode>& node) void DHTBucket::moveToTail(const SharedHandle<DHTNode>& node)
{ {
std::deque<SharedHandle<DHTNode> >::iterator itr = std::deque<SharedHandle<DHTNode> >::iterator itr =
std::find(nodes_.begin(), nodes_.end(), node); std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr != nodes_.end()) { if(itr != nodes_.end()) {
nodes_.erase(itr); nodes_.erase(itr);
nodes_.push_back(node); nodes_.push_back(node);
@ -233,7 +233,7 @@ SharedHandle<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std:
node->setIPAddress(ipaddr); node->setIPAddress(ipaddr);
node->setPort(port); node->setPort(port);
std::deque<SharedHandle<DHTNode> >::const_iterator itr = std::deque<SharedHandle<DHTNode> >::const_iterator itr =
std::find(nodes_.begin(), nodes_.end(), node); std::find_if(nodes_.begin(), nodes_.end(), derefEqual(node));
if(itr == nodes_.end()) { if(itr == nodes_.end()) {
return SharedHandle<DHTNode>(); return SharedHandle<DHTNode>();
} else { } else {

View file

@ -109,7 +109,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
} else { } else {
SharedHandle<DHTQueryMessage> message = SharedHandle<DHTQueryMessage> message =
factory_->createQueryMessage(dict, remoteAddr, remotePort); factory_->createQueryMessage(dict, remoteAddr, remotePort);
if(message->getLocalNode() == message->getRemoteNode()) { if(*message->getLocalNode() == *message->getRemoteNode()) {
// drop message from localnode // drop message from localnode
logger_->info("Received DHT message from localnode."); logger_->info("Received DHT message from localnode.");
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);

View file

@ -45,7 +45,7 @@ DHTNodeLookupEntry::DHTNodeLookupEntry():
bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const
{ {
return node == entry.node; return *node == *entry.node;
} }
} // namespace aria2 } // namespace aria2

View file

@ -77,7 +77,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
if(logger_->debug()) { if(logger_->debug()) {
logger_->debug("Trying to add node:%s", node->toString().c_str()); logger_->debug("Trying to add node:%s", node->toString().c_str());
} }
if(localNode_ == node) { if(*localNode_ == *node) {
if(logger_->debug()) { if(logger_->debug()) {
logger_->debug("Adding node with the same ID with localnode is not" logger_->debug("Adding node with the same ID with localnode is not"
" allowed."); " allowed.");

View file

@ -99,8 +99,9 @@ void DefaultBtRequestFactory::removeCompletedPiece() {
void DefaultBtRequestFactory::removeTargetPiece void DefaultBtRequestFactory::removeTargetPiece
(const SharedHandle<Piece>& piece) (const SharedHandle<Piece>& piece)
{ {
pieces_.erase(std::remove(pieces_.begin(), pieces_.end(), piece), pieces_.erase(std::remove_if(pieces_.begin(), pieces_.end(),
pieces_.end()); derefEqual(piece)),
pieces_.end());
dispatcher_->doAbortOutstandingRequestAction(piece); dispatcher_->doAbortOutstandingRequestAction(piece);
pieceStorage_->cancelPiece(piece); pieceStorage_->cancelPiece(piece);
} }

View file

@ -45,6 +45,7 @@
#include "BtLeecherStateChoke.h" #include "BtLeecherStateChoke.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "wallclock.h" #include "wallclock.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -75,7 +76,7 @@ public:
FindIdenticalPeer(const SharedHandle<Peer>& peer):peer_(peer) {} FindIdenticalPeer(const SharedHandle<Peer>& peer):peer_(peer) {}
bool operator()(const SharedHandle<Peer>& peer) const { bool operator()(const SharedHandle<Peer>& peer) const {
return (peer_ == peer) || return (*peer_ == *peer) ||
((peer_->getIPAddress() == peer->getIPAddress()) && ((peer_->getIPAddress() == peer->getIPAddress()) &&
(peer_->getPort() == peer->getPort())); (peer_->getPort() == peer->getPort()));
} }
@ -337,7 +338,7 @@ void DefaultPeerStorage::onReturningPeer(const SharedHandle<Peer>& peer)
void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer) void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer)
{ {
std::deque<SharedHandle<Peer> >::iterator itr = std::deque<SharedHandle<Peer> >::iterator itr =
std::find(peers_.begin(), peers_.end(), peer); std::find_if(peers_.begin(), peers_.end(), derefEqual(peer));
if(itr == peers_.end()) { if(itr == peers_.end()) {
if(logger_->debug()) { if(logger_->debug()) {
logger_->debug("Cannot find peer %s:%u in PeerStorage.", logger_->debug("Cannot find peer %s:%u in PeerStorage.",

View file

@ -127,7 +127,8 @@ SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece) void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece)
{ {
std::deque<SharedHandle<Piece> >::iterator i = std::deque<SharedHandle<Piece> >::iterator i =
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece); std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece,
DerefLess<SharedHandle<Piece> >());
usedPieces_.insert(i, piece); usedPieces_.insert(i, piece);
if(logger_->debug()) { if(logger_->debug()) {
logger_->debug("usedPieces_.size()=%lu", logger_->debug("usedPieces_.size()=%lu",
@ -141,8 +142,9 @@ SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
p->setIndex(index); p->setIndex(index);
std::deque<SharedHandle<Piece> >::const_iterator i = std::deque<SharedHandle<Piece> >::const_iterator i =
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), p); std::lower_bound(usedPieces_.begin(), usedPieces_.end(), p,
if(i != usedPieces_.end() && (*i) == p) { DerefLess<SharedHandle<Piece> >());
if(i != usedPieces_.end() && *(*i) == *p) {
return *i; return *i;
} else { } else {
p.reset(0); p.reset(0);
@ -365,8 +367,9 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
return; return;
} }
std::deque<SharedHandle<Piece> >::iterator i = std::deque<SharedHandle<Piece> >::iterator i =
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece); std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece,
if(i != usedPieces_.end() && (*i) == piece) { DerefLess<SharedHandle<Piece> >());
if(i != usedPieces_.end() && *(*i) == *piece) {
usedPieces_.erase(i); usedPieces_.erase(i);
} }
} }
@ -723,7 +726,8 @@ void DefaultPieceStorage::addInFlightPiece
(const std::vector<SharedHandle<Piece> >& pieces) (const std::vector<SharedHandle<Piece> >& pieces)
{ {
usedPieces_.insert(usedPieces_.end(), pieces.begin(), pieces.end()); usedPieces_.insert(usedPieces_.end(), pieces.begin(), pieces.end());
std::sort(usedPieces_.begin(), usedPieces_.end()); std::sort(usedPieces_.begin(), usedPieces_.end(),
DerefLess<SharedHandle<Piece> >());
} }
size_t DefaultPieceStorage::countInFlightPiece() size_t DefaultPieceStorage::countInFlightPiece()

View file

@ -41,6 +41,7 @@
#include "util.h" #include "util.h"
#include "wallclock.h" #include "wallclock.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -102,7 +103,8 @@ DownloadContext::findFileEntryByOffset(off_t offset) const
SharedHandle<FileEntry> obj(new FileEntry()); SharedHandle<FileEntry> obj(new FileEntry());
obj->setOffset(offset); obj->setOffset(offset);
std::vector<SharedHandle<FileEntry> >::const_iterator i = std::vector<SharedHandle<FileEntry> >::const_iterator i =
std::upper_bound(fileEntries_.begin(), fileEntries_.end(), obj); std::upper_bound(fileEntries_.begin(), fileEntries_.end(), obj,
DerefLess<SharedHandle<FileEntry> >());
if(i != fileEntries_.end() && (*i)->getOffset() == offset) { if(i != fileEntries_.end() && (*i)->getOffset() == offset) {
return *i; return *i;
} else { } else {

View file

@ -43,6 +43,7 @@
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h" #include "Logger.h"
#include "util.h" #include "util.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -166,10 +167,11 @@ bool EpollEventPoll::addEvents(sock_t socket,
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
DerefLess<SharedHandle<KSocketEntry> >());
int r = 0; int r = 0;
int errNum = 0; int errNum = 0;
if(i != socketEntries_.end() && (*i) == socketEntry) { if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i); event.addSelf(*i);
@ -229,8 +231,9 @@ bool EpollEventPoll::deleteEvents(sock_t socket,
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.removeSelf(*i); event.removeSelf(*i);
@ -295,7 +298,8 @@ bool EpollEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.push_back(entry); nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this); entry->addSocketEvents(this);
@ -311,7 +315,8 @@ bool EpollEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
return false; return false;
} else { } else {

View file

@ -151,7 +151,7 @@ public:
bool operator==(const ADNSEvent& event) const bool operator==(const ADNSEvent& event) const
{ {
return resolver_ == event.resolver_; return *resolver_ == *event.resolver_;
} }
virtual int getEvents() const virtual int getEvents() const
@ -323,7 +323,7 @@ public:
bool operator==(const AsyncNameResolverEntry& entry) bool operator==(const AsyncNameResolverEntry& entry)
{ {
return nameResolver_ == entry.nameResolver_ && return *nameResolver_ == *entry.nameResolver_ &&
command_ == entry.command_; command_ == entry.command_;
} }

View file

@ -165,7 +165,7 @@ bool HttpConnection::isIssued(const SharedHandle<Segment>& segment) const
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests_.begin(), for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests_.begin(),
eoi = outstandingHttpRequests_.end(); itr != eoi; ++itr) { eoi = outstandingHttpRequests_.end(); itr != eoi; ++itr) {
SharedHandle<HttpRequest> httpRequest = (*itr)->getHttpRequest(); SharedHandle<HttpRequest> httpRequest = (*itr)->getHttpRequest();
if(httpRequest->getSegment() == segment) { if(*httpRequest->getSegment() == *segment) {
return true; return true;
} }
} }

View file

@ -170,12 +170,13 @@ bool KqueueEventPoll::addEvents
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
DerefLess<SharedHandle<KSocketEntry> >());
int r = 0; int r = 0;
struct timespec zeroTimeout = { 0, 0 }; struct timespec zeroTimeout = { 0, 0 };
struct kevent changelist[2]; struct kevent changelist[2];
size_t n; size_t n;
if(i != socketEntries_.end() && (*i) == socketEntry) { if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i); event.addSelf(*i);
n = (*i)->getEvents(changelist); n = (*i)->getEvents(changelist);
} else { } else {
@ -221,8 +222,9 @@ bool KqueueEventPoll::deleteEvents(sock_t socket,
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.removeSelf(*i); event.removeSelf(*i);
int r = 0; int r = 0;
struct timespec zeroTimeout = { 0, 0 }; struct timespec zeroTimeout = { 0, 0 };
@ -272,7 +274,8 @@ bool KqueueEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.push_back(entry); nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this); entry->addSocketEvents(this);
@ -288,7 +291,8 @@ bool KqueueEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
return false; return false;
} else { } else {

View file

@ -119,7 +119,7 @@ void DiskWriterEntry::setDiskWriter(const SharedHandle<DiskWriter>& diskWriter)
bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const
{ {
return fileEntry_ < entry.fileEntry_; return *fileEntry_ < *entry.fileEntry_;
} }
void DiskWriterEntry::enableDirectIO() void DiskWriterEntry::enableDirectIO()

View file

@ -148,7 +148,7 @@ void PeerAbstractCommand::setReadCheckSocket(const SocketHandle& socket)
disableReadCheckSocket(); disableReadCheckSocket();
} else { } else {
if(checkSocketIsReadable_) { if(checkSocketIsReadable_) {
if(readCheckTarget_ != socket) { if(*readCheckTarget_ != *socket) {
e_->deleteSocketForReadCheck(readCheckTarget_, this); e_->deleteSocketForReadCheck(readCheckTarget_, this);
e_->addSocketForReadCheck(socket, this); e_->addSocketForReadCheck(socket, this);
readCheckTarget_ = socket; readCheckTarget_ = socket;
@ -176,7 +176,7 @@ void PeerAbstractCommand::setWriteCheckSocket(const SocketHandle& socket)
disableWriteCheckSocket(); disableWriteCheckSocket();
} else { } else {
if(checkSocketIsWritable_) { if(checkSocketIsWritable_) {
if(writeCheckTarget_ != socket) { if(*writeCheckTarget_ != *socket) {
e_->deleteSocketForWriteCheck(writeCheckTarget_, this); e_->deleteSocketForWriteCheck(writeCheckTarget_, this);
e_->addSocketForWriteCheck(socket, this); e_->addSocketForWriteCheck(socket, this);
writeCheckTarget_ = socket; writeCheckTarget_ = socket;

View file

@ -103,7 +103,7 @@ public:
bool operator()(size_t lhs, size_t rhs) const bool operator()(size_t lhs, size_t rhs) const
{ {
return pieceStats_[lhs] < pieceStats_[rhs]; return *pieceStats_[lhs] < *pieceStats_[rhs];
} }
}; };
} // namespace } // namespace

View file

@ -41,6 +41,7 @@
#include "Command.h" #include "Command.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h" #include "Logger.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -97,8 +98,9 @@ void PollEventPoll::poll(const struct timeval& tv)
if(first->revents) { if(first->revents) {
se->setSocket(first->fd); se->setSocket(first->fd);
std::deque<SharedHandle<KSocketEntry> >::iterator itr = std::deque<SharedHandle<KSocketEntry> >::iterator itr =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), se); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), se,
if(itr != socketEntries_.end() && (*itr) == se) { DerefLess<SharedHandle<KSocketEntry> >());
if(itr != socketEntries_.end() && *(*itr) == *se) {
(*itr)->processEvents(first->revents); (*itr)->processEvents(first->revents);
} else { } else {
if(logger_->debug()) { if(logger_->debug()) {
@ -150,8 +152,9 @@ bool PollEventPoll::addEvents
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<KSocketEntry> >());
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_;
first != last; ++first) { first != last; ++first) {
@ -197,8 +200,9 @@ bool PollEventPoll::deleteEvents
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.removeSelf(*i); event.removeSelf(*i);
for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_; for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_;
first != last; ++first) { first != last; ++first) {
@ -246,7 +250,8 @@ bool PollEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.push_back(entry); nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this); entry->addSocketEvents(this);
@ -262,7 +267,8 @@ bool PollEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
return false; return false;
} else { } else {

View file

@ -173,10 +173,11 @@ bool PortEventPoll::addEvents(sock_t socket,
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
DerefLess<SharedHandle<KSocketEntry> >());
int r = 0; int r = 0;
int errNum = 0; int errNum = 0;
if(i != socketEntries_.end() && (*i) == socketEntry) { if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i); event.addSelf(*i);
A2PortEvent pv = (*i)->getEvents(); A2PortEvent pv = (*i)->getEvents();
r = port_associate(port_, PORT_SOURCE_FD, (*i)->getSocket(), r = port_associate(port_, PORT_SOURCE_FD, (*i)->getSocket(),
@ -226,8 +227,9 @@ bool PortEventPoll::deleteEvents(sock_t socket,
{ {
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket)); SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i = std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.removeSelf(*i); event.removeSelf(*i);
int r = 0; int r = 0;
int errNum = 0; int errNum = 0;
@ -280,7 +282,8 @@ bool PortEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.push_back(entry); nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this); entry->addSocketEvents(this);
@ -296,7 +299,8 @@ bool PortEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command)); (new KAsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<KAsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
return false; return false;
} else { } else {

View file

@ -280,7 +280,7 @@ void SegmentMan::cancelSegment
{ {
for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(), for(SegmentEntries::iterator 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) {
cancelSegment((*itr)->segment); cancelSegment((*itr)->segment);
itr = usedSegmentEntries_.erase(itr); itr = usedSegmentEntries_.erase(itr);
//eoi = usedSegmentEntries_.end(); //eoi = usedSegmentEntries_.end();

View file

@ -44,6 +44,7 @@
#include "Command.h" #include "Command.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h" #include "Logger.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -278,8 +279,9 @@ bool SelectEventPoll::addEvents(sock_t socket, Command* command,
{ {
SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket)); SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket));
std::deque<SharedHandle<SocketEntry> >::iterator i = std::deque<SharedHandle<SocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<SocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
(*i)->addCommandEvent(command, events); (*i)->addCommandEvent(command, events);
} else { } else {
socketEntries_.insert(i, socketEntry); socketEntries_.insert(i, socketEntry);
@ -294,8 +296,9 @@ bool SelectEventPoll::deleteEvents(sock_t socket, Command* command,
{ {
SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket)); SharedHandle<SocketEntry> socketEntry(new SocketEntry(socket));
std::deque<SharedHandle<SocketEntry> >::iterator i = std::deque<SharedHandle<SocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry); std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
if(i != socketEntries_.end() && (*i) == socketEntry) { DerefLess<SharedHandle<SocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
(*i)->removeCommandEvent(command, events); (*i)->removeCommandEvent(command, events);
if((*i)->eventEmpty()) { if((*i)->eventEmpty()) {
socketEntries_.erase(i); socketEntries_.erase(i);
@ -317,7 +320,8 @@ bool SelectEventPoll::addNameResolver
SharedHandle<AsyncNameResolverEntry> entry SharedHandle<AsyncNameResolverEntry> entry
(new AsyncNameResolverEntry(resolver, command)); (new AsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.push_back(entry); nameResolverEntries_.push_back(entry);
return true; return true;
@ -332,7 +336,8 @@ bool SelectEventPoll::deleteNameResolver
SharedHandle<AsyncNameResolverEntry> entry SharedHandle<AsyncNameResolverEntry> entry
(new AsyncNameResolverEntry(resolver, command)); (new AsyncNameResolverEntry(resolver, command));
std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator itr = std::deque<SharedHandle<AsyncNameResolverEntry> >::iterator itr =
std::find(nameResolverEntries_.begin(), nameResolverEntries_.end(), entry); std::find_if(nameResolverEntries_.begin(), nameResolverEntries_.end(),
derefEqual(entry));
if(itr == nameResolverEntries_.end()) { if(itr == nameResolverEntries_.end()) {
return false; return false;
} else { } else {

View file

@ -143,7 +143,7 @@ private:
bool operator==(const AsyncNameResolverEntry& entry) bool operator==(const AsyncNameResolverEntry& entry)
{ {
return nameResolver_ == entry.nameResolver_ && return *nameResolver_ == *entry.nameResolver_ &&
command_ == entry.command_; command_ == entry.command_;
} }

View file

@ -43,6 +43,7 @@
#include "ServerStat.h" #include "ServerStat.h"
#include "util.h" #include "util.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -55,7 +56,8 @@ SharedHandle<ServerStat> ServerStatMan::find(const std::string& hostname,
{ {
SharedHandle<ServerStat> ss(new ServerStat(hostname, protocol)); SharedHandle<ServerStat> ss(new ServerStat(hostname, protocol));
std::deque<SharedHandle<ServerStat> >::const_iterator i = std::deque<SharedHandle<ServerStat> >::const_iterator i =
std::lower_bound(serverStats_.begin(), serverStats_.end(), ss); std::lower_bound(serverStats_.begin(), serverStats_.end(), ss,
DerefLess<SharedHandle<ServerStat> >());
if(i != serverStats_.end() && if(i != serverStats_.end() &&
(*i)->getHostname() == hostname && (*i)->getProtocol() == protocol) { (*i)->getHostname() == hostname && (*i)->getProtocol() == protocol) {
return *i; return *i;
@ -67,9 +69,10 @@ SharedHandle<ServerStat> ServerStatMan::find(const std::string& hostname,
bool ServerStatMan::add(const SharedHandle<ServerStat>& serverStat) bool ServerStatMan::add(const SharedHandle<ServerStat>& serverStat)
{ {
std::deque<SharedHandle<ServerStat> >::iterator i = std::deque<SharedHandle<ServerStat> >::iterator i =
std::lower_bound(serverStats_.begin(), serverStats_.end(), serverStat); std::lower_bound(serverStats_.begin(), serverStats_.end(), serverStat,
DerefLess<SharedHandle<ServerStat> >());
if(i != serverStats_.end() && (*i) == serverStat) { if(i != serverStats_.end() && *(*i) == *serverStat) {
return false; return false;
} else { } else {
serverStats_.insert(i, serverStat); serverStats_.insert(i, serverStat);
@ -79,8 +82,10 @@ bool ServerStatMan::add(const SharedHandle<ServerStat>& serverStat)
bool ServerStatMan::save(std::ostream& out) const bool ServerStatMan::save(std::ostream& out) const
{ {
std::copy(serverStats_.begin(), serverStats_.end(), for(std::deque<SharedHandle<ServerStat> >::const_iterator i =
std::ostream_iterator<SharedHandle<ServerStat> >(out, "\n")); serverStats_.begin(), eoi = serverStats_.end(); i != eoi; ++i) {
out << *(*i) << "\n";
}
out.flush(); out.flush();
return !out.bad(); return !out.bad();
} }

View file

@ -35,6 +35,7 @@
#ifndef D_SHARED_HANDLE_H #ifndef D_SHARED_HANDLE_H
#define D_SHARED_HANDLE_H #define D_SHARED_HANDLE_H
#include <cassert>
#include <iosfwd> #include <iosfwd>
namespace aria2 { namespace aria2 {
@ -236,6 +237,11 @@ public:
T* operator->() const { return obj_; } T* operator->() const { return obj_; }
T& operator*() const {
assert(obj_);
return *obj_;
}
T* get() const { T* get() const {
return obj_; return obj_;
} }
@ -273,25 +279,26 @@ static_pointer_cast(const SharedHandle<S>& t) {
return SharedHandle<T>(t, static_cast<T*>(t.get())); return SharedHandle<T>(t, static_cast<T*>(t.get()));
} }
// Intentionally renamed obj_ as obj_x to cause error
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& o, const SharedHandle<T>& sp) { std::ostream& operator<<(std::ostream& o, const SharedHandle<T>& sp) {
o << *sp.obj_; o << *sp.obj_x;
return o; return o;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator==(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) { bool operator==(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
return *t1.obj_ == *t2.obj_; return *t1.obj_x == *t2.obj_;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator!=(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) { bool operator!=(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
return *t1.obj_ != *t2.obj_; return *t1.obj_x != *t2.obj_;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator<(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) { bool operator<(const SharedHandle<T1>& t1, const SharedHandle<T2>& t2) {
return *t1.obj_ < *t2.obj_; return *t1.obj_x < *t2.obj_;
} }
template<typename T> template<typename T>
@ -357,6 +364,11 @@ public:
T* operator->() const { return obj_; } T* operator->() const { return obj_; }
T& operator*() const {
assert(obj_);
return *obj_;
}
T* get() const { T* get() const {
if(isNull()) { if(isNull()) {
return 0; return 0;
@ -378,25 +390,26 @@ public:
} }
}; };
// Intentionally renamed obj_ as obj_x to cause error
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& o, const WeakHandle<T>& sp) { std::ostream& operator<<(std::ostream& o, const WeakHandle<T>& sp) {
o << *sp.obj_; o << *sp.obj_x;
return o; return o;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator==(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) { bool operator==(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
return *t1.obj_ == *t2.obj_; return *t1.obj_x == *t2.obj_;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator!=(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) { bool operator!=(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
return *t1.obj_ != *t2.obj_; return *t1.obj_x != *t2.obj_;
} }
template<typename T1, typename T2> template<typename T1, typename T2>
bool operator<(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) { bool operator<(const WeakHandle<T1>& t1, const WeakHandle<T2>& t2) {
return *t1.obj_ < *t2.obj_; return *t1.obj_x < *t2.obj_;
} }
template<typename T, typename S> template<typename T, typename S>

View file

@ -167,7 +167,7 @@ SharedHandle<Piece> UnknownLengthPieceStorage::getPiece(size_t index)
void UnknownLengthPieceStorage::completePiece(const SharedHandle<Piece>& piece) void UnknownLengthPieceStorage::completePiece(const SharedHandle<Piece>& piece)
{ {
if(piece_ == piece) { if(*piece_ == *piece) {
downloadFinished_ = true; downloadFinished_ = true;
totalLength_ = piece_->getLength(); totalLength_ = piece_->getLength();
diskAdaptor_->setTotalLength(totalLength_); diskAdaptor_->setTotalLength(totalLength_);
@ -177,7 +177,7 @@ void UnknownLengthPieceStorage::completePiece(const SharedHandle<Piece>& piece)
void UnknownLengthPieceStorage::cancelPiece(const SharedHandle<Piece>& piece) void UnknownLengthPieceStorage::cancelPiece(const SharedHandle<Piece>& piece)
{ {
if(piece_ == piece) { if(*piece_ == *piece) {
piece_.reset(); piece_.reset();
} }
} }

View file

@ -431,6 +431,39 @@ bool in(T x, S s, S t)
return s <= x && x <= t; return s <= x && x <= t;
} }
template<typename T>
struct DerefLess {
bool operator()(const T& lhs, const T& rhs) const
{
return *lhs < *rhs;
}
};
template<typename T>
struct DerefEqualTo {
bool operator()(const T& lhs, const T& rhs) const
{
return *lhs == *rhs;
}
};
template<typename T>
struct DerefEqual {
T target;
DerefEqual(const T& t):target(t) {}
bool operator()(const T& other) const
{
return *target == *other;
}
};
template<typename T>
struct DerefEqual<T> derefEqual(const T& t)
{
return DerefEqual<T>(t);
}
} // namespace aria2 } // namespace aria2
#endif // D_A2_FUNCTIONAL_H #endif // D_A2_FUNCTIONAL_H

View file

@ -174,7 +174,7 @@ void option_processing(Option& op, std::vector<std::string>& uris,
} catch(OptionHandlerException& e) { } catch(OptionHandlerException& e) {
std::cerr << e.stackTrace() << "\n" std::cerr << e.stackTrace() << "\n"
<< "Usage:" << "\n" << "Usage:" << "\n"
<< oparser.findByName(e.getOptionName()) << *oparser.findByName(e.getOptionName())
<< std::endl; << std::endl;
exit(downloadresultcode::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} catch(Exception& e) { } catch(Exception& e) {

View file

@ -101,10 +101,10 @@ void showUsage(const std::string& keyword, const OptionParser& oparser) {
} }
std::cout << "\n" std::cout << "\n"
<< _("Options:") << "\n"; << _("Options:") << "\n";
for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
std::copy(handlers.begin(), handlers.end(), handlers.begin(), eoi = handlers.end(); i != eoi; ++i) {
std::ostream_iterator<SharedHandle<OptionHandler> > std::cout << *(*i) << "\n\n";
(std::cout, "\n\n")); }
} else { } else {
std::vector<SharedHandle<OptionHandler> > handlers = std::vector<SharedHandle<OptionHandler> > handlers =
oparser.findByNameSubstring(keyword); oparser.findByNameSubstring(keyword);
@ -113,13 +113,14 @@ void showUsage(const std::string& keyword, const OptionParser& oparser) {
" '%s'."), keyword.c_str()) " '%s'."), keyword.c_str())
<< "\n" << "\n"
<< _("Options:") << "\n"; << _("Options:") << "\n";
std::copy(handlers.begin(), handlers.end(), for(std::vector<SharedHandle<OptionHandler> >::const_iterator i =
std::ostream_iterator<SharedHandle<OptionHandler> > handlers.begin(), eoi = handlers.end(); i != eoi; ++i) {
(std::cout, "\n\n")); std::cout << *(*i) << "\n\n";
}
} else { } else {
std::cout << StringFormat(_("No option matching with '%s'."), std::cout << StringFormat(_("No option matching with '%s'."),
keyword.c_str()) keyword.c_str())
<< "\n" << oparser.findByName("help") << "\n"; << "\n" << *oparser.findByName("help") << "\n";
} }
} }

View file

@ -68,7 +68,7 @@ void BNodeTest::testFindBucketFor()
{ {
BNode b(bucket5); BNode b(bucket5);
CPPUNIT_ASSERT(bucket5 == BNode::findBucketFor(&b, localNodeID)); CPPUNIT_ASSERT(*bucket5 == *BNode::findBucketFor(&b, localNodeID));
} }
{ {
BNode b(bucket1); BNode b(bucket1);
@ -97,7 +97,7 @@ void BNodeTest::testFindBucketFor()
bp4->setLeft(bp3); bp4->setLeft(bp3);
bp4->setRight(b2); bp4->setRight(b2);
CPPUNIT_ASSERT(bucket5 == BNode::findBucketFor(bp4, localNode->getID())); CPPUNIT_ASSERT(*bucket5 == *BNode::findBucketFor(bp4, localNode->getID()));
delete bp4; delete bp4;
} }
@ -220,7 +220,7 @@ void BNodeTest::testEnumerateBucket()
std::vector<SharedHandle<DHTBucket> > buckets; std::vector<SharedHandle<DHTBucket> > buckets;
BNode::enumerateBucket(buckets, &b); BNode::enumerateBucket(buckets, &b);
CPPUNIT_ASSERT_EQUAL((size_t)1, buckets.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, buckets.size());
CPPUNIT_ASSERT(bucket1 == buckets[0]); CPPUNIT_ASSERT(*bucket1 == *buckets[0]);
} }
{ {
BNode* b1 = new BNode(bucket1); BNode* b1 = new BNode(bucket1);
@ -248,11 +248,11 @@ void BNodeTest::testEnumerateBucket()
std::vector<SharedHandle<DHTBucket> > buckets; std::vector<SharedHandle<DHTBucket> > buckets;
BNode::enumerateBucket(buckets, bp4); BNode::enumerateBucket(buckets, bp4);
CPPUNIT_ASSERT_EQUAL((size_t)5, buckets.size()); CPPUNIT_ASSERT_EQUAL((size_t)5, buckets.size());
CPPUNIT_ASSERT(bucket1 == buckets[0]); CPPUNIT_ASSERT(*bucket1 == *buckets[0]);
CPPUNIT_ASSERT(bucket3 == buckets[1]); CPPUNIT_ASSERT(*bucket3 == *buckets[1]);
CPPUNIT_ASSERT(bucket5 == buckets[2]); CPPUNIT_ASSERT(*bucket5 == *buckets[2]);
CPPUNIT_ASSERT(bucket4 == buckets[3]); CPPUNIT_ASSERT(*bucket4 == *buckets[3]);
CPPUNIT_ASSERT(bucket2 == buckets[4]); CPPUNIT_ASSERT(*bucket2 == *buckets[4]);
delete bp4; delete bp4;
} }

View file

@ -111,8 +111,8 @@ void DHTAnnouncePeerMessageTest::testDoReceivedAction()
SharedHandle<MockDHTResponseMessage> m SharedHandle<MockDHTResponseMessage> m
(dynamic_pointer_cast<MockDHTResponseMessage> (dynamic_pointer_cast<MockDHTResponseMessage>
(dispatcher.messageQueue_[0].message_)); (dispatcher.messageQueue_[0].message_));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("announce_peer"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(std::string("announce_peer"), m->getMessageType());
CPPUNIT_ASSERT_EQUAL(transactionID, m->getTransactionID()); CPPUNIT_ASSERT_EQUAL(transactionID, m->getTransactionID());
std::vector<SharedHandle<Peer> > peers; std::vector<SharedHandle<Peer> > peers;

View file

@ -319,7 +319,7 @@ void DHTBucketTest::testAddNode()
// nodes[0] is located at the tail of the bucket(least recent seen) // nodes[0] is located at the tail of the bucket(least recent seen)
nodes[0]->markBad(); nodes[0]->markBad();
CPPUNIT_ASSERT(bucket.addNode(newNode)); CPPUNIT_ASSERT(bucket.addNode(newNode));
CPPUNIT_ASSERT(bucket.getNodes().back() == newNode); CPPUNIT_ASSERT(*bucket.getNodes().back() == *newNode);
} }
void DHTBucketTest::testMoveToHead() void DHTBucketTest::testMoveToHead()
@ -337,7 +337,7 @@ void DHTBucketTest::testMoveToHead()
CPPUNIT_ASSERT(bucket.addNode(nodes[i])); CPPUNIT_ASSERT(bucket.addNode(nodes[i]));
} }
bucket.moveToHead(nodes[DHTBucket::K-1]); bucket.moveToHead(nodes[DHTBucket::K-1]);
CPPUNIT_ASSERT(bucket.getNodes().front() == nodes[DHTBucket::K-1]); CPPUNIT_ASSERT(*bucket.getNodes().front() == *nodes[DHTBucket::K-1]);
} }
void DHTBucketTest::testMoveToTail() void DHTBucketTest::testMoveToTail()
@ -355,7 +355,7 @@ void DHTBucketTest::testMoveToTail()
CPPUNIT_ASSERT(bucket.addNode(nodes[i])); CPPUNIT_ASSERT(bucket.addNode(nodes[i]));
} }
bucket.moveToTail(nodes[0]); bucket.moveToTail(nodes[0]);
CPPUNIT_ASSERT(bucket.getNodes().back() == nodes[0]); CPPUNIT_ASSERT(*bucket.getNodes().back() == *nodes[0]);
} }
void DHTBucketTest::testGetGoodNodes() void DHTBucketTest::testGetGoodNodes()
@ -400,12 +400,12 @@ void DHTBucketTest::testCacheNode()
bucket.cacheNode(n1); bucket.cacheNode(n1);
bucket.cacheNode(n2); bucket.cacheNode(n2);
CPPUNIT_ASSERT_EQUAL((size_t)2, bucket.getCachedNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)2, bucket.getCachedNodes().size());
CPPUNIT_ASSERT(n2 == bucket.getCachedNodes()[0]); CPPUNIT_ASSERT(*n2 == *bucket.getCachedNodes()[0]);
bucket.cacheNode(n3); bucket.cacheNode(n3);
CPPUNIT_ASSERT_EQUAL((size_t)2, bucket.getCachedNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)2, bucket.getCachedNodes().size());
CPPUNIT_ASSERT(n3 == bucket.getCachedNodes()[0]); CPPUNIT_ASSERT(*n3 == *bucket.getCachedNodes()[0]);
CPPUNIT_ASSERT(n2 == bucket.getCachedNodes()[1]); CPPUNIT_ASSERT(*n2 == *bucket.getCachedNodes()[1]);
} }
void DHTBucketTest::testDropNode() void DHTBucketTest::testDropNode()
@ -432,7 +432,7 @@ void DHTBucketTest::testDropNode()
{ {
std::deque<SharedHandle<DHTNode> > tnodes = bucket.getNodes(); std::deque<SharedHandle<DHTNode> > tnodes = bucket.getNodes();
CPPUNIT_ASSERT_EQUAL((size_t)8, tnodes.size()); CPPUNIT_ASSERT_EQUAL((size_t)8, tnodes.size());
CPPUNIT_ASSERT(nodes[3] == tnodes[3]); CPPUNIT_ASSERT(*nodes[3] == *tnodes[3]);
} }
bucket.cacheNode(cachedNode1); bucket.cacheNode(cachedNode1);
@ -442,11 +442,13 @@ void DHTBucketTest::testDropNode()
{ {
std::deque<SharedHandle<DHTNode> > tnodes = bucket.getNodes(); std::deque<SharedHandle<DHTNode> > tnodes = bucket.getNodes();
CPPUNIT_ASSERT_EQUAL((size_t)8, tnodes.size()); CPPUNIT_ASSERT_EQUAL((size_t)8, tnodes.size());
CPPUNIT_ASSERT(tnodes.end() == std::find(tnodes.begin(), tnodes.end(), nodes[3])); CPPUNIT_ASSERT(tnodes.end() ==
CPPUNIT_ASSERT(cachedNode2 == tnodes[7]); std::find_if(tnodes.begin(), tnodes.end(),
derefEqual(nodes[3])));
CPPUNIT_ASSERT(*cachedNode2 == *tnodes[7]);
} }
CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getCachedNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getCachedNodes().size());
CPPUNIT_ASSERT(cachedNode1 == bucket.getCachedNodes()[0]); CPPUNIT_ASSERT(*cachedNode1 == *bucket.getCachedNodes()[0]);
} }
} // namespace aria2 } // namespace aria2

View file

@ -103,8 +103,8 @@ void DHTFindNodeMessageTest::testDoReceivedAction()
SharedHandle<MockDHTResponseMessage> m SharedHandle<MockDHTResponseMessage> m
(dynamic_pointer_cast<MockDHTResponseMessage> (dynamic_pointer_cast<MockDHTResponseMessage>
(dispatcher.messageQueue_[0].message_)); (dispatcher.messageQueue_[0].message_));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("find_node"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(std::string("find_node"), m->getMessageType());
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID()); CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
CPPUNIT_ASSERT_EQUAL((size_t)1, m->nodes_.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, m->nodes_.size());

View file

@ -124,8 +124,8 @@ void DHTGetPeersMessageTest::testDoReceivedAction()
SharedHandle<MockDHTResponseMessage> m SharedHandle<MockDHTResponseMessage> m
(dynamic_pointer_cast<MockDHTResponseMessage> (dynamic_pointer_cast<MockDHTResponseMessage>
(dispatcher.messageQueue_[0].message_)); (dispatcher.messageQueue_[0].message_));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID()); CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_); CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_);
@ -161,13 +161,13 @@ void DHTGetPeersMessageTest::testDoReceivedAction()
SharedHandle<MockDHTResponseMessage> m SharedHandle<MockDHTResponseMessage> m
(dynamic_pointer_cast<MockDHTResponseMessage> (dynamic_pointer_cast<MockDHTResponseMessage>
(dispatcher.messageQueue_[0].message_)); (dispatcher.messageQueue_[0].message_));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID()); CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_); CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_);
CPPUNIT_ASSERT_EQUAL((size_t)1, m->nodes_.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, m->nodes_.size());
CPPUNIT_ASSERT(returnNode1 == m->nodes_[0]); CPPUNIT_ASSERT(*returnNode1 == *m->nodes_[0]);
CPPUNIT_ASSERT_EQUAL((size_t)0, m->peers_.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, m->peers_.size());
} }
} }

View file

@ -58,11 +58,11 @@ void DHTIDCloserTest::testOperator()
std::sort(entries.begin(), entries.end(), DHTIDCloser(e3->node->getID())); std::sort(entries.begin(), entries.end(), DHTIDCloser(e3->node->getID()));
CPPUNIT_ASSERT(e3 == entries[0]); CPPUNIT_ASSERT(*e3 == *entries[0]);
CPPUNIT_ASSERT(e2 == entries[1]); CPPUNIT_ASSERT(*e2 == *entries[1]);
CPPUNIT_ASSERT(e4 == entries[2]); CPPUNIT_ASSERT(*e4 == *entries[2]);
CPPUNIT_ASSERT(e1 == entries[3]); CPPUNIT_ASSERT(*e1 == *entries[3]);
CPPUNIT_ASSERT(e5 == entries[4]); CPPUNIT_ASSERT(*e5 == *entries[4]);
} }
} // namespace aria2 } // namespace aria2

View file

@ -100,8 +100,8 @@ void DHTMessageFactoryImplTest::testCreatePingMessage()
remoteNode->setIPAddress("192.168.0.1"); remoteNode->setIPAddress("192.168.0.1");
remoteNode->setPort(6881); remoteNode->setPort(6881);
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} }
@ -125,8 +125,8 @@ void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} }
@ -151,8 +151,8 @@ void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
remoteNode->setIPAddress("192.168.0.1"); remoteNode->setIPAddress("192.168.0.1");
remoteNode->setPort(6881); remoteNode->setPort(6881);
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
CPPUNIT_ASSERT_EQUAL(util::toHex(targetNodeID, DHT_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(targetNodeID, DHT_ID_LENGTH),
@ -196,11 +196,11 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
CPPUNIT_ASSERT(nodes[0] == m->getClosestKNodes()[0]); CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
CPPUNIT_ASSERT(nodes[7] == m->getClosestKNodes()[7]); CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} catch(Exception& e) { } catch(Exception& e) {
@ -249,11 +249,11 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage6()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
CPPUNIT_ASSERT(nodes[0] == m->getClosestKNodes()[0]); CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
CPPUNIT_ASSERT(nodes[7] == m->getClosestKNodes()[7]); CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} catch(Exception& e) { } catch(Exception& e) {
@ -282,8 +282,8 @@ void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
remoteNode->setIPAddress("192.168.0.1"); remoteNode->setIPAddress("192.168.0.1");
remoteNode->setPort(6881); remoteNode->setPort(6881);
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
CPPUNIT_ASSERT_EQUAL(util::toHex(infoHash, DHT_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(infoHash, DHT_ID_LENGTH),
@ -343,15 +343,15 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("token"), m->getToken()); CPPUNIT_ASSERT_EQUAL(std::string("token"), m->getToken());
CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
CPPUNIT_ASSERT(nodes[0] == m->getClosestKNodes()[0]); CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
CPPUNIT_ASSERT(nodes[7] == m->getClosestKNodes()[7]); CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
CPPUNIT_ASSERT_EQUAL((size_t)4, m->getValues().size()); CPPUNIT_ASSERT_EQUAL((size_t)4, m->getValues().size());
CPPUNIT_ASSERT(peers[0] == m->getValues()[0]); CPPUNIT_ASSERT(*peers[0] == *m->getValues()[0]);
CPPUNIT_ASSERT(peers[3] == m->getValues()[3]); CPPUNIT_ASSERT(*peers[3] == *m->getValues()[3]);
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} catch(Exception& e) { } catch(Exception& e) {
@ -416,15 +416,15 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage6()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("token"), m->getToken()); CPPUNIT_ASSERT_EQUAL(std::string("token"), m->getToken());
CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size()); CPPUNIT_ASSERT_EQUAL((size_t)DHTBucket::K, m->getClosestKNodes().size());
CPPUNIT_ASSERT(nodes[0] == m->getClosestKNodes()[0]); CPPUNIT_ASSERT(*nodes[0] == *m->getClosestKNodes()[0]);
CPPUNIT_ASSERT(nodes[7] == m->getClosestKNodes()[7]); CPPUNIT_ASSERT(*nodes[7] == *m->getClosestKNodes()[7]);
CPPUNIT_ASSERT_EQUAL((size_t)4, m->getValues().size()); CPPUNIT_ASSERT_EQUAL((size_t)4, m->getValues().size());
CPPUNIT_ASSERT(peers[0] == m->getValues()[0]); CPPUNIT_ASSERT(*peers[0] == *m->getValues()[0]);
CPPUNIT_ASSERT(peers[3] == m->getValues()[3]); CPPUNIT_ASSERT(*peers[3] == *m->getValues()[3]);
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} catch(Exception& e) { } catch(Exception& e) {
@ -458,8 +458,8 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
remoteNode->setIPAddress("192.168.0.1"); remoteNode->setIPAddress("192.168.0.1");
remoteNode->setPort(6882); remoteNode->setPort(6882);
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(token, m->getToken()); CPPUNIT_ASSERT_EQUAL(token, m->getToken());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
@ -490,8 +490,8 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
remoteNode->getIPAddress(), remoteNode->getIPAddress(),
remoteNode->getPort()))); remoteNode->getPort())));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH), CPPUNIT_ASSERT_EQUAL(util::toHex(transactionID, DHT_TRANSACTION_ID_LENGTH),
util::toHex(m->getTransactionID())); util::toHex(m->getTransactionID()));
} }

View file

@ -92,8 +92,8 @@ void DHTPingMessageTest::testDoReceivedAction()
SharedHandle<MockDHTResponseMessage> m SharedHandle<MockDHTResponseMessage> m
(dynamic_pointer_cast<MockDHTResponseMessage> (dynamic_pointer_cast<MockDHTResponseMessage>
(dispatcher.messageQueue_[0].message_)); (dispatcher.messageQueue_[0].message_));
CPPUNIT_ASSERT(localNode == m->getLocalNode()); CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode()); CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
CPPUNIT_ASSERT_EQUAL(std::string("ping_reply"), m->getMessageType()); CPPUNIT_ASSERT_EQUAL(std::string("ping_reply"), m->getMessageType());
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID()); CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
} }

View file

@ -210,16 +210,16 @@ void DefaultBtRequestFactoryTest::testRemoveTargetPiece() {
requestFactory_->addTargetPiece(piece1); requestFactory_->addTargetPiece(piece1);
CPPUNIT_ASSERT(std::find(requestFactory_->getTargetPieces().begin(), CPPUNIT_ASSERT(std::find_if(requestFactory_->getTargetPieces().begin(),
requestFactory_->getTargetPieces().end(), requestFactory_->getTargetPieces().end(),
piece1) != derefEqual(piece1)) !=
requestFactory_->getTargetPieces().end()); requestFactory_->getTargetPieces().end());
requestFactory_->removeTargetPiece(piece1); requestFactory_->removeTargetPiece(piece1);
CPPUNIT_ASSERT(std::find(requestFactory_->getTargetPieces().begin(), CPPUNIT_ASSERT(std::find_if(requestFactory_->getTargetPieces().begin(),
requestFactory_->getTargetPieces().end(), requestFactory_->getTargetPieces().end(),
piece1) == derefEqual(piece1)) ==
requestFactory_->getTargetPieces().end()); requestFactory_->getTargetPieces().end());
} }

View file

@ -121,7 +121,8 @@ void DefaultPeerStorageTest::testAddPeer() {
CPPUNIT_ASSERT(ps.addPeer(peer4)); CPPUNIT_ASSERT(ps.addPeer(peer4));
// peer2 was deleted. While peer1 is oldest, its cuid is not 0. // peer2 was deleted. While peer1 is oldest, its cuid is not 0.
CPPUNIT_ASSERT_EQUAL((size_t)3, ps.countPeer()); CPPUNIT_ASSERT_EQUAL((size_t)3, ps.countPeer());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer2) == ps.getPeers().end()); CPPUNIT_ASSERT(std::find_if(ps.getPeers().begin(), ps.getPeers().end(),
derefEqual(peer2)) == ps.getPeers().end());
SharedHandle<Peer> peer5(new Peer("192.168.0.4", 0)); SharedHandle<Peer> peer5(new Peer("192.168.0.4", 0));
@ -224,13 +225,14 @@ void DefaultPeerStorageTest::testReturnPeer()
ps.returnPeer(peer2); // peer2 removed from the container ps.returnPeer(peer2); // peer2 removed from the container
CPPUNIT_ASSERT_EQUAL((size_t)2, ps.getPeers().size()); CPPUNIT_ASSERT_EQUAL((size_t)2, ps.getPeers().size());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer2) CPPUNIT_ASSERT(std::find_if(ps.getPeers().begin(), ps.getPeers().end(),
== ps.getPeers().end()); derefEqual(peer2)) == ps.getPeers().end());
CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getDroppedPeers().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getDroppedPeers().size());
ps.returnPeer(peer1); // peer1 is removed from the container ps.returnPeer(peer1); // peer1 is removed from the container
CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getPeers().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getPeers().size());
CPPUNIT_ASSERT(std::find(ps.getPeers().begin(), ps.getPeers().end(), peer1) == ps.getPeers().end()); CPPUNIT_ASSERT(std::find_if(ps.getPeers().begin(), ps.getPeers().end(),
derefEqual(peer1)) == ps.getPeers().end());
CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getDroppedPeers().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, ps.getDroppedPeers().size());
} }

View file

@ -35,7 +35,7 @@ void SequentialPickerTest::testPick()
picker.pickNext(); picker.pickNext();
CPPUNIT_ASSERT(picker.isPicked()); CPPUNIT_ASSERT(picker.isPicked());
CPPUNIT_ASSERT_EQUAL(Integer(new int(1)), picker.getPickedEntry()); CPPUNIT_ASSERT_EQUAL(*Integer(new int(1)), *picker.getPickedEntry());
picker.dropPickedEntry(); picker.dropPickedEntry();
@ -44,7 +44,7 @@ void SequentialPickerTest::testPick()
picker.pickNext(); picker.pickNext();
CPPUNIT_ASSERT_EQUAL(Integer(new int(2)), picker.getPickedEntry()); CPPUNIT_ASSERT_EQUAL(*Integer(new int(2)), *picker.getPickedEntry());
CPPUNIT_ASSERT(!picker.hasNext()); CPPUNIT_ASSERT(!picker.hasNext());
} }

View file

@ -51,7 +51,7 @@ void SingletonHolderTest::testInstance()
IntHandle i(new int(100)); IntHandle i(new int(100));
SingletonHolder<IntHandle>::instance(i); SingletonHolder<IntHandle>::instance(i);
std::cerr << SingletonHolder<IntHandle>::instance() << std::endl; std::cerr << *SingletonHolder<IntHandle>::instance() << std::endl;
std::cerr << SingletonHolder<MHandle>::instance()->greeting() << std::endl; std::cerr << SingletonHolder<MHandle>::instance()->greeting() << std::endl;