From 93e5dbed325f29c1bf867a2847d3b839d545cfb2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 12 Nov 2010 12:48:48 +0000 Subject: [PATCH] 2010-11-12 Tatsuhiro Tsujikawa Removed SharedHandle::isNull(). Instead we added operator* and operator unspecified_bool_type. Removed use of WeakHandle and replaced with raw pointer. --- ChangeLog | 6 + src/AbstractBtMessage.cc | 15 ++- src/AbstractBtMessage.h | 25 ++-- src/AbstractCommand.cc | 48 +++---- src/AbstractProxyResponseCommand.cc | 2 +- src/ActivePeerConnectionCommand.cc | 2 +- src/AdaptiveFileAllocationIterator.cc | 4 +- src/AdaptiveFileAllocationIterator.h | 2 +- src/AdaptiveURISelector.cc | 10 +- src/AuthConfigFactory.cc | 4 +- src/BNode.cc | 8 +- src/BtDependency.cc | 2 +- src/BtDependency.h | 4 +- src/BtExtendedMessage.cc | 4 +- src/BtMessageDispatcher.h | 1 - src/BtMessageFactory.h | 1 - src/BtMessageReceiver.h | 1 - src/BtPortMessage.cc | 17 ++- src/BtPortMessage.h | 16 +-- src/BtPostDownloadHandler.cc | 2 +- src/BtRegistry.h | 12 +- src/BtRequestFactory.h | 1 - src/CheckIntegrityEntry.cc | 4 +- src/ConsoleStatCalc.cc | 6 +- src/CreateRequestCommand.cc | 4 +- src/DHTAbstractMessage.cc | 19 +-- src/DHTAbstractMessage.h | 24 ++-- src/DHTAbstractTask.cc | 14 +- src/DHTAbstractTask.h | 24 ++-- src/DHTAnnouncePeerMessage.cc | 9 +- src/DHTAnnouncePeerMessage.h | 8 +- src/DHTEntryPointNameResolveCommand.cc | 2 +- src/DHTGetPeersCommand.cc | 4 +- src/DHTGetPeersMessage.cc | 10 +- src/DHTGetPeersMessage.h | 9 +- src/DHTInteractionCommand.cc | 2 +- src/DHTMessageFactoryImpl.cc | 23 ++-- src/DHTMessageFactoryImpl.h | 21 ++- src/DHTMessageReceiver.cc | 4 +- src/DHTMessageTracker.cc | 2 +- src/DHTNodeLookupEntry.cc | 2 +- src/DHTReplaceNodeTask.cc | 2 +- src/DHTSetup.cc | 20 +-- src/DHTTaskFactoryImpl.cc | 12 +- src/DHTTaskFactoryImpl.h | 16 +-- src/DefaultAuthResolver.cc | 2 +- src/DefaultBtAnnounce.cc | 4 +- src/DefaultBtInteractive.cc | 13 +- src/DefaultBtInteractive.h | 8 +- src/DefaultBtMessageDispatcher.cc | 12 +- src/DefaultBtMessageDispatcher.h | 8 +- src/DefaultBtMessageFactory.cc | 35 ++--- src/DefaultBtMessageFactory.h | 30 ++--- src/DefaultBtMessageReceiver.cc | 14 +- src/DefaultBtMessageReceiver.h | 12 +- src/DefaultBtProgressInfoFile.cc | 2 +- src/DefaultBtRequestFactory.cc | 15 ++- src/DefaultBtRequestFactory.h | 9 +- src/DefaultExtensionMessageFactory.cc | 3 + src/DefaultExtensionMessageFactory.h | 13 +- src/DefaultPeerStorage.cc | 4 +- src/DefaultPieceStorage.cc | 12 +- src/DownloadCommand.cc | 6 +- src/DownloadEngine.cc | 10 +- src/DownloadHandler.cc | 2 +- src/DownloadHandlerFactory.cc | 10 +- src/Exception.cc | 2 +- src/FeatureConfig.cc | 2 +- src/FeedbackURISelector.cc | 4 +- src/FileEntry.cc | 12 +- src/FileEntry.h | 2 +- src/FtpConnection.cc | 2 +- src/FtpInitiateConnectionCommand.cc | 6 +- src/FtpNegotiationCommand.cc | 10 +- src/HaveEraseCommand.cc | 2 +- src/HttpInitiateConnectionCommand.cc | 6 +- src/HttpListenCommand.cc | 6 +- src/HttpRequest.cc | 28 ++-- src/HttpRequest.h | 2 +- src/HttpRequestCommand.cc | 2 +- src/HttpResponse.cc | 6 +- src/HttpResponseCommand.cc | 20 +-- src/HttpServer.cc | 2 +- src/HttpServerCommand.cc | 2 +- src/HttpSkipResponseCommand.cc | 2 +- src/InitiateConnectionCommand.cc | 2 +- src/LpdReceiveMessageCommand.cc | 8 +- src/MSEHandshake.cc | 2 +- src/Metalink2RequestGroup.cc | 14 +- src/MetalinkParserController.cc | 94 ++++++------- src/MetalinkPostDownloadHandler.cc | 2 +- src/MultiDiskAdaptor.cc | 6 +- src/MultiFileAllocationIterator.cc | 8 +- src/Netrc.cc | 4 +- src/NetrcAuthResolver.cc | 6 +- src/OptionParser.cc | 4 +- src/PStringBuildVisitor.cc | 2 +- src/PStringSegment.cc | 2 +- src/Peer.cc | 2 +- src/Peer.h | 2 +- src/PeerAbstractCommand.cc | 2 +- src/PeerConnection.h | 1 - src/PeerInteractionCommand.cc | 64 ++++----- src/PeerListenCommand.cc | 2 +- src/PeerReceiveHandshakeCommand.cc | 4 +- src/PeerSessionResource.cc | 8 +- src/PeerSessionResource.h | 4 +- src/Piece.cc | 6 +- src/RequestGroup.cc | 74 +++++----- src/RequestGroup.h | 4 +- src/RequestGroupMan.cc | 10 +- src/SegmentMan.cc | 12 +- src/SequentialPicker.h | 2 +- src/SessionSerializer.cc | 4 +- src/SharedHandle.h | 26 ++-- src/SimpleRandomizer.cc | 2 +- src/StreamFileAllocationEntry.cc | 2 +- src/StreamFilter.cc | 2 +- src/TrackerWatcherCommand.cc | 8 +- src/UTMetadataDataExtensionMessage.cc | 1 + src/UTMetadataDataExtensionMessage.h | 5 +- src/UTMetadataPostDownloadHandler.cc | 2 +- src/UTMetadataRequestExtensionMessage.cc | 5 +- src/UTMetadataRequestExtensionMessage.h | 8 +- src/UTMetadataRequestFactory.cc | 5 +- src/UTMetadataRequestFactory.h | 13 +- src/UnknownLengthPieceStorage.cc | 8 +- src/XmlRpcMethod.cc | 2 +- src/XmlRpcMethodImpl.cc | 46 +++---- src/XmlRpcRequestParserController.cc | 2 +- src/XmlRpcRequestParserController.h | 2 +- src/bittorrent_helper.cc | 2 +- src/option_processing.cc | 2 +- test/AuthConfigFactoryTest.cc | 16 +-- test/BNodeTest.cc | 2 +- test/Bencode2Test.cc | 2 +- test/BtCancelMessageTest.cc | 2 +- test/BtChokeMessageTest.cc | 8 +- test/BtDependencyTest.cc | 16 +-- test/BtPieceMessageTest.cc | 4 +- test/BtPortMessageTest.cc | 16 +-- test/BtRegistryTest.cc | 6 +- test/BtRejectMessageTest.cc | 2 +- test/BtRequestMessageTest.cc | 4 +- test/DHTAnnouncePeerMessageTest.cc | 7 +- test/DHTFindNodeMessageTest.cc | 6 +- test/DHTGetPeersMessageTest.cc | 17 +-- test/DHTMessageFactoryImplTest.cc | 6 +- test/DHTMessageTrackerTest.cc | 10 +- test/DHTPingMessageTest.cc | 4 +- test/DefaultBtMessageDispatcherTest.cc | 4 +- test/DefaultBtMessageFactoryTest.cc | 2 +- test/DefaultBtRequestFactoryTest.cc | 6 +- test/DefaultExtensionMessageFactoryTest.cc | 4 +- test/DefaultPeerStorageTest.cc | 4 +- test/DefaultPieceStorageTest.cc | 8 +- test/DownloadContextTest.cc | 4 +- test/FileEntryTest.cc | 8 +- test/HttpHeaderProcessorTest.cc | 2 +- test/HttpResponseTest.cc | 12 +- test/LpdMessageReceiverTest.cc | 12 +- test/MagnetTest.cc | 2 +- test/Metalink2RequestGroupTest.cc | 12 +- test/MetalinkParserControllerTest.cc | 14 +- test/MetalinkProcessorTest.cc | 22 +-- test/MultiDiskAdaptorTest.cc | 126 +++++++++--------- test/MultiFileAllocationIteratorTest.cc | 22 +-- test/NetrcTest.cc | 14 +- test/OptionParserTest.cc | 14 +- test/ParameterizedStringParserTest.cc | 20 +-- test/PeerSessionResourceTest.cc | 2 +- test/RequestGroupManTest.cc | 2 +- test/SegmentManTest.cc | 28 ++-- test/ServerStatManTest.cc | 14 +- test/SharedHandleTest.cc | 3 +- test/UTMetadataDataExtensionMessageTest.cc | 2 +- test/UTMetadataRequestExtensionMessageTest.cc | 14 +- test/UTMetadataRequestFactoryTest.cc | 4 +- test/ValueBaseTest.cc | 2 +- test/XmlRpcMethodTest.cc | 6 +- test/XmlRpcRequestProcessorTest.cc | 2 +- 181 files changed, 911 insertions(+), 876 deletions(-) diff --git a/ChangeLog b/ChangeLog index b38d78bb..395e71bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-11-12 Tatsuhiro Tsujikawa + + Removed SharedHandle::isNull(). Instead we added operator* and + operator unspecified_bool_type. Removed use of WeakHandle and + replaced with raw pointer. + 2010-11-11 Tatsuhiro Tsujikawa Fixed memory leak diff --git a/src/AbstractBtMessage.cc b/src/AbstractBtMessage.cc index 38c15be6..07f88f5c 100644 --- a/src/AbstractBtMessage.cc +++ b/src/AbstractBtMessage.cc @@ -48,6 +48,10 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name): uploading_(false), cuid_(0), name_(name), + dispatcher_(0), + messageFactory_(0), + requestFactory_(0), + peerConnection_(0), metadataGetMode_(false), logger_(LogFactory::getInstance()) {} @@ -61,7 +65,7 @@ void AbstractBtMessage::setPeer(const SharedHandle& peer) void AbstractBtMessage::validate() { - if(!validator_.isNull()) { + if(validator_) { validator_->validate(); } } @@ -77,23 +81,22 @@ void AbstractBtMessage::setPieceStorage pieceStorage_ = pieceStorage; } -void AbstractBtMessage::setBtMessageDispatcher -(const WeakHandle& dispatcher) +void AbstractBtMessage::setBtMessageDispatcher(BtMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void AbstractBtMessage::setPeerConnection(const WeakHandle& peerConnection) +void AbstractBtMessage::setPeerConnection(PeerConnection* peerConnection) { peerConnection_ = peerConnection; } -void AbstractBtMessage::setBtMessageFactory(const WeakHandle& factory) +void AbstractBtMessage::setBtMessageFactory(BtMessageFactory* factory) { messageFactory_ = factory; } -void AbstractBtMessage::setBtRequestFactory(const WeakHandle& factory) +void AbstractBtMessage::setBtRequestFactory(BtRequestFactory* factory) { requestFactory_ = factory; } diff --git a/src/AbstractBtMessage.h b/src/AbstractBtMessage.h index 09cf05d3..52cd24a3 100644 --- a/src/AbstractBtMessage.h +++ b/src/AbstractBtMessage.h @@ -62,13 +62,13 @@ private: SharedHandle peer_; - WeakHandle dispatcher_; + BtMessageDispatcher* dispatcher_; - WeakHandle messageFactory_; + BtMessageFactory* messageFactory_; - WeakHandle requestFactory_; + BtRequestFactory* requestFactory_; - WeakHandle peerConnection_; + PeerConnection* peerConnection_; SharedHandle validator_; @@ -86,22 +86,22 @@ protected: return pieceStorage_; } - const WeakHandle& getPeerConnection() const + PeerConnection* getPeerConnection() const { return peerConnection_; } - const WeakHandle& getBtMessageDispatcher() const + BtMessageDispatcher* getBtMessageDispatcher() const { return dispatcher_; } - const WeakHandle& getBtRequestFactory() const + BtRequestFactory* getBtRequestFactory() const { return requestFactory_; } - const WeakHandle& getBtMessageFactory() const + BtMessageFactory* getBtMessageFactory() const { return messageFactory_; } @@ -172,14 +172,13 @@ public: void setPieceStorage(const SharedHandle& pieceStorage); - void setBtMessageDispatcher - (const WeakHandle& dispatcher); + void setBtMessageDispatcher(BtMessageDispatcher* dispatcher); - void setPeerConnection(const WeakHandle& peerConnection); + void setPeerConnection(PeerConnection* peerConnection); - void setBtMessageFactory(const WeakHandle& factory); + void setBtMessageFactory(BtMessageFactory* factory); - void setBtRequestFactory(const WeakHandle& factory); + void setBtRequestFactory(BtRequestFactory* factory); const std::string& getName() const { diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 1375c8b3..aad57e5a 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -90,7 +90,7 @@ AbstractCommand::AbstractCommand(cuid_t cuid, nameResolverCheck_(false), incNumConnection_(incNumConnection) { - if(!socket_.isNull() && socket_->isOpen()) { + if(socket_ && socket_->isOpen()) { setReadCheckSocket(socket_); } if(incNumConnection_) { @@ -126,7 +126,7 @@ bool AbstractCommand::execute() { if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) { return true; } - if(!req_.isNull() && req_->removalRequested()) { + if(req_ && req_->removalRequested()) { if(getLogger()->debug()) { getLogger()->debug ("CUID#%s - Discard original URI=%s because it is requested.", @@ -134,10 +134,10 @@ bool AbstractCommand::execute() { } return prepareForRetry(0); } - if(!getPieceStorage().isNull()) { + if(getPieceStorage()) { segments_.clear(); getSegmentMan()->getInFlightSegment(segments_, getCuid()); - if(!req_.isNull() && segments_.empty()) { + if(req_ && segments_.empty()) { // This command previously has assigned segments, but it is // canceled. So discard current request chain. Plus, if no // segment is available when http pipelining is used. @@ -149,17 +149,17 @@ bool AbstractCommand::execute() { // Request::isPipeliningEnabled() == true means aria2 // accessed the remote server and discovered that the server // supports pipelining. - if(!req_.isNull() && req_->isPipeliningEnabled()) { + if(req_ && req_->isPipeliningEnabled()) { e_->poolSocket(req_, createProxyRequest(), socket_); } return prepareForRetry(0); } // TODO it is not needed to check other PeerStats every time. // Find faster Request when no segment is available. - if(!req_.isNull() && fileEntry_->countPooledRequest() > 0 && + if(req_ && fileEntry_->countPooledRequest() > 0 && !getPieceStorage()->hasMissingUnusedPiece()) { SharedHandle fasterRequest = fileEntry_->findFasterRequest(req_); - if(!fasterRequest.isNull()) { + if(fasterRequest) { if(getLogger()->info()) { getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u", util::itos(getCuid()).c_str(), @@ -186,18 +186,18 @@ bool AbstractCommand::execute() { (!checkSocketIsReadable_ && !checkSocketIsWritable_ && !nameResolverCheck_)) { checkPoint_ = global::wallclock; - if(!getPieceStorage().isNull()) { - if(req_.isNull() || req_->getMaxPipelinedRequest() == 1 || + if(getPieceStorage()) { + if(!req_ || req_->getMaxPipelinedRequest() == 1 || // Why the following condition is necessary? That's because // For single file download, SegmentMan::getSegment(cuid) // is more efficient. getDownloadContext()->getFileEntries().size() == 1) { - size_t maxSegments = req_.isNull()?1:req_->getMaxPipelinedRequest(); + size_t maxSegments = req_?req_->getMaxPipelinedRequest():1; size_t minSplitSize = calculateMinSplitSize(); while(segments_.size() < maxSegments) { SharedHandle segment = getSegmentMan()->getSegment(getCuid(), minSplitSize); - if(segment.isNull()) { + if(!segment) { break; } else { segments_.push_back(segment); @@ -272,7 +272,7 @@ bool AbstractCommand::execute() { return false; } } catch(DlAbortEx& err) { - if(req_.isNull()) { + if(!req_) { if(getLogger()->debug()) { getLogger()->debug(EX_EXCEPTION_CAUGHT, err); } @@ -292,7 +292,7 @@ bool AbstractCommand::execute() { tryReserved(); return true; } catch(DlRetryEx& err) { - assert(!req_.isNull()); + assert(req_); if(getLogger()->info()) { getLogger()->info (MSG_RESTARTING_DOWNLOAD, @@ -327,7 +327,7 @@ bool AbstractCommand::execute() { } } catch(DownloadFailureException& err) { getLogger()->error(EX_EXCEPTION_CAUGHT, err); - if(!req_.isNull()) { + if(req_) { fileEntry_->addURIResult(req_->getUri(), err.getCode()); requestGroup_->setLastUriResult(req_->getUri(), err.getCode()); } @@ -364,16 +364,16 @@ void AbstractCommand::tryReserved() { } bool AbstractCommand::prepareForRetry(time_t wait) { - if(!getPieceStorage().isNull()) { + if(getPieceStorage()) { getSegmentMan()->cancelSegment(getCuid()); } - if(!req_.isNull()) { + if(req_) { fileEntry_->poolRequest(req_); if(getLogger()->debug()) { getLogger()->debug("CUID#%s - Pooling request URI=%s", util::itos(getCuid()).c_str(), req_->getUri().c_str()); } - if(!getSegmentMan().isNull()) { + if(getSegmentMan()) { getSegmentMan()->recognizeSegmentFor(fileEntry_); } } @@ -391,7 +391,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) { } void AbstractCommand::onAbort() { - if(!req_.isNull()) { + if(req_) { fileEntry_->removeIdenticalURI(req_->getUri()); fileEntry_->removeRequest(req_); } @@ -399,13 +399,13 @@ void AbstractCommand::onAbort() { getLogger()->debug("CUID#%s - Aborting download", util::itos(getCuid()).c_str()); } - if(!getPieceStorage().isNull()) { + if(getPieceStorage()) { getSegmentMan()->cancelSegment(getCuid()); // Don't do following process if BitTorrent is involved or files // in DownloadContext is more than 1. The latter condition is // limitation of current implementation. if(!getOption()->getAsBool(PREF_ALWAYS_RESUME) && - !fileEntry_.isNull() && + fileEntry_ && getSegmentMan()->calculateSessionDownloadLength() == 0 && !requestGroup_->p2pInvolved() && getDownloadContext()->getFileEntries().size() == 1) { @@ -660,7 +660,7 @@ SharedHandle AbstractCommand::createProxyRequest() const bool AbstractCommand::isAsyncNameResolverInitialized() const { - return !asyncNameResolver_.isNull(); + return asyncNameResolver_; } void AbstractCommand::initAsyncNameResolver(const std::string& hostname) @@ -709,7 +709,7 @@ const std::vector& AbstractCommand::getResolvedAddresses() void AbstractCommand::setNameResolverCheck (const SharedHandle& resolver) { - if(!resolver.isNull()) { + if(resolver) { nameResolverCheck_ = true; e_->addNameResolverCheck(resolver, this); } @@ -717,7 +717,7 @@ void AbstractCommand::setNameResolverCheck void AbstractCommand::disableNameResolverCheck (const SharedHandle& resolver) { - if(!resolver.isNull()) { + if(resolver) { nameResolverCheck_ = false; e_->deleteNameResolverCheck(resolver, this); } @@ -854,7 +854,7 @@ void AbstractCommand::createSocket() size_t AbstractCommand::calculateMinSplitSize() const { - if(!req_.isNull() && req_->isPipeliningEnabled()) { + if(req_ && req_->isPipeliningEnabled()) { return getDownloadContext()->getPieceLength(); } else { return getOption()->getAsInt(PREF_MIN_SPLIT_SIZE); diff --git a/src/AbstractProxyResponseCommand.cc b/src/AbstractProxyResponseCommand.cc index 8df05995..230dec8a 100644 --- a/src/AbstractProxyResponseCommand.cc +++ b/src/AbstractProxyResponseCommand.cc @@ -68,7 +68,7 @@ AbstractProxyResponseCommand::~AbstractProxyResponseCommand() {} bool AbstractProxyResponseCommand::executeInternal() { SharedHandle httpResponse = httpConnection_->receiveResponse(); - if(httpResponse.isNull()) { + if(!httpResponse) { // the server has not responded our request yet. getDownloadEngine()->addCommand(this); return false; diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 5a92c301..97285a49 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -135,7 +135,7 @@ bool ActivePeerConnectionCommand::execute() { void ActivePeerConnectionCommand::connectToPeer(const SharedHandle& peer) { - if(peer.isNull()) { + if(!peer) { return; } peer->usedBy(e_->newCUID()); diff --git a/src/AdaptiveFileAllocationIterator.cc b/src/AdaptiveFileAllocationIterator.cc index 19010217..cd1fe1e5 100644 --- a/src/AdaptiveFileAllocationIterator.cc +++ b/src/AdaptiveFileAllocationIterator.cc @@ -53,7 +53,7 @@ AdaptiveFileAllocationIterator::~AdaptiveFileAllocationIterator() {} void AdaptiveFileAllocationIterator::allocateChunk() { - if(allocator_.isNull()) { + if(!allocator_) { #ifdef HAVE_FALLOCATE try { if(logger_->debug()) { @@ -92,7 +92,7 @@ void AdaptiveFileAllocationIterator::allocateChunk() bool AdaptiveFileAllocationIterator::finished() { - if(allocator_.isNull()) { + if(!allocator_) { return (uint64_t)offset_ == totalLength_; } else { return allocator_->finished(); diff --git a/src/AdaptiveFileAllocationIterator.h b/src/AdaptiveFileAllocationIterator.h index 637a7cae..cac27bc3 100644 --- a/src/AdaptiveFileAllocationIterator.h +++ b/src/AdaptiveFileAllocationIterator.h @@ -66,7 +66,7 @@ public: virtual off_t getCurrentLength() { - if(allocator_.isNull()) { + if(!allocator_) { return offset_; } else { return allocator_->getCurrentLength(); diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index 227a0f56..16909e23 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -266,7 +266,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); - if(ss.isNull()) + if(!ss) continue; if((int)ss->getSingleConnectionAvgSpeed() > max) { @@ -288,7 +288,7 @@ std::deque AdaptiveURISelector::getUrisBySpeed for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); - if(ss.isNull()) + if(!ss) continue; if(ss->getSingleConnectionAvgSpeed() > min || ss->getMultiConnectionAvgSpeed() > min) { @@ -313,7 +313,7 @@ std::string AdaptiveURISelector::getFirstNotTestedUri for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); - if(ss.isNull()) + if(!ss) return *i; } return A2STR::NIL; @@ -327,7 +327,7 @@ std::string AdaptiveURISelector::getFirstToTestUri for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); - if(ss.isNull()) + if(!ss) continue; counter = ss->getCounter(); if(counter > 8) @@ -360,7 +360,7 @@ unsigned int AdaptiveURISelector::getNbTestedServers for(std::deque::const_iterator i = uris.begin(), eoi = uris.end(); i != eoi; ++i) { SharedHandle ss = getServerStats(*i); - if(ss.isNull()) + if(!ss) ++counter; } return uris.size() - counter; diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc index 25032e10..4d52fbb4 100644 --- a/src/AuthConfigFactory.cc +++ b/src/AuthConfigFactory.cc @@ -97,7 +97,7 @@ AuthConfigFactory::createAuthConfig SharedHandle ac = authResolver.resolveAuthConfig(request->getHost()); - if(!ac.isNull() && ac->getUser() == request->getUsername()) { + if(ac && ac->getUser() == request->getUsername()) { return ac; } } @@ -187,7 +187,7 @@ bool AuthConfigFactory::activateBasicCred if(i == basicCreds_.end()) { SharedHandle authConfig = createHttpAuthResolver(op)->resolveAuthConfig(host); - if(authConfig.isNull()) { + if(!authConfig) { return false; } else { BasicCred bc(authConfig->getUser(), authConfig->getPassword(), diff --git a/src/BNode.cc b/src/BNode.cc index adfb8028..71c849ee 100644 --- a/src/BNode.cc +++ b/src/BNode.cc @@ -78,7 +78,7 @@ void BNode::setBucket(const SharedHandle& bucket) bool BNode::isInRange(const unsigned char* key) const { - if(bucket_.isNull()) { + if(!bucket_) { return left_->isInRange(key) || right_->isInRange(key); } else { return bucket_->isInRange(key); @@ -91,7 +91,7 @@ BNode* BNode::findBNodeFor(BNode* b, const unsigned char* key) return 0; } while(1) { - if(!b->getBucket().isNull()) { + if(b->getBucket()) { return b; } // we assume key fits in either left or right bucket range. @@ -164,7 +164,7 @@ void BNode::findClosestKNodes(std::vector >& nodes, visited.push_back(bnode); { SharedHandle bucket = bnode->getBucket(); - if(!bucket.isNull()) { + if(bucket) { std::vector > goodNodes; bucket->getGoodNodes(goodNodes); size_t r = DHTBucket::K-nodes.size(); @@ -187,7 +187,7 @@ void BNode::enumerateBucket(std::vector >& buckets, if(!b) { break; } - if(!b->getBucket().isNull()) { + if(b->getBucket()) { buckets.push_back(b->getBucket()); b = b->getUp(); } else if(std::find(visited.begin(), visited.end(), b->getLeft()) == visited.end()) { diff --git a/src/BtDependency.cc b/src/BtDependency.cc index 100517a2..376790a2 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -51,7 +51,7 @@ namespace aria2 { -BtDependency::BtDependency(const WeakHandle& dependant, +BtDependency::BtDependency(RequestGroup* dependant, const SharedHandle& dependee): dependant_(dependant), dependee_(dependee), diff --git a/src/BtDependency.h b/src/BtDependency.h index 47eab55b..32fe45ad 100644 --- a/src/BtDependency.h +++ b/src/BtDependency.h @@ -46,11 +46,11 @@ class Logger; class BtDependency : public Dependency { private: - WeakHandle dependant_; + RequestGroup* dependant_; SharedHandle dependee_; Logger* logger_; public: - BtDependency(const WeakHandle& dependant, + BtDependency(RequestGroup* dependant, const SharedHandle& dependee); virtual ~BtDependency(); diff --git a/src/BtExtendedMessage.cc b/src/BtExtendedMessage.cc index 480888d8..8b1bcec2 100644 --- a/src/BtExtendedMessage.cc +++ b/src/BtExtendedMessage.cc @@ -99,7 +99,7 @@ BtExtendedMessage::create(const SharedHandle& factory, { bittorrent::assertPayloadLengthGreater(1, dataLength, NAME); bittorrent::assertID(ID, data, NAME); - assert(!factory.isNull()); + assert(factory); ExtensionMessageHandle extmsg = factory->createMessage(data+1, dataLength-1); BtExtendedMessageHandle message(new BtExtendedMessage(extmsg)); @@ -108,7 +108,7 @@ BtExtendedMessage::create(const SharedHandle& factory, void BtExtendedMessage::doReceivedAction() { - if(!extensionMessage_.isNull()) { + if(extensionMessage_) { extensionMessage_->doReceivedAction(); } } diff --git a/src/BtMessageDispatcher.h b/src/BtMessageDispatcher.h index 8f867680..cc3f0898 100644 --- a/src/BtMessageDispatcher.h +++ b/src/BtMessageDispatcher.h @@ -88,7 +88,6 @@ public: }; typedef SharedHandle BtMessageDispatcherHandle; -typedef WeakHandle BtMessageDispatcherWeakHandle; } // namespace aria2 diff --git a/src/BtMessageFactory.h b/src/BtMessageFactory.h index ab3dbc72..b4b6e2a5 100644 --- a/src/BtMessageFactory.h +++ b/src/BtMessageFactory.h @@ -98,7 +98,6 @@ public: }; typedef SharedHandle BtMessageFactoryHandle; -typedef WeakHandle BtMessageFactoryWeakHandle; } // namespace aria2 diff --git a/src/BtMessageReceiver.h b/src/BtMessageReceiver.h index be281260..e3a59593 100644 --- a/src/BtMessageReceiver.h +++ b/src/BtMessageReceiver.h @@ -55,7 +55,6 @@ public: }; typedef SharedHandle BtMessageReceiverHandle; -typedef WeakHandle BtMessageReceiverWeakHandle; } // namespace aria2 diff --git a/src/BtPortMessage.cc b/src/BtPortMessage.cc index 881a4cb8..b66cb5c2 100644 --- a/src/BtPortMessage.cc +++ b/src/BtPortMessage.cc @@ -52,7 +52,12 @@ namespace aria2 { const std::string BtPortMessage::NAME("port"); BtPortMessage::BtPortMessage(uint16_t port): - SimpleBtMessage(ID, NAME), port_(port) {} + SimpleBtMessage(ID, NAME), port_(port), + localNode_(0), + routingTable_(0), + taskQueue_(0), + taskFactory_(0) + {} SharedHandle BtPortMessage::create (const unsigned char* data, size_t dataLength) @@ -66,7 +71,7 @@ SharedHandle BtPortMessage::create void BtPortMessage::doReceivedAction() { - if(!taskFactory_.isNull() && !taskQueue_.isNull()) { + if(taskFactory_ && taskQueue_) { if(port_ == 0) { if(getLogger()->debug()) { getLogger()->debug("Ignored port 0."); @@ -116,22 +121,22 @@ std::string BtPortMessage::toString() const { return strconcat(NAME, " port=", util::uitos(port_)); } -void BtPortMessage::setLocalNode(const WeakHandle& localNode) +void BtPortMessage::setLocalNode(DHTNode* localNode) { localNode_ = localNode; } -void BtPortMessage::setRoutingTable(const WeakHandle& routingTable) +void BtPortMessage::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void BtPortMessage::setTaskQueue(const WeakHandle& taskQueue) +void BtPortMessage::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void BtPortMessage::setTaskFactory(const WeakHandle& taskFactory) +void BtPortMessage::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } diff --git a/src/BtPortMessage.h b/src/BtPortMessage.h index c2a0991c..4dd2fe82 100644 --- a/src/BtPortMessage.h +++ b/src/BtPortMessage.h @@ -49,13 +49,13 @@ private: uint16_t port_; static const size_t MESSAGE_LENGTH = 7; - WeakHandle localNode_; + DHTNode* localNode_; - WeakHandle routingTable_; + DHTRoutingTable* routingTable_; - WeakHandle taskQueue_; + DHTTaskQueue* taskQueue_; - WeakHandle taskFactory_; + DHTTaskFactory* taskFactory_; public: BtPortMessage(uint16_t port); @@ -76,13 +76,13 @@ public: virtual std::string toString() const; - void setLocalNode(const WeakHandle& localNode); + void setLocalNode(DHTNode* localNode); - void setRoutingTable(const WeakHandle& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - void setTaskQueue(const WeakHandle& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const WeakHandle& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); }; } // namespace aria2 diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc index 21219257..6baace05 100644 --- a/src/BtPostDownloadHandler.cc +++ b/src/BtPostDownloadHandler.cc @@ -84,7 +84,7 @@ void BtPostDownloadHandler::getNextRequestGroups requestGroup->followedBy(newRgs.begin(), newRgs.end()); SharedHandle mi = createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); - if(!mi.isNull()) { + if(mi) { setMetadataInfo(newRgs.begin(), newRgs.end(), mi); } groups.insert(groups.end(), newRgs.begin(), newRgs.end()); diff --git a/src/BtRegistry.h b/src/BtRegistry.h index 44fc14a9..a39700f5 100644 --- a/src/BtRegistry.h +++ b/src/BtRegistry.h @@ -76,12 +76,12 @@ struct BtObject { bool isNull() const { - return downloadContext_.isNull() && - pieceStorage_.isNull() && - peerStorage_.isNull() && - btAnnounce_.isNull() && - btRuntime_.isNull() && - btProgressInfoFile_.isNull(); + return !downloadContext_ && + !pieceStorage_ && + !peerStorage_ && + !btAnnounce_ && + !btRuntime_ && + !btProgressInfoFile_; } }; diff --git a/src/BtRequestFactory.h b/src/BtRequestFactory.h index 5b9ff3a3..9e812c89 100644 --- a/src/BtRequestFactory.h +++ b/src/BtRequestFactory.h @@ -88,7 +88,6 @@ public: }; typedef SharedHandle BtRequestFactoryHandle; -typedef WeakHandle BtRequestFactoryWeakHandle; } // namespace aria2 diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index 764c0984..a5f28418 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -61,7 +61,7 @@ void CheckIntegrityEntry::validateChunk() uint64_t CheckIntegrityEntry::getTotalLength() { - if(validator_.isNull()) { + if(!validator_) { return 0; } else { return validator_->getTotalLength(); @@ -70,7 +70,7 @@ uint64_t CheckIntegrityEntry::getTotalLength() off_t CheckIntegrityEntry::getCurrentLength() { - if(validator_.isNull()) { + if(!validator_) { return 0; } else { return validator_->getCurrentOffset(); diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index c1477c52..da14b244 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -121,7 +121,7 @@ void printProgress #ifdef ENABLE_BITTORRENT SharedHandle ps = e->getBtRegistry()->get(rg->getGID()).peerStorage_; - if(!ps.isNull()) { + if(ps) { std::vector > peers; ps->getActivePeers(peers); o << " " << "SEED:" @@ -280,7 +280,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e) { SharedHandle entry = e->getFileAllocationMan()->getPickedEntry(); - if(!entry.isNull()) { + if(entry) { o << " " << "[FileAlloc:" << "#" << entry->getRequestGroup()->getGID() << " " @@ -308,7 +308,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e) { SharedHandle entry = e->getCheckIntegrityMan()->getPickedEntry(); - if(!entry.isNull()) { + if(entry) { o << " " << "[Checksum:" << "#" << entry->getRequestGroup()->getGID() << " " diff --git a/src/CreateRequestCommand.cc b/src/CreateRequestCommand.cc index 2a8dfad0..ef1f70c2 100644 --- a/src/CreateRequestCommand.cc +++ b/src/CreateRequestCommand.cc @@ -87,8 +87,8 @@ bool CreateRequestCommand::executeInternal() getOption()->getAsBool(PREF_USE_HEAD)) || getOption()->getAsBool(PREF_DRY_RUN)? Request::METHOD_HEAD:Request::METHOD_GET)); - if(getRequest().isNull()) { - if(!getSegmentMan().isNull()) { + if(!getRequest()) { + if(getSegmentMan()) { getSegmentMan()->ignoreSegmentFor(getFileEntry()); } throw DL_ABORT_EX("No URI available."); diff --git a/src/DHTAbstractMessage.cc b/src/DHTAbstractMessage.cc index 96e849b9..518c7e68 100644 --- a/src/DHTAbstractMessage.cc +++ b/src/DHTAbstractMessage.cc @@ -49,7 +49,12 @@ namespace aria2 { DHTAbstractMessage::DHTAbstractMessage(const SharedHandle& localNode, const SharedHandle& remoteNode, const std::string& transactionID): - DHTMessage(localNode, remoteNode, transactionID) {} + DHTMessage(localNode, remoteNode, transactionID), + connection_(0), + dispatcher_(0), + factory_(0), + routingTable_(0) + {} DHTAbstractMessage::~DHTAbstractMessage() {} @@ -75,26 +80,22 @@ bool DHTAbstractMessage::send() return r == static_cast(message.size()); } -void DHTAbstractMessage::setConnection -(const WeakHandle& connection) +void DHTAbstractMessage::setConnection(DHTConnection* connection) { connection_ = connection; } -void DHTAbstractMessage::setMessageDispatcher -(const WeakHandle& dispatcher) +void DHTAbstractMessage::setMessageDispatcher(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DHTAbstractMessage::setMessageFactory -(const WeakHandle& factory) +void DHTAbstractMessage::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } -void DHTAbstractMessage::setRoutingTable -(const WeakHandle& routingTable) +void DHTAbstractMessage::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } diff --git a/src/DHTAbstractMessage.h b/src/DHTAbstractMessage.h index 46c2d9d9..82b65e72 100644 --- a/src/DHTAbstractMessage.h +++ b/src/DHTAbstractMessage.h @@ -48,13 +48,13 @@ class DHTRoutingTable; class DHTAbstractMessage:public DHTMessage { private: - WeakHandle connection_; + DHTConnection* connection_; - WeakHandle dispatcher_; + DHTMessageDispatcher* dispatcher_; - WeakHandle factory_; + DHTMessageFactory* factory_; - WeakHandle routingTable_; + DHTRoutingTable* routingTable_; public: DHTAbstractMessage(const SharedHandle& localNode, const SharedHandle& remoteNode, @@ -70,33 +70,33 @@ public: std::string getBencodedMessage(); - const WeakHandle& getConnection() const + DHTConnection* getConnection() const { return connection_; } - void setConnection(const WeakHandle& connection); + void setConnection(DHTConnection* connection); - const WeakHandle& getMessageDispatcher() const + DHTMessageDispatcher* getMessageDispatcher() const { return dispatcher_; } - void setMessageDispatcher(const WeakHandle& dispatcher); + void setMessageDispatcher(DHTMessageDispatcher* dispatcher); - const WeakHandle& getMessageFactory() const + DHTMessageFactory* getMessageFactory() const { return factory_; } - void setMessageFactory(const WeakHandle& factory); + void setMessageFactory(DHTMessageFactory* factory); - const WeakHandle& getRoutingTable() const + DHTRoutingTable* getRoutingTable() const { return routingTable_; } - void setRoutingTable(const WeakHandle& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); }; } // namespace aria2 diff --git a/src/DHTAbstractTask.cc b/src/DHTAbstractTask.cc index 706ab5de..076c0596 100644 --- a/src/DHTAbstractTask.cc +++ b/src/DHTAbstractTask.cc @@ -48,7 +48,11 @@ namespace aria2 { DHTAbstractTask::DHTAbstractTask(): finished_(false), - logger_(LogFactory::getInstance()) + logger_(LogFactory::getInstance()), + routingTable_(0), + dispatcher_(0), + factory_(0), + taskQueue_(0) {} bool DHTAbstractTask::finished() @@ -56,22 +60,22 @@ bool DHTAbstractTask::finished() return finished_; } -void DHTAbstractTask::setRoutingTable(const WeakHandle routingTable) +void DHTAbstractTask::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void DHTAbstractTask::setMessageDispatcher(const WeakHandle dispatcher) +void DHTAbstractTask::setMessageDispatcher(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DHTAbstractTask::setMessageFactory(const WeakHandle factory) +void DHTAbstractTask::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } -void DHTAbstractTask::setTaskQueue(const WeakHandle taskQueue) +void DHTAbstractTask::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } diff --git a/src/DHTAbstractTask.h b/src/DHTAbstractTask.h index 880fa985..f5ce4c5a 100644 --- a/src/DHTAbstractTask.h +++ b/src/DHTAbstractTask.h @@ -58,13 +58,13 @@ private: SharedHandle localNode_; - WeakHandle routingTable_; + DHTRoutingTable* routingTable_; - WeakHandle dispatcher_; + DHTMessageDispatcher* dispatcher_; - WeakHandle factory_; + DHTMessageFactory* factory_; - WeakHandle taskQueue_; + DHTTaskQueue* taskQueue_; protected: void setFinished(bool f) { @@ -80,33 +80,33 @@ public: virtual bool finished(); - const WeakHandle& getRoutingTable() const + DHTRoutingTable* getRoutingTable() const { return routingTable_; } - void setRoutingTable(const WeakHandle routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - const WeakHandle& getMessageDispatcher() const + DHTMessageDispatcher* getMessageDispatcher() const { return dispatcher_; } - void setMessageDispatcher(const WeakHandle dispatcher); + void setMessageDispatcher(DHTMessageDispatcher* dispatcher); - const WeakHandle& getMessageFactory() const + DHTMessageFactory* getMessageFactory() const { return factory_; } - void setMessageFactory(const WeakHandle factory); + void setMessageFactory(DHTMessageFactory* factory); - const WeakHandle& getTaskQueue() const + DHTTaskQueue* getTaskQueue() const { return taskQueue_; } - void setTaskQueue(const WeakHandle taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); const SharedHandle& getLocalNode() const { diff --git a/src/DHTAnnouncePeerMessage.cc b/src/DHTAnnouncePeerMessage.cc index 592eb4bf..055dac3c 100644 --- a/src/DHTAnnouncePeerMessage.cc +++ b/src/DHTAnnouncePeerMessage.cc @@ -68,7 +68,9 @@ DHTAnnouncePeerMessage::DHTAnnouncePeerMessage const std::string& transactionID): DHTQueryMessage(localNode, remoteNode, transactionID), token_(token), - tcpPort_(tcpPort) + tcpPort_(tcpPort), + peerAnnounceStorage_(0), + tokenTracker_(0) { memcpy(infoHash_, infoHash, DHT_ID_LENGTH); } @@ -115,13 +117,12 @@ void DHTAnnouncePeerMessage::validate() const } void DHTAnnouncePeerMessage::setPeerAnnounceStorage -(const WeakHandle& storage) +(DHTPeerAnnounceStorage* storage) { peerAnnounceStorage_ = storage; } -void DHTAnnouncePeerMessage::setTokenTracker -(const WeakHandle& tokenTracker) +void DHTAnnouncePeerMessage::setTokenTracker(DHTTokenTracker* tokenTracker) { tokenTracker_ = tokenTracker; } diff --git a/src/DHTAnnouncePeerMessage.h b/src/DHTAnnouncePeerMessage.h index 082a31a2..ab2c7716 100644 --- a/src/DHTAnnouncePeerMessage.h +++ b/src/DHTAnnouncePeerMessage.h @@ -52,9 +52,9 @@ private: uint16_t tcpPort_; - WeakHandle peerAnnounceStorage_; + DHTPeerAnnounceStorage* peerAnnounceStorage_; - WeakHandle tokenTracker_; + DHTTokenTracker* tokenTracker_; protected: virtual std::string toStringOptional() const; public: @@ -90,9 +90,9 @@ public: return tcpPort_; } - void setPeerAnnounceStorage(const WeakHandle& storage); + void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage); - void setTokenTracker(const WeakHandle& tokenTracker); + void setTokenTracker(DHTTokenTracker* tokenTracker); static const std::string ANNOUNCE_PEER; diff --git a/src/DHTEntryPointNameResolveCommand.cc b/src/DHTEntryPointNameResolveCommand.cc index d59cbdec..905a2710 100644 --- a/src/DHTEntryPointNameResolveCommand.cc +++ b/src/DHTEntryPointNameResolveCommand.cc @@ -80,7 +80,7 @@ bool DHTEntryPointNameResolveCommand::execute() return true; } #ifdef ENABLE_ASYNC_DNS - if(resolver_.isNull()) { + if(!resolver_) { int family; if(e_->getOption()->getAsBool(PREF_ENABLE_ASYNC_DNS6)) { family = AF_UNSPEC; diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc index c2f50048..b0365959 100644 --- a/src/DHTGetPeersCommand.cc +++ b/src/DHTGetPeersCommand.cc @@ -76,7 +76,7 @@ bool DHTGetPeersCommand::execute() if(btRuntime_->isHalt()) { return true; } - if(task_.isNull() && + if(!task_ && ((numRetry_ > 0 && lastGetPeerTime_.difference(global::wallclock) >= (time_t)numRetry_*5) || lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_INTERVAL || @@ -91,7 +91,7 @@ bool DHTGetPeersCommand::execute() task_ = taskFactory_->createPeerLookupTask (requestGroup_->getDownloadContext(), btRuntime_, peerStorage_); taskQueue_->addPeriodicTask2(task_); - } else if(!task_.isNull() && task_->finished()) { + } else if(task_ && task_->finished()) { lastGetPeerTime_ = global::wallclock; if(numRetry_ < MAX_RETRIES && btRuntime_->lessThanMinPeers()) { ++numRetry_; diff --git a/src/DHTGetPeersMessage.cc b/src/DHTGetPeersMessage.cc index 2a553792..6fd94a2b 100644 --- a/src/DHTGetPeersMessage.cc +++ b/src/DHTGetPeersMessage.cc @@ -56,7 +56,9 @@ DHTGetPeersMessage::DHTGetPeersMessage(const SharedHandle& localNode, const SharedHandle& remoteNode, const unsigned char* infoHash, const std::string& transactionID): - DHTQueryMessage(localNode, remoteNode, transactionID) + DHTQueryMessage(localNode, remoteNode, transactionID), + peerAnnounceStorage_(0), + tokenTracker_(0) { memcpy(infoHash_, infoHash, DHT_ID_LENGTH); } @@ -91,14 +93,12 @@ const std::string& DHTGetPeersMessage::getMessageType() const return GET_PEERS; } -void DHTGetPeersMessage::setPeerAnnounceStorage -(const WeakHandle& storage) +void DHTGetPeersMessage::setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage) { peerAnnounceStorage_ = storage; } -void DHTGetPeersMessage::setTokenTracker -(const WeakHandle& tokenTracker) +void DHTGetPeersMessage::setTokenTracker(DHTTokenTracker* tokenTracker) { tokenTracker_ = tokenTracker; } diff --git a/src/DHTGetPeersMessage.h b/src/DHTGetPeersMessage.h index 0969d511..58443159 100644 --- a/src/DHTGetPeersMessage.h +++ b/src/DHTGetPeersMessage.h @@ -48,9 +48,9 @@ class DHTGetPeersMessage:public DHTQueryMessage { private: unsigned char infoHash_[DHT_ID_LENGTH]; - WeakHandle peerAnnounceStorage_; + DHTPeerAnnounceStorage* peerAnnounceStorage_; - WeakHandle tokenTracker_; + DHTTokenTracker* tokenTracker_; protected: virtual std::string toStringOptional() const; public: @@ -72,10 +72,9 @@ public: return infoHash_; } - void setPeerAnnounceStorage - (const WeakHandle& storage); + void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage); - void setTokenTracker(const WeakHandle& tokenTracker); + void setTokenTracker(DHTTokenTracker* tokenTracker); static const std::string GET_PEERS; diff --git a/src/DHTInteractionCommand.cc b/src/DHTInteractionCommand.cc index 347b8ec9..e49d9fb3 100644 --- a/src/DHTInteractionCommand.cc +++ b/src/DHTInteractionCommand.cc @@ -82,7 +82,7 @@ bool DHTInteractionCommand::execute() for(size_t i = 0; i < 20; ++i) { SharedHandle m = receiver_->receiveMessage(); - if(m.isNull()) { + if(!m) { break; } } diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc index 9910abe8..b3294800 100644 --- a/src/DHTMessageFactoryImpl.cc +++ b/src/DHTMessageFactoryImpl.cc @@ -66,6 +66,11 @@ namespace aria2 { DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family): family_(family), + connection_(0), + dispatcher_(0), + routingTable_(0), + peerAnnounceStorage_(0), + tokenTracker_(0), logger_(LogFactory::getInstance()) {} DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {} @@ -75,7 +80,7 @@ DHTMessageFactoryImpl::getRemoteNode (const unsigned char* id, const std::string& ipaddr, uint16_t port) const { SharedHandle node = routingTable_->getNode(id, ipaddr, port); - if(node.isNull()) { + if(!node) { node.reset(new DHTNode(id)); node->setIPAddress(ipaddr); node->setPort(port); @@ -309,8 +314,7 @@ void DHTMessageFactoryImpl::setCommonProperty m->setConnection(connection_); m->setMessageDispatcher(dispatcher_); m->setRoutingTable(routingTable_); - WeakHandle factory(this); - m->setMessageFactory(factory); + m->setMessageFactory(this); m->setVersion(getDefaultVersion()); } @@ -506,32 +510,29 @@ DHTMessageFactoryImpl::createUnknownMessage return m; } -void DHTMessageFactoryImpl::setRoutingTable -(const WeakHandle& routingTable) +void DHTMessageFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void DHTMessageFactoryImpl::setConnection -(const WeakHandle& connection) +void DHTMessageFactoryImpl::setConnection(DHTConnection* connection) { connection_ = connection; } void DHTMessageFactoryImpl::setMessageDispatcher -(const WeakHandle& dispatcher) +(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } void DHTMessageFactoryImpl::setPeerAnnounceStorage -(const WeakHandle& storage) +(DHTPeerAnnounceStorage* storage) { peerAnnounceStorage_ = storage; } -void DHTMessageFactoryImpl::setTokenTracker -(const WeakHandle& tokenTracker) +void DHTMessageFactoryImpl::setTokenTracker(DHTTokenTracker* tokenTracker) { tokenTracker_ = tokenTracker; } diff --git a/src/DHTMessageFactoryImpl.h b/src/DHTMessageFactoryImpl.h index 52025338..7bc41491 100644 --- a/src/DHTMessageFactoryImpl.h +++ b/src/DHTMessageFactoryImpl.h @@ -55,15 +55,15 @@ private: SharedHandle localNode_; - WeakHandle connection_; + DHTConnection* connection_; - WeakHandle dispatcher_; + DHTMessageDispatcher* dispatcher_; - WeakHandle routingTable_; + DHTRoutingTable* routingTable_; - WeakHandle peerAnnounceStorage_; + DHTPeerAnnounceStorage* peerAnnounceStorage_; - WeakHandle tokenTracker_; + DHTTokenTracker* tokenTracker_; Logger* logger_; @@ -155,16 +155,15 @@ public: createUnknownMessage(const unsigned char* data, size_t length, const std::string& ipaddr, uint16_t port); - void setRoutingTable(const WeakHandle& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - void setConnection(const WeakHandle& connection); + void setConnection(DHTConnection* connection); - void setMessageDispatcher(const WeakHandle& dispatcher); + void setMessageDispatcher(DHTMessageDispatcher* dispatcher); - void setPeerAnnounceStorage - (const WeakHandle& storage); + void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage); - void setTokenTracker(const WeakHandle& tokenTracker); + void setTokenTracker(DHTTokenTracker* tokenTracker); void setLocalNode(const SharedHandle& localNode); }; diff --git a/src/DHTMessageReceiver.cc b/src/DHTMessageReceiver.cc index ddcb9891..c6d4158d 100644 --- a/src/DHTMessageReceiver.cc +++ b/src/DHTMessageReceiver.cc @@ -97,12 +97,12 @@ SharedHandle DHTMessageReceiver::receiveMessage() std::pair, SharedHandle > p = tracker_->messageArrived(dict, remoteAddr, remotePort); - if(p.first.isNull()) { + if(!p.first) { // timeout or malicious? message return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); } onMessageReceived(p.first); - if(!p.second.isNull()) { + if(p.second) { p.second->onReceived(p.first); } return p.first; diff --git a/src/DHTMessageTracker.cc b/src/DHTMessageTracker.cc index ae0b2a91..88ec2db4 100644 --- a/src/DHTMessageTracker.cc +++ b/src/DHTMessageTracker.cc @@ -129,7 +129,7 @@ void DHTMessageTracker::handleTimeoutEntry routingTable_->dropNode(node); } SharedHandle callback = entry->getCallback(); - if(!callback.isNull()) { + if(callback) { callback->onTimeout(node); } } catch(RecoverableException& e) { diff --git a/src/DHTNodeLookupEntry.cc b/src/DHTNodeLookupEntry.cc index 58cb5825..0026e4bf 100644 --- a/src/DHTNodeLookupEntry.cc +++ b/src/DHTNodeLookupEntry.cc @@ -41,7 +41,7 @@ DHTNodeLookupEntry::DHTNodeLookupEntry(const SharedHandle& node): node(node), used(false) {} DHTNodeLookupEntry::DHTNodeLookupEntry(): - node(0), used(false) {} + used(false) {} bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const { diff --git a/src/DHTReplaceNodeTask.cc b/src/DHTReplaceNodeTask.cc index d9ce8979..66fa70c4 100644 --- a/src/DHTReplaceNodeTask.cc +++ b/src/DHTReplaceNodeTask.cc @@ -62,7 +62,7 @@ void DHTReplaceNodeTask::startup() void DHTReplaceNodeTask::sendMessage() { SharedHandle questionableNode = bucket_->getLRUQuestionableNode(); - if(questionableNode.isNull()) { + if(!questionableNode) { setFinished(true); } else { SharedHandle m = diff --git a/src/DHTSetup.cc b/src/DHTSetup.cc index ec8b7ac7..255f4ca6 100644 --- a/src/DHTSetup.cc +++ b/src/DHTSetup.cc @@ -115,7 +115,7 @@ void DHTSetup::setup logger_->error("Exception caught while loading DHT routing table from %s", e, dhtFile.c_str()); } - if(localNode.isNull()) { + if(!localNode) { localNode.reset(new DHTNode()); } @@ -167,10 +167,10 @@ void DHTSetup::setup receiver->setRoutingTable(routingTable); taskFactory->setLocalNode(localNode); - taskFactory->setRoutingTable(routingTable); - taskFactory->setMessageDispatcher(dispatcher); - taskFactory->setMessageFactory(factory); - taskFactory->setTaskQueue(taskQueue); + taskFactory->setRoutingTable(routingTable.get()); + taskFactory->setMessageDispatcher(dispatcher.get()); + taskFactory->setMessageFactory(factory.get()); + taskFactory->setTaskQueue(taskQueue.get()); taskFactory->setTimeout(messageTimeout); routingTable->setTaskQueue(taskQueue); @@ -179,11 +179,11 @@ void DHTSetup::setup peerAnnounceStorage->setTaskQueue(taskQueue); peerAnnounceStorage->setTaskFactory(taskFactory); - factory->setRoutingTable(routingTable); - factory->setConnection(connection); - factory->setMessageDispatcher(dispatcher); - factory->setPeerAnnounceStorage(peerAnnounceStorage); - factory->setTokenTracker(tokenTracker); + factory->setRoutingTable(routingTable.get()); + factory->setConnection(connection.get()); + factory->setMessageDispatcher(dispatcher.get()); + factory->setPeerAnnounceStorage(peerAnnounceStorage.get()); + factory->setTokenTracker(tokenTracker.get()); factory->setLocalNode(localNode); // assign them into DHTRegistry diff --git a/src/DHTTaskFactoryImpl.cc b/src/DHTTaskFactoryImpl.cc index b95a462b..3119efb9 100644 --- a/src/DHTTaskFactoryImpl.cc +++ b/src/DHTTaskFactoryImpl.cc @@ -54,6 +54,10 @@ namespace aria2 { DHTTaskFactoryImpl::DHTTaskFactoryImpl(): + routingTable_(0), + dispatcher_(0), + factory_(0), + taskQueue_(0), timeout_(DHT_MESSAGE_TIMEOUT), logger_(LogFactory::getInstance()) {} @@ -125,22 +129,22 @@ void DHTTaskFactoryImpl::setCommonProperty(const SharedHandle& task->setLocalNode(localNode_); } -void DHTTaskFactoryImpl::setRoutingTable(const WeakHandle routingTable) +void DHTTaskFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void DHTTaskFactoryImpl::setMessageDispatcher(const WeakHandle dispatcher) +void DHTTaskFactoryImpl::setMessageDispatcher(DHTMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DHTTaskFactoryImpl::setMessageFactory(const WeakHandle factory) +void DHTTaskFactoryImpl::setMessageFactory(DHTMessageFactory* factory) { factory_ = factory; } -void DHTTaskFactoryImpl::setTaskQueue(const WeakHandle taskQueue) +void DHTTaskFactoryImpl::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } diff --git a/src/DHTTaskFactoryImpl.h b/src/DHTTaskFactoryImpl.h index 679dca27..032fb0fa 100644 --- a/src/DHTTaskFactoryImpl.h +++ b/src/DHTTaskFactoryImpl.h @@ -52,13 +52,13 @@ class DHTTaskFactoryImpl:public DHTTaskFactory { private: SharedHandle localNode_; - WeakHandle routingTable_; + DHTRoutingTable* routingTable_; - WeakHandle dispatcher_; + DHTMessageDispatcher* dispatcher_; - WeakHandle factory_; + DHTMessageFactory* factory_; - WeakHandle taskQueue_; + DHTTaskQueue* taskQueue_; time_t timeout_; @@ -91,13 +91,13 @@ public: createReplaceNodeTask(const SharedHandle& bucket, const SharedHandle& newNode); - void setRoutingTable(const WeakHandle routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - void setMessageDispatcher(const WeakHandle dispatcher); + void setMessageDispatcher(DHTMessageDispatcher* dispatcher); - void setMessageFactory(const WeakHandle factory); + void setMessageFactory(DHTMessageFactory* factory); - void setTaskQueue(const WeakHandle taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); void setLocalNode(const SharedHandle& localNode); diff --git a/src/DefaultAuthResolver.cc b/src/DefaultAuthResolver.cc index 72f8fc79..bc6650a0 100644 --- a/src/DefaultAuthResolver.cc +++ b/src/DefaultAuthResolver.cc @@ -40,7 +40,7 @@ namespace aria2 { AuthConfigHandle DefaultAuthResolver::resolveAuthConfig (const std::string& hostname) { - if(getUserDefinedAuthConfig().isNull()) { + if(!getUserDefinedAuthConfig()) { return getDefaultAuthConfig(); } else { return getUserDefinedAuthConfig(); diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index faa24aa0..5f65d5e7 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -276,7 +276,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, } } const SharedHandle& peerData = dict->get(BtAnnounce::PEERS); - if(peerData.isNull()) { + if(!peerData) { logger_->info(MSG_NO_PEER_LIST_RECEIVED); } else { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { @@ -286,7 +286,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, } } const SharedHandle& peer6Data = dict->get(BtAnnounce::PEERS6); - if(peer6Data.isNull()) { + if(!peer6Data) { logger_->info("No peers6 received."); } else { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index d7234b7e..1fe827b8 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -83,6 +83,7 @@ DefaultBtInteractive::DefaultBtInteractive downloadContext_(downloadContext), peer_(peer), metadataGetMode_(false), + localNode_(0), logger_(LogFactory::getInstance()), allowedFastSetSize_(10), haveTimer_(global::wallclock), @@ -95,7 +96,8 @@ DefaultBtInteractive::DefaultBtInteractive utPexEnabled_(false), dhtEnabled_(false), numReceivedMessage_(0), - maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST) + maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST), + requestGroupMan_(0) {} DefaultBtInteractive::~DefaultBtInteractive() {} @@ -111,7 +113,7 @@ void DefaultBtInteractive::initiateHandshake() { BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) { SharedHandle message = btMessageReceiver_->receiveHandshake(quickReply); - if(message.isNull()) { + if(!message) { return SharedHandle(); } if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(), @@ -290,7 +292,7 @@ size_t DefaultBtInteractive::receiveMessages() { break; } BtMessageHandle message = btMessageReceiver_->receiveMessage(); - if(message.isNull()) { + if(!message) { break; } ++msgcount; @@ -569,7 +571,7 @@ void DefaultBtInteractive::doInteractionProcessing() { sendPendingMessage(); } -void DefaultBtInteractive::setLocalNode(const WeakHandle& node) +void DefaultBtInteractive::setLocalNode(DHTNode* node) { localNode_ = node; } @@ -657,8 +659,7 @@ void DefaultBtInteractive::setBtMessageFactory messageFactory_ = factory; } -void DefaultBtInteractive::setRequestGroupMan -(const WeakHandle& rgman) +void DefaultBtInteractive::setRequestGroupMan(RequestGroupMan* rgman) { requestGroupMan_ = rgman; } diff --git a/src/DefaultBtInteractive.h b/src/DefaultBtInteractive.h index ef3ff147..e639e242 100644 --- a/src/DefaultBtInteractive.h +++ b/src/DefaultBtInteractive.h @@ -124,7 +124,7 @@ private: bool metadataGetMode_; - WeakHandle localNode_; + DHTNode* localNode_; Logger* logger_; size_t allowedFastSetSize_; @@ -143,7 +143,7 @@ private: size_t maxOutstandingRequest_; - WeakHandle requestGroupMan_; + RequestGroupMan* requestGroupMan_; static const time_t FLOODING_CHECK_INTERVAL = 5; @@ -232,14 +232,14 @@ public: utPexEnabled_ = f; } - void setLocalNode(const WeakHandle& node); + void setLocalNode(DHTNode* node); void setDHTEnabled(bool f) { dhtEnabled_ = f; } - void setRequestGroupMan(const WeakHandle& rgman); + void setRequestGroupMan(RequestGroupMan* rgman); void setUTMetadataRequestTracker (const SharedHandle& tracker) diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc index 3d90653a..7732fbb9 100644 --- a/src/DefaultBtMessageDispatcher.cc +++ b/src/DefaultBtMessageDispatcher.cc @@ -60,6 +60,8 @@ namespace aria2 { DefaultBtMessageDispatcher::DefaultBtMessageDispatcher(): cuid(0), + messageFactory_(0), + requestGroupMan_(0), requestTimeout_(0), logger_(LogFactory::getInstance()) {} @@ -266,14 +268,14 @@ private: SharedHandle peer_; SharedHandle pieceStorage_; BtMessageDispatcher* messageDispatcher_; - WeakHandle messageFactory_; + BtMessageFactory* messageFactory_; time_t requestTimeout_; Logger* logger_; public: ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle& peer, const SharedHandle& pieceStorage, BtMessageDispatcher* dispatcher, - const WeakHandle& factory, + BtMessageFactory* factory, time_t requestTimeout): cuid_(cuid), peer_(peer), @@ -453,14 +455,12 @@ void DefaultBtMessageDispatcher::setPeerStorage peerStorage_ = peerStorage; } -void DefaultBtMessageDispatcher::setBtMessageFactory -(const WeakHandle& factory) +void DefaultBtMessageDispatcher::setBtMessageFactory(BtMessageFactory* factory) { messageFactory_ = factory; } -void DefaultBtMessageDispatcher::setRequestGroupMan -(const WeakHandle& rgman) +void DefaultBtMessageDispatcher::setRequestGroupMan(RequestGroupMan* rgman) { requestGroupMan_ = rgman; } diff --git a/src/DefaultBtMessageDispatcher.h b/src/DefaultBtMessageDispatcher.h index bab99e2a..4f5e73d8 100644 --- a/src/DefaultBtMessageDispatcher.h +++ b/src/DefaultBtMessageDispatcher.h @@ -62,9 +62,9 @@ private: SharedHandle downloadContext_; SharedHandle peerStorage_; SharedHandle pieceStorage_; - WeakHandle messageFactory_; + BtMessageFactory* messageFactory_; SharedHandle peer_; - WeakHandle requestGroupMan_; + RequestGroupMan* requestGroupMan_; time_t requestTimeout_; Logger* logger_; public: @@ -130,9 +130,9 @@ public: void setPeerStorage(const SharedHandle& peerStorage); - void setBtMessageFactory(const WeakHandle& factory); + void setBtMessageFactory(BtMessageFactory* factory); - void setRequestGroupMan(const WeakHandle& rgman); + void setRequestGroupMan(RequestGroupMan* rgman); void setCuid(cuid_t cuid) { diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc index 88f3dbe4..c3687e72 100644 --- a/src/DefaultBtMessageFactory.cc +++ b/src/DefaultBtMessageFactory.cc @@ -70,9 +70,17 @@ namespace aria2 { -DefaultBtMessageFactory::DefaultBtMessageFactory():cuid_(0), - dhtEnabled_(false), - metadataGetMode_(false) +DefaultBtMessageFactory::DefaultBtMessageFactory(): + cuid_(0), + dhtEnabled_(false), + dispatcher_(0), + requestFactory_(0), + peerConnection_(0), + localNode_(0), + routingTable_(0), + taskQueue_(0), + taskFactory_(0), + metadataGetMode_(false) {} DefaultBtMessageFactory::~DefaultBtMessageFactory() {} @@ -251,7 +259,7 @@ void DefaultBtMessageFactory::setCommonProperty msg->setPieceStorage(pieceStorage_); msg->setBtMessageDispatcher(dispatcher_); msg->setBtRequestFactory(requestFactory_); - msg->setBtMessageFactory(WeakHandle(this)); + msg->setBtMessageFactory(this); msg->setPeerConnection(peerConnection_); if(metadataGetMode_) { msg->enableMetadataGetMode(); @@ -460,14 +468,12 @@ DefaultBtMessageFactory::createBtExtendedMessage return m; } -void DefaultBtMessageFactory::setTaskQueue -(const WeakHandle& taskQueue) +void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue) { taskQueue_ = taskQueue; } -void DefaultBtMessageFactory::setTaskFactory -(const WeakHandle& taskFactory) +void DefaultBtMessageFactory::setTaskFactory(DHTTaskFactory* taskFactory) { taskFactory_ = taskFactory; } @@ -496,7 +502,7 @@ void DefaultBtMessageFactory::setPeerStorage } void DefaultBtMessageFactory::setBtMessageDispatcher -(const WeakHandle& dispatcher) +(BtMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } @@ -507,25 +513,22 @@ void DefaultBtMessageFactory::setExtensionMessageFactory extensionMessageFactory_ = factory; } -void DefaultBtMessageFactory::setLocalNode(const WeakHandle& localNode) +void DefaultBtMessageFactory::setLocalNode(DHTNode* localNode) { localNode_ = localNode; } -void DefaultBtMessageFactory::setRoutingTable -(const WeakHandle& routingTable) +void DefaultBtMessageFactory::setRoutingTable(DHTRoutingTable* routingTable) { routingTable_ = routingTable; } -void DefaultBtMessageFactory::setBtRequestFactory -(const WeakHandle& factory) +void DefaultBtMessageFactory::setBtRequestFactory(BtRequestFactory* factory) { requestFactory_ = factory; } -void DefaultBtMessageFactory::setPeerConnection -(const WeakHandle& connection) +void DefaultBtMessageFactory::setPeerConnection(PeerConnection* connection) { peerConnection_ = connection; } diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h index b869ed5e..1ba60eaa 100644 --- a/src/DefaultBtMessageFactory.h +++ b/src/DefaultBtMessageFactory.h @@ -64,21 +64,21 @@ private: bool dhtEnabled_; - WeakHandle dispatcher_; + BtMessageDispatcher* dispatcher_; - WeakHandle requestFactory_; + BtRequestFactory* requestFactory_; - WeakHandle peerConnection_; + PeerConnection* peerConnection_; SharedHandle extensionMessageFactory_; + + DHTNode* localNode_; - WeakHandle localNode_; + DHTRoutingTable* routingTable_; - WeakHandle routingTable_; + DHTTaskQueue* taskQueue_; - WeakHandle taskQueue_; - - WeakHandle taskFactory_; + DHTTaskFactory* taskFactory_; bool metadataGetMode_; @@ -153,22 +153,22 @@ public: } void setBtMessageDispatcher - (const WeakHandle& dispatcher); + (BtMessageDispatcher* dispatcher); - void setBtRequestFactory(const WeakHandle& factory); + void setBtRequestFactory(BtRequestFactory* factory); - void setPeerConnection(const WeakHandle& connection); + void setPeerConnection(PeerConnection* connection); void setExtensionMessageFactory (const SharedHandle& factory); - void setLocalNode(const WeakHandle& localNode); + void setLocalNode(DHTNode* localNode); - void setRoutingTable(const WeakHandle& routingTable); + void setRoutingTable(DHTRoutingTable* routingTable); - void setTaskQueue(const WeakHandle& taskQueue); + void setTaskQueue(DHTTaskQueue* taskQueue); - void setTaskFactory(const WeakHandle& taskFactory); + void setTaskFactory(DHTTaskFactory* taskFactory); void enableMetadataGetMode() { diff --git a/src/DefaultBtMessageReceiver.cc b/src/DefaultBtMessageReceiver.cc index a57852b1..e3953fb9 100644 --- a/src/DefaultBtMessageReceiver.cc +++ b/src/DefaultBtMessageReceiver.cc @@ -51,7 +51,10 @@ namespace aria2 { DefaultBtMessageReceiver::DefaultBtMessageReceiver(): - handshakeSent_(false) + handshakeSent_(false), + peerConnection_(0), + dispatcher_(0), + messageFactory_(0) {} SharedHandle @@ -115,20 +118,17 @@ void DefaultBtMessageReceiver::setDownloadContext downloadContext_ = downloadContext; } -void DefaultBtMessageReceiver::setPeerConnection -(const WeakHandle& peerConnection) +void DefaultBtMessageReceiver::setPeerConnection(PeerConnection* peerConnection) { peerConnection_ = peerConnection; } -void DefaultBtMessageReceiver::setDispatcher -(const WeakHandle& dispatcher) +void DefaultBtMessageReceiver::setDispatcher(BtMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DefaultBtMessageReceiver::setBtMessageFactory -(const WeakHandle& factory) +void DefaultBtMessageReceiver::setBtMessageFactory(BtMessageFactory* factory) { messageFactory_ = factory; } diff --git a/src/DefaultBtMessageReceiver.h b/src/DefaultBtMessageReceiver.h index fc0cb096..663610c0 100644 --- a/src/DefaultBtMessageReceiver.h +++ b/src/DefaultBtMessageReceiver.h @@ -51,9 +51,9 @@ class DefaultBtMessageReceiver : public BtMessageReceiver { private: bool handshakeSent_; SharedHandle downloadContext_; - WeakHandle peerConnection_; - WeakHandle dispatcher_; - WeakHandle messageFactory_; + PeerConnection* peerConnection_; + BtMessageDispatcher* dispatcher_; + BtMessageFactory* messageFactory_; void sendHandshake(); public: @@ -68,11 +68,11 @@ public: void setDownloadContext(const SharedHandle& downloadContext); - void setPeerConnection(const WeakHandle& peerConnection); + void setPeerConnection(PeerConnection* peerConnection); - void setDispatcher(const WeakHandle& dispatcher); + void setDispatcher(BtMessageDispatcher* dispatcher); - void setBtMessageFactory(const WeakHandle& factory); + void setBtMessageFactory(BtMessageFactory* factory); }; typedef SharedHandle DefaultBtMessageReceiverHandle; diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index b35837d3..a662465d 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -96,7 +96,7 @@ void DefaultBtProgressInfoFile::updateFilename() bool DefaultBtProgressInfoFile::isTorrentDownload() { #ifdef ENABLE_BITTORRENT - return !btRuntime_.isNull(); + return btRuntime_; #else // !ENABLE_BITTORRENT return false; #endif // !ENABLE_BITTORRENT diff --git a/src/DefaultBtRequestFactory.cc b/src/DefaultBtRequestFactory.cc index 7a3f022a..070775af 100644 --- a/src/DefaultBtRequestFactory.cc +++ b/src/DefaultBtRequestFactory.cc @@ -51,6 +51,8 @@ namespace aria2 { DefaultBtRequestFactory::DefaultBtRequestFactory(): + dispatcher_(0), + messageFactory_(0), logger_(LogFactory::getInstance()) { if(logger_->debug()) { @@ -74,9 +76,9 @@ namespace { class AbortCompletedPieceRequest { private: - WeakHandle dispatcher_; + BtMessageDispatcher* dispatcher_; public: - AbortCompletedPieceRequest(const WeakHandle& dispatcher): + AbortCompletedPieceRequest(BtMessageDispatcher* dispatcher): dispatcher_(dispatcher) {} void operator()(const SharedHandle& piece) @@ -110,10 +112,10 @@ namespace { class ProcessChokedPiece { private: SharedHandle peer_; - WeakHandle pieceStorage_; + SharedHandle pieceStorage_; public: ProcessChokedPiece(const SharedHandle& peer, - const WeakHandle& pieceStorage): + const SharedHandle& pieceStorage): peer_(peer), pieceStorage_(pieceStorage) {} @@ -280,13 +282,12 @@ void DefaultBtRequestFactory::setPeer(const SharedHandle& peer) } void DefaultBtRequestFactory::setBtMessageDispatcher -(const WeakHandle& dispatcher) +(BtMessageDispatcher* dispatcher) { dispatcher_ = dispatcher; } -void DefaultBtRequestFactory::setBtMessageFactory -(const WeakHandle& factory) +void DefaultBtRequestFactory::setBtMessageFactory(BtMessageFactory* factory) { messageFactory_ = factory; } diff --git a/src/DefaultBtRequestFactory.h b/src/DefaultBtRequestFactory.h index 0977e952..3c2b3492 100644 --- a/src/DefaultBtRequestFactory.h +++ b/src/DefaultBtRequestFactory.h @@ -54,8 +54,8 @@ class DefaultBtRequestFactory : public BtRequestFactory { private: SharedHandle pieceStorage_; SharedHandle peer_; - WeakHandle dispatcher_; - WeakHandle messageFactory_; + BtMessageDispatcher* dispatcher_; + BtMessageFactory* messageFactory_; std::deque > pieces_; Logger* logger_; public: @@ -96,10 +96,9 @@ public: void setPeer(const SharedHandle& peer); - void setBtMessageDispatcher - (const WeakHandle& dispatcher); + void setBtMessageDispatcher(BtMessageDispatcher* dispatcher); - void setBtMessageFactory(const WeakHandle& factory); + void setBtMessageFactory(BtMessageFactory* factory); }; typedef SharedHandle DefaultBtRequestFactoryHandle; diff --git a/src/DefaultExtensionMessageFactory.cc b/src/DefaultExtensionMessageFactory.cc index a22d3dd3..a49abf2e 100644 --- a/src/DefaultExtensionMessageFactory.cc +++ b/src/DefaultExtensionMessageFactory.cc @@ -57,6 +57,9 @@ namespace aria2 { DefaultExtensionMessageFactory::DefaultExtensionMessageFactory(): + messageFactory_(0), + dispatcher_(0), + tracker_(0), logger_(LogFactory::getInstance()) {} DefaultExtensionMessageFactory::DefaultExtensionMessageFactory diff --git a/src/DefaultExtensionMessageFactory.h b/src/DefaultExtensionMessageFactory.h index 786614ab..e388b8d9 100644 --- a/src/DefaultExtensionMessageFactory.h +++ b/src/DefaultExtensionMessageFactory.h @@ -58,11 +58,11 @@ private: SharedHandle dctx_; - WeakHandle messageFactory_; + BtMessageFactory* messageFactory_; - WeakHandle dispatcher_; + BtMessageDispatcher* dispatcher_; - WeakHandle tracker_; + UTMetadataRequestTracker* tracker_; Logger* logger_; @@ -93,18 +93,17 @@ public: dctx_ = dctx; } - void setBtMessageFactory(const WeakHandle& factory) + void setBtMessageFactory(BtMessageFactory* factory) { messageFactory_ = factory; } - void setBtMessageDispatcher(const WeakHandle& disp) + void setBtMessageDispatcher(BtMessageDispatcher* disp) { dispatcher_ = disp; } - void setUTMetadataRequestTracker - (const WeakHandle& tracker) + void setUTMetadataRequestTracker(UTMetadataRequestTracker* tracker) { tracker_ = tracker; } diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index eebac966..95c02527 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -92,7 +92,7 @@ bool DefaultPeerStorage::isPeerAlreadyAdded(const SharedHandle& peer) namespace { size_t calculateMaxPeerListSize(const SharedHandle& btRuntime) { - if(btRuntime.isNull()) { + if(!btRuntime) { return MAX_PEER_LIST_SIZE; } return btRuntime->getMaxPeers() == 0 ? @@ -199,7 +199,7 @@ size_t DefaultPeerStorage::countPeer() const { } bool DefaultPeerStorage::isPeerAvailable() { - return !getUnusedPeer().isNull(); + return getUnusedPeer(); } namespace { diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 1a187c19..10746f1a 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -89,7 +89,7 @@ SharedHandle DefaultPieceStorage::checkOutPiece(size_t index) bitfieldMan_->setUseBit(index); SharedHandle piece = findUsedPiece(index); - if(piece.isNull()) { + if(!piece) { piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index))); #ifdef ENABLE_MESSAGE_DIGEST @@ -114,7 +114,7 @@ SharedHandle DefaultPieceStorage::getPiece(size_t index) SharedHandle piece; if(0 <= index && index <= bitfieldMan_->getMaxIndex()) { piece = findUsedPiece(index); - if(piece.isNull()) { + if(!piece) { piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index))); if(hasPiece(index)) { piece->setAllBlock(); @@ -147,7 +147,7 @@ SharedHandle DefaultPieceStorage::findUsedPiece(size_t index) const if(i != usedPieces_.end() && *(*i) == *p) { return *i; } else { - p.reset(0); + p.reset(); return p; } } @@ -363,7 +363,7 @@ SharedHandle DefaultPieceStorage::getMissingPiece(size_t index) void DefaultPieceStorage::deleteUsedPiece(const SharedHandle& piece) { - if(piece.isNull()) { + if(!piece) { return; } std::deque >::iterator i = @@ -412,7 +412,7 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle& piece) void DefaultPieceStorage::completePiece(const SharedHandle& piece) { - if(piece.isNull()) { + if(!piece) { return; } deleteUsedPiece(piece); @@ -456,7 +456,7 @@ bool DefaultPieceStorage::isSelectiveDownloadingMode() // not unittested void DefaultPieceStorage::cancelPiece(const SharedHandle& piece) { - if(piece.isNull()) { + if(!piece) { return; } bitfieldMan_->unsetUseBit(piece->getIndex()); diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 445ea77a..ed59a940 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -315,11 +315,11 @@ bool DownloadCommand::prepareForNextSegment() { } SharedHandle nextSegment = getSegmentMan()->getSegmentWithIndex (getCuid(), tempSegment->getIndex()+1); - if(nextSegment.isNull()) { + if(!nextSegment) { nextSegment = getSegmentMan()->getCleanSegmentIfOwnerIsIdle (getCuid(), tempSegment->getIndex()+1); } - if(nextSegment.isNull() || nextSegment->getWrittenLength() > 0) { + if(!nextSegment || nextSegment->getWrittenLength() > 0) { // If nextSegment->getWrittenLength() > 0, current socket must // be closed because writing incoming data at // nextSegment->getWrittenLength() corrupts file. @@ -362,7 +362,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle& segment, void DownloadCommand::installStreamFilter (const SharedHandle& streamFilter) { - if(streamFilter.isNull()) { + if(!streamFilter) { return; } streamFilter->installDelegate(streamFilter_); diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 4b2df23a..c37082bb 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -205,7 +205,7 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket, void DownloadEngine::calculateStatistics() { - if(!statCalc_.isNull()) { + if(statCalc_) { statCalc_->calculateStat(this); } } @@ -360,7 +360,7 @@ void DownloadEngine::poolSocket(const SharedHandle& request, const SharedHandle& socket, time_t timeout) { - if(proxyRequest.isNull()) { + if(!proxyRequest) { std::pair peerInfo; socket->getPeerInfo(peerInfo); poolSocket(peerInfo.first, peerInfo.second, @@ -381,7 +381,7 @@ void DownloadEngine::poolSocket const std::map& options, time_t timeout) { - if(proxyRequest.isNull()) { + if(!proxyRequest) { std::pair peerInfo; socket->getPeerInfo(peerInfo); poolSocket(peerInfo.first, peerInfo.second, username, @@ -456,7 +456,7 @@ DownloadEngine::popPooledSocket for(std::vector::const_iterator i = ipaddrs.begin(), eoi = ipaddrs.end(); i != eoi; ++i) { s = popPooledSocket(*i, port, A2STR::NIL, 0); - if(!s.isNull()) { + if(s) { break; } } @@ -473,7 +473,7 @@ DownloadEngine::popPooledSocket for(std::vector::const_iterator i = ipaddrs.begin(), eoi = ipaddrs.end(); i != eoi; ++i) { s = popPooledSocket(options, *i, port, username, A2STR::NIL, 0); - if(!s.isNull()) { + if(s) { break; } } diff --git a/src/DownloadHandler.cc b/src/DownloadHandler.cc index 29d9b027..b708e2c1 100644 --- a/src/DownloadHandler.cc +++ b/src/DownloadHandler.cc @@ -47,7 +47,7 @@ DownloadHandler::~DownloadHandler() {} bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const { - return !criteria_.isNull() && criteria_->match(requestGroup); + return criteria_ && criteria_->match(requestGroup); } void DownloadHandler::setCriteria(const RequestGroupCriteriaHandle& criteria) diff --git a/src/DownloadHandlerFactory.cc b/src/DownloadHandlerFactory.cc index feb22cf4..985a90c7 100644 --- a/src/DownloadHandlerFactory.cc +++ b/src/DownloadHandlerFactory.cc @@ -69,7 +69,7 @@ DownloadHandlerFactory::btMetadataPostDownloadHandler_; SharedHandle DownloadHandlerFactory::getMetalinkPreDownloadHandler() { - if(metalinkPreDownloadHandler_.isNull()) { + if(!metalinkPreDownloadHandler_) { metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler()); RequestGroupCriteriaHandle criteria @@ -86,7 +86,7 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler() SharedHandle DownloadHandlerFactory::getMetalinkPostDownloadHandler() { - if(metalinkPostDownloadHandler_.isNull()) { + if(!metalinkPostDownloadHandler_) { metalinkPostDownloadHandler_.reset(new MetalinkPostDownloadHandler()); } return metalinkPostDownloadHandler_; @@ -99,7 +99,7 @@ DownloadHandlerFactory::getMetalinkPostDownloadHandler() SharedHandle DownloadHandlerFactory::getBtPreDownloadHandler() { - if(btPreDownloadHandler_.isNull()) { + if(!btPreDownloadHandler_) { btPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler()); RequestGroupCriteriaHandle criteria @@ -116,7 +116,7 @@ DownloadHandlerFactory::getBtPreDownloadHandler() SharedHandle DownloadHandlerFactory::getBtPostDownloadHandler() { - if(btPostDownloadHandler_.isNull()) { + if(!btPostDownloadHandler_) { btPostDownloadHandler_.reset(new BtPostDownloadHandler()); } return btPostDownloadHandler_; @@ -125,7 +125,7 @@ DownloadHandlerFactory::getBtPostDownloadHandler() SharedHandle DownloadHandlerFactory::getUTMetadataPostDownloadHandler() { - if(btMetadataPostDownloadHandler_.isNull()) { + if(!btMetadataPostDownloadHandler_) { btMetadataPostDownloadHandler_.reset(new UTMetadataPostDownloadHandler()); } return btMetadataPostDownloadHandler_; diff --git a/src/Exception.cc b/src/Exception.cc index 1e86b30b..567d39a3 100644 --- a/src/Exception.cc +++ b/src/Exception.cc @@ -64,7 +64,7 @@ std::string Exception::stackTrace() const } s << what() << "\n"; SharedHandle e = cause_; - while(!e.isNull()) { + while(e) { s << " -> " << "[" << e->file_ << ":" << e->line_ << "] " << e->what() << "\n"; e = e->cause_; diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc index 94172241..1c10b1f8 100644 --- a/src/FeatureConfig.cc +++ b/src/FeatureConfig.cc @@ -122,7 +122,7 @@ FeatureConfig::FeatureConfig() { const SharedHandle& FeatureConfig::getInstance() { - if(featureConfig_.isNull()) { + if(!featureConfig_) { featureConfig_.reset(new FeatureConfig()); } return featureConfig_; diff --git a/src/FeedbackURISelector.cc b/src/FeedbackURISelector.cc index 2efc6c11..6ee7d9d2 100644 --- a/src/FeedbackURISelector.cc +++ b/src/FeedbackURISelector.cc @@ -115,7 +115,7 @@ std::string FeedbackURISelector::selectRarer } SharedHandle ss = serverStatMan_->find(us.host, us.protocol); - if(!ss.isNull() && ss->isError()) { + if(ss && ss->isError()) { if(logger_->debug()) { logger_->debug("Error not considered: %s", (*i).c_str()); } @@ -161,7 +161,7 @@ std::string FeedbackURISelector::selectFaster } SharedHandle ss = serverStatMan_->find(us.host, us.protocol); - if(ss.isNull()) { + if(!ss) { normCands.push_back(*i); } else if(ss->isOK()) { if(ss->getDownloadSpeed() > SPEED_THRESHOLD) { diff --git a/src/FileEntry.cc b/src/FileEntry.cc index bd26a1be..cf09a054 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -160,7 +160,7 @@ FileEntry::getRequest } } uris_.insert(uris_.begin(), pending.begin(), pending.end()); - if(g == 0 && uriReuse && req.isNull() && uris_.size() == pending.size()) { + if(g == 0 && uriReuse && !req && uris_.size() == pending.size()) { // Reuse URIs other than ones in pending reuseUri(ignoreHost); } else { @@ -187,12 +187,12 @@ FileEntry::findFasterRequest(const SharedHandle& base) return SharedHandle(); } const SharedHandle& fastest = requestPool_.front()->getPeerStat(); - if(fastest.isNull()) { + if(!fastest) { return SharedHandle(); } const SharedHandle& basestat = base->getPeerStat(); // TODO hard coded value. See PREF_STARTUP_IDLE_TIME - if(basestat.isNull() || + if(!basestat || (basestat->getDownloadStartTime(). difference(global::wallclock) >= startupIdleTime && fastest->getAvgDownloadSpeed()*0.8 > basestat->calculateDownloadSpeed())){ @@ -212,10 +212,10 @@ public: bool operator()(const SharedHandle& lhs, const SharedHandle& rhs) const { - if(lhs->getPeerStat().isNull()) { + if(!lhs->getPeerStat()) { return false; } - if(rhs->getPeerStat().isNull()) { + if(!rhs->getPeerStat()) { return true; } return @@ -227,7 +227,7 @@ public: void FileEntry::storePool(const SharedHandle& request) { const SharedHandle& peerStat = request->getPeerStat(); - if(!peerStat.isNull()) { + if(peerStat) { // We need to calculate average download speed here in order to // store Request in the right position in the pool. peerStat->calculateAvgDownloadSpeed(); diff --git a/src/FileEntry.h b/src/FileEntry.h index 914f5c8c..4313e3d9 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -315,7 +315,7 @@ void writeFilePath (InputIterator first, InputIterator last, std::ostream& o, bool memory) { SharedHandle e = getFirstRequestedFileEntry(first, last); - if(e.isNull()) { + if(!e) { o << "n/a"; } else { if(e->getPath().empty()) { diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 74f2f654..f690ae6b 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -291,7 +291,7 @@ bool FtpConnection::sendRest(const SharedHandle& segment) { if(socketBuffer_.sendBufferIsEmpty()) { std::string request = "REST "; - if(segment.isNull()) { + if(!segment) { request += "0"; } else { request += util::itos(segment->getPositionToWrite()); diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc index b45fe8a1..0e7be69f 100644 --- a/src/FtpInitiateConnectionCommand.cc +++ b/src/FtpInitiateConnectionCommand.cc @@ -77,7 +77,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand const SharedHandle& proxyRequest) { Command* command; - if(!proxyRequest.isNull()) { + if(proxyRequest) { std::map options; SharedHandle pooledSocket; std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol()); @@ -92,7 +92,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand (getRequest(), getOption().get())->getUser(), proxyRequest->getHost(), proxyRequest->getPort()); } - if(pooledSocket.isNull()) { + if(!pooledSocket) { if(getLogger()->info()) { getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(), addr.c_str(), port); @@ -157,7 +157,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand getRequest()->getPort(), getDownloadEngine()->getAuthConfigFactory()->createAuthConfig (getRequest(), getOption().get())->getUser()); - if(pooledSocket.isNull()) { + if(!pooledSocket) { if(getLogger()->info()) { getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(), addr.c_str(), port); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 1c962575..fa6a006c 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -444,7 +444,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) SharedHandle checkIntegrityEntry = getRequestGroup()->createCheckIntegrityEntry(); - if(checkIntegrityEntry.isNull()) { + if(!checkIntegrityEntry) { sequence_ = SEQ_DOWNLOAD_ALREADY_COMPLETED; poolConnection(); return false; @@ -475,7 +475,7 @@ bool FtpNegotiationCommand::recvSize() { (StringFormat(EX_TOO_LARGE_FILE, util::uitos(size, true).c_str()).str()); } - if(getPieceStorage().isNull()) { + if(!getPieceStorage()) { sequence_ = SEQ_FILE_PREPARATION; return onFileSizeDetermined(size); @@ -492,7 +492,7 @@ bool FtpNegotiationCommand::recvSize() { // Even if one of the other servers waiting in the queue supports SIZE // command, resuming and segmented downloading are disabled when the first // contacted FTP server doesn't support it. - if(getPieceStorage().isNull()) { + if(!getPieceStorage()) { getDownloadContext()->markTotalLengthIsUnknown(); return onFileSizeDetermined(0); @@ -747,7 +747,7 @@ bool FtpNegotiationCommand::sendTunnelRequest() bool FtpNegotiationCommand::recvTunnelResponse() { SharedHandle httpResponse = http_->receiveResponse(); - if(httpResponse.isNull()) { + if(!httpResponse) { return false; } if(httpResponse->getResponseStatus() != HttpHeader::S200) { @@ -788,7 +788,7 @@ bool FtpNegotiationCommand::recvRest(const SharedHandle& segment) { // If we recieve negative response and requested file position is not 0, // then throw exception here. if(status != 350) { - if(!segment.isNull() && segment->getPositionToWrite() != 0) { + if(segment && segment->getPositionToWrite() != 0) { throw DL_ABORT_EX2("FTP server doesn't support resuming.", downloadresultcode::CANNOT_RESUME); } diff --git a/src/HaveEraseCommand.cc b/src/HaveEraseCommand.cc index 0b560303..c1cca2f9 100644 --- a/src/HaveEraseCommand.cc +++ b/src/HaveEraseCommand.cc @@ -65,7 +65,7 @@ void HaveEraseCommand::process() PieceStorageHandle ps = getDownloadEngine()->getRequestGroupMan()->getRequestGroup(i)-> getPieceStorage(); - if(!ps.isNull()) { + if(ps) { ps->removeAdvertisedPiece(5); } } diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc index aad8f938..bba0f7ee 100644 --- a/src/HttpInitiateConnectionCommand.cc +++ b/src/HttpInitiateConnectionCommand.cc @@ -71,13 +71,13 @@ Command* HttpInitiateConnectionCommand::createNextCommand const SharedHandle& proxyRequest) { Command* command; - if(!proxyRequest.isNull()) { + if(proxyRequest) { SharedHandle pooledSocket = getDownloadEngine()->popPooledSocket (getRequest()->getHost(), getRequest()->getPort(), proxyRequest->getHost(), proxyRequest->getPort()); std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol()); - if(pooledSocket.isNull()) { + if(!pooledSocket) { if(getLogger()->info()) { getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(), addr.c_str(), port); @@ -132,7 +132,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand SharedHandle pooledSocket = getDownloadEngine()->popPooledSocket (resolvedAddresses, getRequest()->getPort()); - if(pooledSocket.isNull()) { + if(!pooledSocket) { if(getLogger()->info()) { getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(), addr.c_str(), port); diff --git a/src/HttpListenCommand.cc b/src/HttpListenCommand.cc index 52e5c0af..13c67912 100644 --- a/src/HttpListenCommand.cc +++ b/src/HttpListenCommand.cc @@ -58,7 +58,7 @@ HttpListenCommand::HttpListenCommand HttpListenCommand::~HttpListenCommand() { - if(!serverSocket_.isNull()) { + if(serverSocket_) { e_->deleteSocketForReadCheck(serverSocket_, this); } } @@ -95,7 +95,7 @@ bool HttpListenCommand::execute() bool HttpListenCommand::bindPort(uint16_t port) { - if(!serverSocket_.isNull()) { + if(serverSocket_) { e_->deleteSocketForReadCheck(serverSocket_, this); } serverSocket_.reset(new SocketCore()); @@ -123,7 +123,7 @@ bool HttpListenCommand::bindPort(uint16_t port) family_ == AF_INET?4:6); getLogger()->error(MSG_BIND_FAILURE, e, util::itos(getCuid()).c_str(), port); - if(!serverSocket_.isNull()) { + if(serverSocket_) { e_->deleteSocketForReadCheck(serverSocket_, this); } serverSocket_->closeConnection(); diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index b2725066..1b2b2c40 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -74,7 +74,7 @@ void HttpRequest::setRequest(const SharedHandle& request) off_t HttpRequest::getStartByte() const { - if(segment_.isNull()) { + if(!segment_) { return 0; } else { return fileEntry_->gtoloff(segment_->getPositionToWrite()); @@ -83,7 +83,7 @@ off_t HttpRequest::getStartByte() const off_t HttpRequest::getEndByte() const { - if(segment_.isNull() || request_.isNull()) { + if(!segment_ || !request_) { return 0; } else { if(request_->isPipeliningEnabled()) { @@ -99,7 +99,7 @@ off_t HttpRequest::getEndByte() const RangeHandle HttpRequest::getRange() const { // content-length is always 0 - if(segment_.isNull()) { + if(!segment_) { return SharedHandle(new Range()); } else { return SharedHandle(new Range(getStartByte(), getEndByte(), @@ -109,7 +109,7 @@ RangeHandle HttpRequest::getRange() const bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const { - if(segment_.isNull()) { + if(!segment_) { return true; } if((getStartByte() == range->getStartByte()) && @@ -139,9 +139,9 @@ std::string HttpRequest::createRequest() authConfig_ = authConfigFactory_->createAuthConfig(request_, option_); std::string requestLine = request_->getMethod(); requestLine += " "; - if(!proxyRequest_.isNull()) { + if(proxyRequest_) { if(getProtocol() == Request::PROTO_FTP && - request_->getUsername().empty() && !authConfig_.isNull()) { + request_->getUsername().empty() && authConfig_) { // Insert user into URI, like ftp://USER@host/ std::string uri = getCurrentURI(); assert(uri.size() >= 6); @@ -192,7 +192,7 @@ std::string HttpRequest::createRequest() if(!request_->isKeepAliveEnabled() && !request_->isPipeliningEnabled()) { builtinHds.push_back(std::make_pair("Connection:", "close")); } - if(!segment_.isNull() && segment_->getLength() > 0 && + if(segment_ && segment_->getLength() > 0 && (request_->isPipeliningEnabled() || getStartByte() > 0)) { std::string rangeHeader = "bytes="; rangeHeader += util::itos(getStartByte()); @@ -205,17 +205,17 @@ std::string HttpRequest::createRequest() } builtinHds.push_back(std::make_pair("Range:", rangeHeader)); } - if(!proxyRequest_.isNull()) { + if(proxyRequest_) { if(request_->isKeepAliveEnabled() || request_->isPipeliningEnabled()) { builtinHds.push_back(std::make_pair("Proxy-Connection:", "Keep-Alive")); } else { builtinHds.push_back(std::make_pair("Proxy-Connection:", "close")); } } - if(!proxyRequest_.isNull() && !proxyRequest_->getUsername().empty()) { + if(proxyRequest_ && !proxyRequest_->getUsername().empty()) { builtinHds.push_back(getProxyAuthString()); } - if(!authConfig_.isNull()) { + if(authConfig_) { builtinHds.push_back (std::make_pair("Authorization:", strconcat("Basic ", @@ -224,7 +224,7 @@ std::string HttpRequest::createRequest() if(getPreviousURI().size()) { builtinHds.push_back(std::make_pair("Referer:", getPreviousURI())); } - if(!cookieStorage_.isNull()) { + if(cookieStorage_) { std::string cookiesValue; std::vector cookies = cookieStorage_->criteriaFind @@ -270,7 +270,7 @@ std::string HttpRequest::createRequest() std::string HttpRequest::createProxyRequest() const { - assert(!proxyRequest_.isNull()); + assert(proxyRequest_); std::string hostport = getURIHost(); strappend(hostport, ":", util::uitos(getPort())); @@ -344,12 +344,12 @@ void HttpRequest::setProxyRequest(const SharedHandle& proxyRequest) bool HttpRequest::isProxyRequestSet() const { - return !proxyRequest_.isNull(); + return proxyRequest_; } bool HttpRequest::authenticationUsed() const { - return !authConfig_.isNull(); + return authConfig_; } const SharedHandle& HttpRequest::getAuthConfig() const diff --git a/src/HttpRequest.h b/src/HttpRequest.h index fa4ec390..55c67438 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -106,7 +106,7 @@ public: uint64_t getEntityLength() const { - assert(!fileEntry_.isNull()); + assert(fileEntry_); return fileEntry_->getLength(); } diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 91a7d4b4..d8964052 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -183,7 +183,7 @@ bool HttpRequestCommand::executeInternal() { if(!httpConnection_->isIssued(segment)) { off_t endOffset = 0; if(getRequestGroup()->getTotalLength() > 0 && - !getPieceStorage().isNull()) { + getPieceStorage()) { size_t nextIndex = getPieceStorage()->getNextUsedIndex(segment->getIndex()); endOffset = std::min diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index b2961491..ef3ce260 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -217,7 +217,7 @@ SharedHandle HttpResponse::getContentEncodingStreamFilter() const uint64_t HttpResponse::getContentLength() const { - if(httpHeader_.isNull()) { + if(!httpHeader_) { return 0; } else { return httpHeader_->getRange()->getContentLength(); @@ -226,7 +226,7 @@ uint64_t HttpResponse::getContentLength() const uint64_t HttpResponse::getEntityLength() const { - if(httpHeader_.isNull()) { + if(!httpHeader_) { return 0; } else { return httpHeader_->getRange()->getEntityLength(); @@ -235,7 +235,7 @@ uint64_t HttpResponse::getEntityLength() const std::string HttpResponse::getContentType() const { - if(httpHeader_.isNull()) { + if(!httpHeader_) { return A2STR::NIL; } else { std::pair p; diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index fb90d5ae..e17b298e 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -87,7 +87,7 @@ SharedHandle getTransferEncodingStreamFilter SharedHandle filter; if(httpResponse->isTransferEncodingSpecified()) { filter = httpResponse->getTransferEncodingStreamFilter(); - if(filter.isNull()) { + if(!filter) { throw DL_ABORT_EX (StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED, httpResponse->getTransferEncoding().c_str()).str()); @@ -95,7 +95,7 @@ SharedHandle getTransferEncodingStreamFilter filter->init(); filter->installDelegate(delegate); } - if(filter.isNull()) { + if(!filter) { filter = delegate; } return filter; @@ -110,7 +110,7 @@ SharedHandle getContentEncodingStreamFilter SharedHandle filter; if(httpResponse->isContentEncodingSpecified()) { filter = httpResponse->getContentEncodingStreamFilter(); - if(filter.isNull()) { + if(!filter) { LogFactory::getInstance()->info ("Content-Encoding %s is specified, but the current implementation" "doesn't support it. The decoding process is skipped and the" @@ -121,7 +121,7 @@ SharedHandle getContentEncodingStreamFilter filter->installDelegate(delegate); } } - if(filter.isNull()) { + if(!filter) { filter = delegate; } return filter; @@ -146,7 +146,7 @@ bool HttpResponseCommand::executeInternal() { SharedHandle httpRequest =httpConnection_->getFirstHttpRequest(); SharedHandle httpResponse = httpConnection_->receiveResponse(); - if(httpResponse.isNull()) { + if(!httpResponse) { // The server has not responded to our request yet. // For socket->wantRead() == true, setReadCheckSocket(socket) is already // done in the constructor. @@ -204,7 +204,7 @@ bool HttpResponseCommand::executeInternal() getFileEntry()->removeURIWhoseHostnameIs(us.host); } } - if(getPieceStorage().isNull()) { + if(!getPieceStorage()) { uint64_t totalLength = httpResponse->getEntityLength(); getFileEntry()->setLength(totalLength); if(getFileEntry()->getPath().empty()) { @@ -306,7 +306,7 @@ bool HttpResponseCommand::handleDefaultEncoding SharedHandle checkEntry = getRequestGroup()->createCheckIntegrityEntry(); - if(checkEntry.isNull()) { + if(!checkEntry) { return true; } File file(getRequestGroup()->getFirstFilePath()); @@ -322,7 +322,7 @@ bool HttpResponseCommand::handleDefaultEncoding // Therefore, we shutdown the socket here if pipelining is enabled. DownloadCommand* command = 0; if(getRequest()->getMethod() == Request::METHOD_GET && - !segment.isNull() && segment->getPositionToWrite() == 0 && + segment && segment->getPositionToWrite() == 0 && !getRequest()->isPipeliningEnabled()) { command = createHttpDownloadCommand (httpResponse, @@ -371,7 +371,7 @@ bool HttpResponseCommand::handleOtherEncoding getContentEncodingStreamFilter(httpResponse)); // If chunked transfer-encoding is specified, we have to read end of // chunk markers(0\r\n\r\n, for example). - bool chunkedUsed = !streamFilter.isNull() && + bool chunkedUsed = streamFilter && streamFilter->getName() == ChunkedDecodingStreamFilter::NAME; // For zero-length file, check existing file comparing its size @@ -448,7 +448,7 @@ bool decideFileAllocation (const SharedHandle& filter) { #ifdef HAVE_LIBZ - for(SharedHandle f = filter; !f.isNull(); f = f->getDelegate()){ + for(SharedHandle f = filter; f; f = f->getDelegate()){ // Since the compressed file's length are returned in the response header // and the decompressed file size is unknown at this point, disable file // allocation here. diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 416329fd..9a299ec9 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -82,7 +82,7 @@ SharedHandle HttpServer::receiveRequest() socket_->readData(buf, size); SharedHandle header = headerProcessor_->getHttpRequestHeader(); - if(!header.isNull()) { + if(header) { logger_->info("HTTP Server received request\n%s", headerProcessor_->getHeaderString().c_str()); lastRequestHeader_ = header; diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index bbce79df..95f48d67 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -101,7 +101,7 @@ bool HttpServerCommand::execute() header = httpServer_->receiveRequest(); - if(header.isNull()) { + if(!header) { e_->addCommand(this); return false; } diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index 6f0a173e..3eaef917 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -87,7 +87,7 @@ HttpSkipResponseCommand::~HttpSkipResponseCommand() {} void HttpSkipResponseCommand::installStreamFilter (const SharedHandle& streamFilter) { - if(streamFilter.isNull()) { + if(!streamFilter) { return; } streamFilter->installDelegate(streamFilter_); diff --git a/src/InitiateConnectionCommand.cc b/src/InitiateConnectionCommand.cc index 25b2f210..50c47ddd 100644 --- a/src/InitiateConnectionCommand.cc +++ b/src/InitiateConnectionCommand.cc @@ -77,7 +77,7 @@ bool InitiateConnectionCommand::executeInternal() { std::string hostname; uint16_t port; SharedHandle proxyRequest = createProxyRequest(); - if(proxyRequest.isNull()) { + if(!proxyRequest) { hostname = getRequest()->getHost(); port = getRequest()->getPort(); } else { diff --git a/src/LpdReceiveMessageCommand.cc b/src/LpdReceiveMessageCommand.cc index 86e84131..511cce78 100644 --- a/src/LpdReceiveMessageCommand.cc +++ b/src/LpdReceiveMessageCommand.cc @@ -84,17 +84,17 @@ bool LpdReceiveMessageCommand::execute() } for(size_t i = 0; i < 20; ++i) { SharedHandle m = receiver_->receiveMessage(); - if(m.isNull()) { + if(!m) { break; } - if(m->getPeer().isNull()) { + if(!m->getPeer()) { // bad message continue; } SharedHandle reg = e_->getBtRegistry(); SharedHandle dctx = reg->getDownloadContext(m->getInfoHash()); - if(dctx.isNull()) { + if(!dctx) { if(getLogger()->debug()) { getLogger()->debug("Download Context is null for infohash=%s.", util::toHex(m->getInfoHash()).c_str()); @@ -113,7 +113,7 @@ bool LpdReceiveMessageCommand::execute() BtObject btobj = reg->get(group->getGID()); assert(!btobj.isNull()); SharedHandle peerStorage = btobj.peerStorage_; - assert(!peerStorage.isNull()); + assert(peerStorage); SharedHandle peer = m->getPeer(); if(peerStorage->addPeer(peer)) { if(getLogger()->debug()) { diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc index bc34130a..0ae9c6b5 100644 --- a/src/MSEHandshake.cc +++ b/src/MSEHandshake.cc @@ -492,7 +492,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength break; } } - if(downloadContext.isNull()) { + if(!downloadContext) { throw DL_ABORT_EX("Unknown info hash."); } initCipher(bittorrent::getInfoHash(downloadContext)); diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index cc7ec657..c2e943ef 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -212,7 +212,7 @@ Metalink2RequestGroup::createRequestGroup torrentRg = result[0]; } } - if(!torrentRg.isNull()) { + if(torrentRg) { torrentRg->setNumConcurrentCommand(1); torrentRg->clearPreDownloadHandler(); torrentRg->clearPostDownloadHandler(); @@ -242,7 +242,7 @@ Metalink2RequestGroup::createRequestGroup // make segment size equal to piece hash size. size_t pieceLength; #ifdef ENABLE_MESSAGE_DIGEST - if(entry->chunkChecksum.isNull()) { + if(!entry->chunkChecksum) { pieceLength = option->getAsInt(PREF_SEGMENT_SIZE); } else { pieceLength = entry->chunkChecksum->getChecksumLength(); @@ -261,11 +261,11 @@ Metalink2RequestGroup::createRequestGroup dctx->getFirstFileEntry()->setUniqueProtocol(true); } #ifdef ENABLE_MESSAGE_DIGEST - if(!entry->checksum.isNull()) { + if(entry->checksum) { dctx->setChecksum(entry->checksum->getMessageDigest()); dctx->setChecksumHashAlgo(entry->checksum->getAlgo()); } - if(!entry->chunkChecksum.isNull()) { + if(entry->chunkChecksum) { dctx->setPieceHashes(entry->chunkChecksum->getChecksums().begin(), entry->chunkChecksum->getChecksums().end()); dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo()); @@ -314,9 +314,9 @@ Metalink2RequestGroup::createRequestGroup util::removeMetalinkContentTypes(rg); #ifdef ENABLE_BITTORRENT // Inject depenency between rg and torrentRg here if - // torrentRg.isNull() == false - if(!torrentRg.isNull()) { - SharedHandle dep(new BtDependency(rg, torrentRg)); + // torrentRg is true + if(torrentRg) { + SharedHandle dep(new BtDependency(rg.get(), torrentRg)); rg->dependsOn(dep); torrentRg->belongsTo(rg->getGID()); // metadata download may take very long time. If URIs are diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc index 1acf65b8..9a81a3f3 100644 --- a/src/MetalinkParserController.cc +++ b/src/MetalinkParserController.cc @@ -73,10 +73,10 @@ void MetalinkParserController::newEntryTransaction() void MetalinkParserController::setFileNameOfEntry(const std::string& filename) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } - if(tEntry_->file.isNull()) { + if(!tEntry_->file) { tEntry_->file.reset(new FileEntry(util::escapePath(filename), 0, 0)); } else { tEntry_->file->setPath(util::escapePath(filename)); @@ -85,10 +85,10 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename) void MetalinkParserController::setFileLengthOfEntry(uint64_t length) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } - if(tEntry_->file.isNull()) { + if(!tEntry_->file) { return; } tEntry_->file->setLength(length); @@ -97,7 +97,7 @@ void MetalinkParserController::setFileLengthOfEntry(uint64_t length) void MetalinkParserController::setVersionOfEntry(const std::string& version) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tEntry_->version = version; @@ -105,7 +105,7 @@ void MetalinkParserController::setVersionOfEntry(const std::string& version) void MetalinkParserController::setLanguageOfEntry(const std::string& language) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tEntry_->languages.push_back(language); @@ -113,7 +113,7 @@ void MetalinkParserController::setLanguageOfEntry(const std::string& language) void MetalinkParserController::setOSOfEntry(const std::string& os) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tEntry_->oses.push_back(os); @@ -121,7 +121,7 @@ void MetalinkParserController::setOSOfEntry(const std::string& os) void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections) { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tEntry_->maxConnections = maxConnections; @@ -129,7 +129,7 @@ void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections) void MetalinkParserController::commitEntryTransaction() { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } commitResourceTransaction(); @@ -155,7 +155,7 @@ void MetalinkParserController::cancelEntryTransaction() void MetalinkParserController::newResourceTransaction() { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tResource_.reset(new MetalinkResource()); @@ -163,7 +163,7 @@ void MetalinkParserController::newResourceTransaction() void MetalinkParserController::setURLOfResource(const std::string& url) { - if(tResource_.isNull()) { + if(!tResource_) { return; } tResource_->url = url; @@ -179,7 +179,7 @@ void MetalinkParserController::setURLOfResource(const std::string& url) void MetalinkParserController::setTypeOfResource(const std::string& type) { - if(tResource_.isNull()) { + if(!tResource_) { return; } if(type == MetalinkResource::FTP) { @@ -199,7 +199,7 @@ void MetalinkParserController::setTypeOfResource(const std::string& type) void MetalinkParserController::setLocationOfResource(const std::string& location) { - if(tResource_.isNull()) { + if(!tResource_) { return; } tResource_->location = location; @@ -207,7 +207,7 @@ void MetalinkParserController::setLocationOfResource(const std::string& location void MetalinkParserController::setPriorityOfResource(int priority) { - if(tResource_.isNull()) { + if(!tResource_) { return; } tResource_->priority = priority; @@ -215,7 +215,7 @@ void MetalinkParserController::setPriorityOfResource(int priority) void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections) { - if(tResource_.isNull()) { + if(!tResource_) { return; } tResource_->maxConnections = maxConnections; @@ -223,7 +223,7 @@ void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections) void MetalinkParserController::commitResourceTransaction() { - if(tResource_.isNull()) { + if(!tResource_) { return; } #ifdef ENABLE_BITTORRENT @@ -250,7 +250,7 @@ void MetalinkParserController::cancelResourceTransaction() void MetalinkParserController::newChecksumTransaction() { #ifdef ENABLE_MESSAGE_DIGEST - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tChecksum_.reset(new Checksum()); @@ -260,7 +260,7 @@ void MetalinkParserController::newChecksumTransaction() void MetalinkParserController::setTypeOfChecksum(const std::string& type) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChecksum_.isNull()) { + if(!tChecksum_) { return; } std::string calgo = MessageDigest::getCanonicalHashType(type); @@ -275,7 +275,7 @@ void MetalinkParserController::setTypeOfChecksum(const std::string& type) void MetalinkParserController::setHashOfChecksum(const std::string& md) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChecksum_.isNull()) { + if(!tChecksum_) { return; } if(MessageDigest::isValidHash(tChecksum_->getAlgo(), md)) { @@ -289,10 +289,10 @@ void MetalinkParserController::setHashOfChecksum(const std::string& md) void MetalinkParserController::commitChecksumTransaction() { #ifdef ENABLE_MESSAGE_DIGEST - if(tChecksum_.isNull()) { + if(!tChecksum_) { return; } - if(tEntry_->checksum.isNull() || + if(!tEntry_->checksum || MessageDigest::isStronger(tChecksum_->getAlgo(), tEntry_->checksum->getAlgo())) { tEntry_->checksum = tChecksum_; @@ -311,7 +311,7 @@ void MetalinkParserController::cancelChecksumTransaction() void MetalinkParserController::newChunkChecksumTransactionV4() { #ifdef ENABLE_MESSAGE_DIGEST - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tChunkChecksumV4_.reset(new ChunkChecksum()); @@ -322,7 +322,7 @@ void MetalinkParserController::newChunkChecksumTransactionV4() void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksumV4_.isNull()) { + if(!tChunkChecksumV4_) { return; } std::string calgo = MessageDigest::getCanonicalHashType(type); @@ -337,7 +337,7 @@ void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type) void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksumV4_.isNull()) { + if(!tChunkChecksumV4_) { return; } if(length > 0) { @@ -351,7 +351,7 @@ void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length) void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksumV4_.isNull()) { + if(!tChunkChecksumV4_) { return; } if(MessageDigest::isValidHash(tChunkChecksumV4_->getAlgo(), md)) { @@ -365,10 +365,10 @@ void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md) void MetalinkParserController::commitChunkChecksumTransactionV4() { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksumV4_.isNull()) { + if(!tChunkChecksumV4_) { return; } - if(tEntry_->chunkChecksum.isNull() || + if(!tEntry_->chunkChecksum || MessageDigest::isStronger(tChunkChecksumV4_->getAlgo(), tEntry_->chunkChecksum->getAlgo())) { std::vector checksums(tempChunkChecksumsV4_.begin(), @@ -390,7 +390,7 @@ void MetalinkParserController::cancelChunkChecksumTransactionV4() void MetalinkParserController::newChunkChecksumTransaction() { #ifdef ENABLE_MESSAGE_DIGEST - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tChunkChecksum_.reset(new ChunkChecksum()); @@ -401,7 +401,7 @@ void MetalinkParserController::newChunkChecksumTransaction() void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } std::string calgo = MessageDigest::getCanonicalHashType(type); @@ -416,7 +416,7 @@ void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type) void MetalinkParserController::setLengthOfChunkChecksum(size_t length) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } if(length > 0) { @@ -430,7 +430,7 @@ void MetalinkParserController::setLengthOfChunkChecksum(size_t length) void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::string& md) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) { @@ -444,7 +444,7 @@ void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::s void MetalinkParserController::createNewHashOfChunkChecksum(size_t order) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } tempHashPair_.first = order; @@ -454,7 +454,7 @@ void MetalinkParserController::createNewHashOfChunkChecksum(size_t order) void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string& md) { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } if(MessageDigest::isValidHash(tChunkChecksum_->getAlgo(), md)) { @@ -468,7 +468,7 @@ void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string void MetalinkParserController::addHashOfChunkChecksum() { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } tempChunkChecksums_.push_back(tempHashPair_); @@ -478,10 +478,10 @@ void MetalinkParserController::addHashOfChunkChecksum() void MetalinkParserController::commitChunkChecksumTransaction() { #ifdef ENABLE_MESSAGE_DIGEST - if(tChunkChecksum_.isNull()) { + if(!tChunkChecksum_) { return; } - if(tEntry_->chunkChecksum.isNull() || + if(!tEntry_->chunkChecksum || MessageDigest::isStronger(tChunkChecksum_->getAlgo(), tEntry_->chunkChecksum->getAlgo())) { std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end(), @@ -506,7 +506,7 @@ void MetalinkParserController::cancelChunkChecksumTransaction() void MetalinkParserController::newSignatureTransaction() { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tSignature_.reset(new Signature()); @@ -514,7 +514,7 @@ void MetalinkParserController::newSignatureTransaction() void MetalinkParserController::setTypeOfSignature(const std::string& type) { - if(tSignature_.isNull()) { + if(!tSignature_) { return; } tSignature_->setType(type); @@ -522,7 +522,7 @@ void MetalinkParserController::setTypeOfSignature(const std::string& type) void MetalinkParserController::setFileOfSignature(const std::string& file) { - if(tSignature_.isNull()) { + if(!tSignature_) { return; } tSignature_->setFile(file); @@ -530,7 +530,7 @@ void MetalinkParserController::setFileOfSignature(const std::string& file) void MetalinkParserController::setBodyOfSignature(const std::string& body) { - if(tSignature_.isNull()) { + if(!tSignature_) { return; } tSignature_->setBody(body); @@ -538,7 +538,7 @@ void MetalinkParserController::setBodyOfSignature(const std::string& body) void MetalinkParserController::commitSignatureTransaction() { - if(tSignature_.isNull()) { + if(!tSignature_) { return; } tEntry_->setSignature(tSignature_); @@ -552,7 +552,7 @@ void MetalinkParserController::cancelSignatureTransaction() void MetalinkParserController::newMetaurlTransaction() { - if(tEntry_.isNull()) { + if(!tEntry_) { return; } tMetaurl_.reset(new MetalinkMetaurl()); @@ -560,7 +560,7 @@ void MetalinkParserController::newMetaurlTransaction() void MetalinkParserController::setURLOfMetaurl(const std::string& url) { - if(tMetaurl_.isNull()) { + if(!tMetaurl_) { return; } tMetaurl_->url = url; @@ -569,7 +569,7 @@ void MetalinkParserController::setURLOfMetaurl(const std::string& url) void MetalinkParserController::setMediatypeOfMetaurl (const std::string& mediatype) { - if(tMetaurl_.isNull()) { + if(!tMetaurl_) { return; } tMetaurl_->mediatype = mediatype; @@ -577,7 +577,7 @@ void MetalinkParserController::setMediatypeOfMetaurl void MetalinkParserController::setPriorityOfMetaurl(int priority) { - if(tMetaurl_.isNull()) { + if(!tMetaurl_) { return; } tMetaurl_->priority = priority; @@ -585,7 +585,7 @@ void MetalinkParserController::setPriorityOfMetaurl(int priority) void MetalinkParserController::setNameOfMetaurl(const std::string& name) { - if(tMetaurl_.isNull()) { + if(!tMetaurl_) { return; } tMetaurl_->name = name; @@ -593,7 +593,7 @@ void MetalinkParserController::setNameOfMetaurl(const std::string& name) void MetalinkParserController::commitMetaurlTransaction() { - if(tMetaurl_.isNull()) { + if(!tMetaurl_) { return; } #ifdef ENABLE_BITTORRENT diff --git a/src/MetalinkPostDownloadHandler.cc b/src/MetalinkPostDownloadHandler.cc index 2b65e988..3b142bfe 100644 --- a/src/MetalinkPostDownloadHandler.cc +++ b/src/MetalinkPostDownloadHandler.cc @@ -80,7 +80,7 @@ void MetalinkPostDownloadHandler::getNextRequestGroups requestGroup->followedBy(newRgs.begin(), newRgs.end()); SharedHandle mi = createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext()); - if(!mi.isNull()) { + if(mi) { setMetadataInfo(newRgs.begin(), newRgs.end(), mi); } groups.insert(groups.end(), newRgs.begin(), newRgs.end()); diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 05dcb719..f9d899d4 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -63,7 +63,7 @@ const std::string& DiskWriterEntry::getFilePath() const void DiskWriterEntry::initAndOpenFile() { - if(!diskWriter_.isNull()) { + if(diskWriter_) { diskWriter_->initAndOpenFile(fileEntry_->getLength()); if(directIO_) { diskWriter_->enableDirectIO(); @@ -74,7 +74,7 @@ void DiskWriterEntry::initAndOpenFile() void DiskWriterEntry::openFile() { - if(!diskWriter_.isNull()) { + if(diskWriter_) { diskWriter_->openFile(fileEntry_->getLength()); if(directIO_) { diskWriter_->enableDirectIO(); @@ -85,7 +85,7 @@ void DiskWriterEntry::openFile() void DiskWriterEntry::openExistingFile() { - if(!diskWriter_.isNull()) { + if(diskWriter_) { diskWriter_->openExistingFile(fileEntry_->getLength()); if(directIO_) { diskWriter_->enableDirectIO(); diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc index 9a0dc3f5..85b3f527 100644 --- a/src/MultiFileAllocationIterator.cc +++ b/src/MultiFileAllocationIterator.cc @@ -55,7 +55,7 @@ MultiFileAllocationIterator::~MultiFileAllocationIterator() {} void MultiFileAllocationIterator::allocateChunk() { - while(fileAllocationIterator_.isNull() || + while(!fileAllocationIterator_ || fileAllocationIterator_->finished()) { if(entries_.empty()) { break; @@ -92,12 +92,12 @@ void MultiFileAllocationIterator::allocateChunk() bool MultiFileAllocationIterator::finished() { return entries_.empty() && - (fileAllocationIterator_.isNull() || fileAllocationIterator_->finished()); + (!fileAllocationIterator_ || fileAllocationIterator_->finished()); } off_t MultiFileAllocationIterator::getCurrentLength() { - if(fileAllocationIterator_.isNull()) { + if(!fileAllocationIterator_) { return 0; } else { return fileAllocationIterator_->getCurrentLength(); @@ -106,7 +106,7 @@ off_t MultiFileAllocationIterator::getCurrentLength() uint64_t MultiFileAllocationIterator::getTotalLength() { - if(fileAllocationIterator_.isNull()) { + if(!fileAllocationIterator_) { return 0; } else { return fileAllocationIterator_->getTotalLength(); diff --git a/src/Netrc.cc b/src/Netrc.cc index 2ba523b9..99e0eb8d 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -105,7 +105,7 @@ void Netrc::parse(const std::string& path) storeAuthenticator(authenticator); authenticator.reset(new DefaultAuthenticator()); } else { - if(authenticator.isNull()) { + if(!authenticator) { throw DL_ABORT_EX (StringFormat("Netrc:parse error. %s encounterd where 'machine'" " or 'default' expected.", token.c_str()).str()); @@ -145,7 +145,7 @@ void Netrc::parse(const std::string& path) void Netrc::storeAuthenticator(const SharedHandle& authenticator) { - if(!authenticator.isNull()) { + if(authenticator) { authenticators_.push_back(authenticator); } } diff --git a/src/NetrcAuthResolver.cc b/src/NetrcAuthResolver.cc index 9d188585..ea6d298c 100644 --- a/src/NetrcAuthResolver.cc +++ b/src/NetrcAuthResolver.cc @@ -43,7 +43,7 @@ NetrcAuthResolver::NetrcAuthResolver():ignoreDefault_(false) {} SharedHandle NetrcAuthResolver::resolveAuthConfig(const std::string& hostname) { - if(getUserDefinedAuthConfig().isNull()) { + if(!getUserDefinedAuthConfig()) { return findNetrcAuthenticator(hostname); } else { return getUserDefinedAuthConfig(); @@ -53,11 +53,11 @@ NetrcAuthResolver::resolveAuthConfig(const std::string& hostname) SharedHandle NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const { - if(netrc_.isNull()) { + if(!netrc_) { return getDefaultAuthConfig(); } else { SharedHandle auth = netrc_->findAuthenticator(hostname); - if(auth.isNull()) { + if(!auth) { return getDefaultAuthConfig(); } else { if(ignoreDefault_ && auth->getMachine().empty()) { diff --git a/src/OptionParser.cc b/src/OptionParser.cc index a99b76b7..be872d3e 100644 --- a/src/OptionParser.cc +++ b/src/OptionParser.cc @@ -154,7 +154,7 @@ void OptionParser::parseArg } else { op = findByShortName(c); } - if(op.isNull()) { + if(!op) { throw DL_ABORT_EX("Failed to parse command-line options."); } out << op->getName() << "="; @@ -390,7 +390,7 @@ SharedHandle OptionParser::optionParser_; const SharedHandle& OptionParser::getInstance() { - if(optionParser_.isNull()) { + if(!optionParser_) { optionParser_.reset(new OptionParser()); optionParser_->setOptionHandlers(OptionHandlerFactory::createOptionHandlers()); } diff --git a/src/PStringBuildVisitor.cc b/src/PStringBuildVisitor.cc index 68c57671..0c06c470 100644 --- a/src/PStringBuildVisitor.cc +++ b/src/PStringBuildVisitor.cc @@ -54,7 +54,7 @@ void PStringBuildVisitor::visit(PStringSegment& segment) uris_.push_back(uri); } - if(!segment.getNext().isNull()) { + if(segment.getNext()) { segment.getNext()->accept(*this); } diff --git a/src/PStringSegment.cc b/src/PStringSegment.cc index a08df34f..6dfedb9f 100644 --- a/src/PStringSegment.cc +++ b/src/PStringSegment.cc @@ -58,7 +58,7 @@ const std::string& PStringSegment::getValue() const bool PStringSegment::hasNext() const { - return !next_.isNull(); + return next_; } SharedHandle PStringSegment::getNext() const diff --git a/src/Peer.cc b/src/Peer.cc index 4451bdad..74c97f1b 100644 --- a/src/Peer.cc +++ b/src/Peer.cc @@ -404,7 +404,7 @@ void Peer::setFirstContactTime(const Timer& time) firstContactTime_ = time; } -void Peer::setBtMessageDispatcher(const WeakHandle& dpt) +void Peer::setBtMessageDispatcher(BtMessageDispatcher* dpt) { assert(res_); res_->setBtMessageDispatcher(dpt); diff --git a/src/Peer.h b/src/Peer.h index 99bf9ab4..92fff8a8 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -322,7 +322,7 @@ public: disconnectedGracefully_ = f; } - void setBtMessageDispatcher(const WeakHandle& dpt); + void setBtMessageDispatcher(BtMessageDispatcher* dpt); size_t countOutstandingUpload() const; }; diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index ef6a2af2..8ab45138 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -68,7 +68,7 @@ PeerAbstractCommand::PeerAbstractCommand(cuid_t cuid, checkSocketIsWritable_(false), noCheck_(false) { - if(!socket_.isNull() && socket_->isOpen()) { + if(socket_ && socket_->isOpen()) { setReadCheckSocket(socket_); } } diff --git a/src/PeerConnection.h b/src/PeerConnection.h index d632f35e..31636e97 100644 --- a/src/PeerConnection.h +++ b/src/PeerConnection.h @@ -128,7 +128,6 @@ public: }; typedef SharedHandle PeerConnectionHandle; -typedef WeakHandle PeerConnectionWeakHandle; } // namespace aria2 diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 31c8f57a..2c39f7c8 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -138,7 +138,7 @@ PeerInteractionCommand::PeerInteractionCommand extensionMessageFactory->setDownloadContext (requestGroup_->getDownloadContext()); extensionMessageFactory->setUTMetadataRequestTracker - (utMetadataRequestTracker); + (utMetadataRequestTracker.get()); // PieceStorage will be set later. SharedHandle factory(new DefaultBtMessageFactory()); @@ -149,22 +149,22 @@ PeerInteractionCommand::PeerInteractionCommand factory->setExtensionMessageFactory(extensionMessageFactory); factory->setPeer(getPeer()); if(family == AF_INET) { - factory->setLocalNode(DHTRegistry::getData().localNode); - factory->setRoutingTable(DHTRegistry::getData().routingTable); - factory->setTaskQueue(DHTRegistry::getData().taskQueue); - factory->setTaskFactory(DHTRegistry::getData().taskFactory); + factory->setLocalNode(DHTRegistry::getData().localNode.get()); + factory->setRoutingTable(DHTRegistry::getData().routingTable.get()); + factory->setTaskQueue(DHTRegistry::getData().taskQueue.get()); + factory->setTaskFactory(DHTRegistry::getData().taskFactory.get()); } else { - factory->setLocalNode(DHTRegistry::getData6().localNode); - factory->setRoutingTable(DHTRegistry::getData6().routingTable); - factory->setTaskQueue(DHTRegistry::getData6().taskQueue); - factory->setTaskFactory(DHTRegistry::getData6().taskFactory); + factory->setLocalNode(DHTRegistry::getData6().localNode.get()); + factory->setRoutingTable(DHTRegistry::getData6().routingTable.get()); + factory->setTaskQueue(DHTRegistry::getData6().taskQueue.get()); + factory->setTaskFactory(DHTRegistry::getData6().taskFactory.get()); } if(metadataGetMode) { factory->enableMetadataGetMode(); } PeerConnectionHandle peerConnection; - if(passedPeerConnection.isNull()) { + if(!passedPeerConnection) { peerConnection.reset(new PeerConnection(cuid, getPeer(), getSocket())); } else { peerConnection = passedPeerConnection; @@ -178,21 +178,22 @@ PeerInteractionCommand::PeerInteractionCommand dispatcher->setPieceStorage(pieceStorage); dispatcher->setPeerStorage(peerStorage); dispatcher->setRequestTimeout(getOption()->getAsInt(PREF_BT_REQUEST_TIMEOUT)); - dispatcher->setBtMessageFactory(factory); - dispatcher->setRequestGroupMan(getDownloadEngine()->getRequestGroupMan()); + dispatcher->setBtMessageFactory(factory.get()); + dispatcher->setRequestGroupMan + (getDownloadEngine()->getRequestGroupMan().get()); DefaultBtMessageReceiverHandle receiver(new DefaultBtMessageReceiver()); receiver->setDownloadContext(requestGroup_->getDownloadContext()); - receiver->setPeerConnection(peerConnection); - receiver->setDispatcher(dispatcher); - receiver->setBtMessageFactory(factory); + receiver->setPeerConnection(peerConnection.get()); + receiver->setDispatcher(dispatcher.get()); + receiver->setBtMessageFactory(factory.get()); SharedHandle reqFactory (new DefaultBtRequestFactory()); reqFactory->setPeer(getPeer()); reqFactory->setPieceStorage(pieceStorage); - reqFactory->setBtMessageDispatcher(dispatcher); - reqFactory->setBtMessageFactory(factory); + reqFactory->setBtMessageDispatcher(dispatcher.get()); + reqFactory->setBtMessageFactory(factory.get()); DefaultBtInteractiveHandle btInteractive (new DefaultBtInteractive(requestGroup_->getDownloadContext(), getPeer())); @@ -208,7 +209,8 @@ PeerInteractionCommand::PeerInteractionCommand btInteractive->setExtensionMessageRegistry(exMsgRegistry); btInteractive->setKeepAliveInterval (getOption()->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL)); - btInteractive->setRequestGroupMan(getDownloadEngine()->getRequestGroupMan()); + btInteractive->setRequestGroupMan + (getDownloadEngine()->getRequestGroupMan().get()); btInteractive->setBtMessageFactory(factory); if((metadataGetMode || !torrentAttrs->privateTorrent) && !getPeer()->isLocalPeer()) { @@ -219,13 +221,13 @@ PeerInteractionCommand::PeerInteractionCommand if(DHTRegistry::isInitialized()) { btInteractive->setDHTEnabled(true); factory->setDHTEnabled(true); - btInteractive->setLocalNode(DHTRegistry::getData().localNode); + btInteractive->setLocalNode(DHTRegistry::getData().localNode.get()); } } else { if(DHTRegistry::isInitialized6()) { btInteractive->setDHTEnabled(true); factory->setDHTEnabled(true); - btInteractive->setLocalNode(DHTRegistry::getData6().localNode); + btInteractive->setLocalNode(DHTRegistry::getData6().localNode.get()); } } } @@ -238,27 +240,27 @@ PeerInteractionCommand::PeerInteractionCommand btInteractive_ = btInteractive; // reverse depends - factory->setBtMessageDispatcher(dispatcher); - factory->setBtRequestFactory(reqFactory); - factory->setPeerConnection(peerConnection); + factory->setBtMessageDispatcher(dispatcher.get()); + factory->setBtRequestFactory(reqFactory.get()); + factory->setPeerConnection(peerConnection.get()); - extensionMessageFactory->setBtMessageDispatcher(dispatcher); - extensionMessageFactory->setBtMessageFactory(factory); + extensionMessageFactory->setBtMessageDispatcher(dispatcher.get()); + extensionMessageFactory->setBtMessageFactory(factory.get()); if(metadataGetMode) { utMetadataRequestFactory->setDownloadContext (requestGroup_->getDownloadContext()); - utMetadataRequestFactory->setBtMessageDispatcher(dispatcher); - utMetadataRequestFactory->setBtMessageFactory(factory); + utMetadataRequestFactory->setBtMessageDispatcher(dispatcher.get()); + utMetadataRequestFactory->setBtMessageFactory(factory.get()); utMetadataRequestFactory->setPeer(getPeer()); utMetadataRequestFactory->setUTMetadataRequestTracker - (utMetadataRequestTracker); + (utMetadataRequestTracker.get()); } getPeer()->allocateSessionResource (requestGroup_->getDownloadContext()->getPieceLength(), requestGroup_->getDownloadContext()->getTotalLength()); - getPeer()->setBtMessageDispatcher(dispatcher); + getPeer()->setBtMessageDispatcher(dispatcher.get()); btRuntime_->increaseConnections(); requestGroup_->increaseNumCommand(); @@ -297,7 +299,7 @@ bool PeerInteractionCommand::executeInternal() { } } BtMessageHandle handshakeMessage = btInteractive_->receiveHandshake(); - if(handshakeMessage.isNull()) { + if(!handshakeMessage) { break; } btInteractive_->doPostHandshakeProcessing(); @@ -306,7 +308,7 @@ bool PeerInteractionCommand::executeInternal() { } case RECEIVER_WAIT_HANDSHAKE: { BtMessageHandle handshakeMessage =btInteractive_->receiveAndSendHandshake(); - if(handshakeMessage.isNull()) { + if(!handshakeMessage) { break; } btInteractive_->doPostHandshakeProcessing(); diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index a3a56bb4..ab8e16b7 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -107,7 +107,7 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) uint16_t PeerListenCommand::getPort() const { - if(socket_.isNull()) { + if(!socket_) { return 0; } else { std::pair addr; diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc index a6886009..0d1bfef5 100644 --- a/src/PeerReceiveHandshakeCommand.cc +++ b/src/PeerReceiveHandshakeCommand.cc @@ -72,7 +72,7 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand PeerAbstractCommand(cuid, peer, e, s), peerConnection_(peerConnection) { - if(peerConnection_.isNull()) { + if(!peerConnection_) { peerConnection_.reset(new PeerConnection(cuid, getPeer(), getSocket())); } } @@ -99,7 +99,7 @@ bool PeerReceiveHandshakeCommand::executeInternal() SharedHandle downloadContext = getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash); - if(downloadContext.isNull()) { + if(!downloadContext) { throw DL_ABORT_EX (StringFormat("Unknown info hash %s", util::toHex(infoHash).c_str()).str()); diff --git a/src/PeerSessionResource.cc b/src/PeerSessionResource.cc index 429e57a4..f8141d33 100644 --- a/src/PeerSessionResource.cc +++ b/src/PeerSessionResource.cc @@ -57,7 +57,8 @@ PeerSessionResource::PeerSessionResource(size_t pieceLength, uint64_t totalLengt extendedMessagingEnabled_(false), dhtEnabled_(false), lastDownloadUpdate_(0), - lastAmUnchoking_(0) + lastAmUnchoking_(0), + dispatcher_(0) {} PeerSessionResource::~PeerSessionResource() @@ -263,15 +264,14 @@ uint64_t PeerSessionResource::getCompletedLength() const return bitfieldMan_->getCompletedLength(); } -void PeerSessionResource::setBtMessageDispatcher -(const WeakHandle& dpt) +void PeerSessionResource::setBtMessageDispatcher(BtMessageDispatcher* dpt) { dispatcher_ = dpt; } size_t PeerSessionResource::countOutstandingUpload() const { - assert(!dispatcher_.isNull()); + assert(dispatcher_); return dispatcher_->countOutstandingUpload(); } diff --git a/src/PeerSessionResource.h b/src/PeerSessionResource.h index 7e677ecb..fecd23fd 100644 --- a/src/PeerSessionResource.h +++ b/src/PeerSessionResource.h @@ -81,7 +81,7 @@ private: Timer lastAmUnchoking_; - WeakHandle dispatcher_; + BtMessageDispatcher* dispatcher_; public: PeerSessionResource(size_t pieceLength, uint64_t totalLength); @@ -230,7 +230,7 @@ public: uint64_t getCompletedLength() const; - void setBtMessageDispatcher(const WeakHandle& dpt); + void setBtMessageDispatcher(BtMessageDispatcher* dpt); size_t countOutstandingUpload() const; }; diff --git a/src/Piece.cc b/src/Piece.cc index c4e7f770..c7fe2c06 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -200,7 +200,7 @@ bool Piece::updateHash return false; } if(begin == nextBegin_ && nextBegin_+dataLength <= length_) { - if(mdctx_.isNull()) { + if(!mdctx_) { mdctx_ = MessageDigest::create(hashAlgo_); } mdctx_->update(data, dataLength); @@ -213,12 +213,12 @@ bool Piece::updateHash bool Piece::isHashCalculated() const { - return !mdctx_.isNull() && nextBegin_ == length_; + return mdctx_ && nextBegin_ == length_; } std::string Piece::getHashString() { - if(mdctx_.isNull()) { + if(!mdctx_) { return A2STR::NIL; } else { std::string hash = mdctx_->hexDigest(); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index e25d3e52..34d14987 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -141,6 +141,10 @@ RequestGroup::RequestGroup(const SharedHandle