Skip to content

Commit

Permalink
2010-11-11 Tatsuhiro Tsujikawa <[email protected]>
Browse files Browse the repository at this point in the history
	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
  • Loading branch information
tatsuhiro-t committed Nov 11, 2010
1 parent bcf4593 commit bc98e39
Show file tree
Hide file tree
Showing 41 changed files with 306 additions and 167 deletions.
47 changes: 47 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
2010-11-11 Tatsuhiro Tsujikawa <[email protected]>

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 <[email protected]>

Create SharedHandle outside of function call to avoid unexpected
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void AbstractCommand::setReadCheckSocket(const SocketHandle& socket) {
disableReadCheckSocket();
} else {
if(checkSocketIsReadable_) {
if(readCheckTarget_ != socket) {
if(*readCheckTarget_ != *socket) {
e_->deleteSocketForReadCheck(readCheckTarget_, this);
e_->addSocketForReadCheck(socket, this);
readCheckTarget_ = socket;
Expand Down Expand Up @@ -498,7 +498,7 @@ void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
disableWriteCheckSocket();
} else {
if(checkSocketIsWritable_) {
if(writeCheckTarget_ != socket) {
if(*writeCheckTarget_ != *socket) {
e_->deleteSocketForWriteCheck(writeCheckTarget_, this);
e_->addSocketForWriteCheck(socket, this);
writeCheckTarget_ = socket;
Expand Down
8 changes: 6 additions & 2 deletions src/DHTAbstractNodeLookupTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "Logger.h"
#include "util.h"
#include "DHTIDCloser.h"
#include "a2functional.h"

namespace aria2 {

Expand Down Expand Up @@ -203,7 +204,10 @@ class DHTAbstractNodeLookupTask:public DHTAbstractTask {
static_cast<unsigned long>(count));
}
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()) {
getLogger()->debug("%lu node lookup entries are unique.",
static_cast<unsigned long>(entries_.size()));
Expand All @@ -223,7 +227,7 @@ class DHTAbstractNodeLookupTask:public DHTAbstractTask {
--inFlightMessage_;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->node == node) {
if(*(*i)->node == *node) {
entries_.erase(i);
break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/DHTBucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool DHTBucket::addNode(const SharedHandle<DHTNode>& node)
{
notifyUpdate();
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(nodes_.size() < K) {
nodes_.push_back(node);
Expand Down Expand Up @@ -145,7 +145,7 @@ void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
{
if(cachedNodes_.size()) {
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()) {
nodes_.erase(itr);
nodes_.push_back(cachedNodes_.front());
Expand All @@ -157,7 +157,7 @@ void DHTBucket::dropNode(const SharedHandle<DHTNode>& node)
void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
{
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()) {
nodes_.erase(itr);
nodes_.push_front(node);
Expand All @@ -167,7 +167,7 @@ void DHTBucket::moveToHead(const SharedHandle<DHTNode>& node)
void DHTBucket::moveToTail(const SharedHandle<DHTNode>& node)
{
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()) {
nodes_.erase(itr);
nodes_.push_back(node);
Expand Down Expand Up @@ -233,7 +233,7 @@ SharedHandle<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std:
node->setIPAddress(ipaddr);
node->setPort(port);
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()) {
return SharedHandle<DHTNode>();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/DHTMessageReceiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
} else {
SharedHandle<DHTQueryMessage> message =
factory_->createQueryMessage(dict, remoteAddr, remotePort);
if(message->getLocalNode() == message->getRemoteNode()) {
if(*message->getLocalNode() == *message->getRemoteNode()) {
// drop message from localnode
logger_->info("Received DHT message from localnode.");
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
Expand Down
2 changes: 1 addition & 1 deletion src/DHTNodeLookupEntry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DHTNodeLookupEntry::DHTNodeLookupEntry():

bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const
{
return node == entry.node;
return *node == *entry.node;
}

} // namespace aria2
2 changes: 1 addition & 1 deletion src/DHTRoutingTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
if(logger_->debug()) {
logger_->debug("Trying to add node:%s", node->toString().c_str());
}
if(localNode_ == node) {
if(*localNode_ == *node) {
if(logger_->debug()) {
logger_->debug("Adding node with the same ID with localnode is not"
" allowed.");
Expand Down
5 changes: 3 additions & 2 deletions src/DefaultBtRequestFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ void DefaultBtRequestFactory::removeCompletedPiece() {
void DefaultBtRequestFactory::removeTargetPiece
(const SharedHandle<Piece>& piece)
{
pieces_.erase(std::remove(pieces_.begin(), pieces_.end(), piece),
pieces_.end());
pieces_.erase(std::remove_if(pieces_.begin(), pieces_.end(),
derefEqual(piece)),
pieces_.end());
dispatcher_->doAbortOutstandingRequestAction(piece);
pieceStorage_->cancelPiece(piece);
}
Expand Down
5 changes: 3 additions & 2 deletions src/DefaultPeerStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "BtLeecherStateChoke.h"
#include "PieceStorage.h"
#include "wallclock.h"
#include "a2functional.h"

namespace aria2 {

Expand Down Expand Up @@ -75,7 +76,7 @@ class FindIdenticalPeer {
FindIdenticalPeer(const SharedHandle<Peer>& peer):peer_(peer) {}

bool operator()(const SharedHandle<Peer>& peer) const {
return (peer_ == peer) ||
return (*peer_ == *peer) ||
((peer_->getIPAddress() == peer->getIPAddress()) &&
(peer_->getPort() == peer->getPort()));
}
Expand Down Expand Up @@ -337,7 +338,7 @@ void DefaultPeerStorage::onReturningPeer(const SharedHandle<Peer>& peer)
void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer)
{
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(logger_->debug()) {
logger_->debug("Cannot find peer %s:%u in PeerStorage.",
Expand Down
16 changes: 10 additions & 6 deletions src/DefaultPieceStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ SharedHandle<Piece> DefaultPieceStorage::getPiece(size_t index)
void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece)
{
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);
if(logger_->debug()) {
logger_->debug("usedPieces_.size()=%lu",
Expand All @@ -141,8 +142,9 @@ SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
p->setIndex(index);

std::deque<SharedHandle<Piece> >::const_iterator i =
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), p);
if(i != usedPieces_.end() && (*i) == p) {
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), p,
DerefLess<SharedHandle<Piece> >());
if(i != usedPieces_.end() && *(*i) == *p) {
return *i;
} else {
p.reset(0);
Expand Down Expand Up @@ -365,8 +367,9 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
return;
}
std::deque<SharedHandle<Piece> >::iterator i =
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece);
if(i != usedPieces_.end() && (*i) == piece) {
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece,
DerefLess<SharedHandle<Piece> >());
if(i != usedPieces_.end() && *(*i) == *piece) {
usedPieces_.erase(i);
}
}
Expand Down Expand Up @@ -723,7 +726,8 @@ void DefaultPieceStorage::addInFlightPiece
(const std::vector<SharedHandle<Piece> >& pieces)
{
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()
Expand Down
4 changes: 3 additions & 1 deletion src/DownloadContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "util.h"
#include "wallclock.h"
#include "DlAbortEx.h"
#include "a2functional.h"

namespace aria2 {

Expand Down Expand Up @@ -102,7 +103,8 @@ DownloadContext::findFileEntryByOffset(off_t offset) const
SharedHandle<FileEntry> obj(new FileEntry());
obj->setOffset(offset);
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) {
return *i;
} else {
Expand Down
17 changes: 11 additions & 6 deletions src/EpollEventPoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "LogFactory.h"
#include "Logger.h"
#include "util.h"
#include "a2functional.h"

namespace aria2 {

Expand Down Expand Up @@ -166,10 +167,11 @@ bool EpollEventPoll::addEvents(sock_t socket,
{
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
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 errNum = 0;
if(i != socketEntries_.end() && (*i) == socketEntry) {
if(i != socketEntries_.end() && *(*i) == *socketEntry) {

event.addSelf(*i);

Expand Down Expand Up @@ -229,8 +231,9 @@ bool EpollEventPoll::deleteEvents(sock_t socket,
{
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry);
if(i != socketEntries_.end() && (*i) == socketEntry) {
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {

event.removeSelf(*i);

Expand Down Expand Up @@ -295,7 +298,8 @@ bool EpollEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
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()) {
nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this);
Expand All @@ -311,7 +315,8 @@ bool EpollEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
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()) {
return false;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ADNSEvent : public Event<SocketEntry> {

bool operator==(const ADNSEvent& event) const
{
return resolver_ == event.resolver_;
return *resolver_ == *event.resolver_;
}

virtual int getEvents() const
Expand Down Expand Up @@ -323,7 +323,7 @@ class AsyncNameResolverEntry {

bool operator==(const AsyncNameResolverEntry& entry)
{
return nameResolver_ == entry.nameResolver_ &&
return *nameResolver_ == *entry.nameResolver_ &&
command_ == entry.command_;
}

Expand Down
2 changes: 1 addition & 1 deletion src/HttpConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool HttpConnection::isIssued(const SharedHandle<Segment>& segment) const
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests_.begin(),
eoi = outstandingHttpRequests_.end(); itr != eoi; ++itr) {
SharedHandle<HttpRequest> httpRequest = (*itr)->getHttpRequest();
if(httpRequest->getSegment() == segment) {
if(*httpRequest->getSegment() == *segment) {
return true;
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/KqueueEventPoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ bool KqueueEventPoll::addEvents
{
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
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;
struct timespec zeroTimeout = { 0, 0 };
struct kevent changelist[2];
size_t n;
if(i != socketEntries_.end() && (*i) == socketEntry) {
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i);
n = (*i)->getEvents(changelist);
} else {
Expand Down Expand Up @@ -221,8 +222,9 @@ bool KqueueEventPoll::deleteEvents(sock_t socket,
{
SharedHandle<KSocketEntry> socketEntry(new KSocketEntry(socket));
std::deque<SharedHandle<KSocketEntry> >::iterator i =
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry);
if(i != socketEntries_.end() && (*i) == socketEntry) {
std::lower_bound(socketEntries_.begin(), socketEntries_.end(), socketEntry,
DerefLess<SharedHandle<KSocketEntry> >());
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.removeSelf(*i);
int r = 0;
struct timespec zeroTimeout = { 0, 0 };
Expand Down Expand Up @@ -272,7 +274,8 @@ bool KqueueEventPoll::addNameResolver
SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
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()) {
nameResolverEntries_.push_back(entry);
entry->addSocketEvents(this);
Expand All @@ -288,7 +291,8 @@ bool KqueueEventPoll::deleteNameResolver
SharedHandle<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
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()) {
return false;
} else {
Expand Down
Loading

0 comments on commit bc98e39

Please sign in to comment.