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

Removed SharedHandle::isNull(). Instead we added operator* and
	operator unspecified_bool_type. Removed use of WeakHandle and
	replaced with raw pointer.
This commit is contained in:
Tatsuhiro Tsujikawa 2010-11-12 12:48:48 +00:00
parent f6f5a7e5ee
commit 93e5dbed32
181 changed files with 911 additions and 876 deletions

View file

@ -1,3 +1,9 @@
2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net>
Fixed memory leak

View file

@ -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>& 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<BtMessageDispatcher>& dispatcher)
void AbstractBtMessage::setBtMessageDispatcher(BtMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void AbstractBtMessage::setPeerConnection(const WeakHandle<PeerConnection>& peerConnection)
void AbstractBtMessage::setPeerConnection(PeerConnection* peerConnection)
{
peerConnection_ = peerConnection;
}
void AbstractBtMessage::setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory)
void AbstractBtMessage::setBtMessageFactory(BtMessageFactory* factory)
{
messageFactory_ = factory;
}
void AbstractBtMessage::setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory)
void AbstractBtMessage::setBtRequestFactory(BtRequestFactory* factory)
{
requestFactory_ = factory;
}

View file

@ -62,13 +62,13 @@ private:
SharedHandle<Peer> peer_;
WeakHandle<BtMessageDispatcher> dispatcher_;
BtMessageDispatcher* dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_;
BtMessageFactory* messageFactory_;
WeakHandle<BtRequestFactory> requestFactory_;
BtRequestFactory* requestFactory_;
WeakHandle<PeerConnection> peerConnection_;
PeerConnection* peerConnection_;
SharedHandle<BtMessageValidator> validator_;
@ -86,22 +86,22 @@ protected:
return pieceStorage_;
}
const WeakHandle<PeerConnection>& getPeerConnection() const
PeerConnection* getPeerConnection() const
{
return peerConnection_;
}
const WeakHandle<BtMessageDispatcher>& getBtMessageDispatcher() const
BtMessageDispatcher* getBtMessageDispatcher() const
{
return dispatcher_;
}
const WeakHandle<BtRequestFactory>& getBtRequestFactory() const
BtRequestFactory* getBtRequestFactory() const
{
return requestFactory_;
}
const WeakHandle<BtMessageFactory>& getBtMessageFactory() const
BtMessageFactory* getBtMessageFactory() const
{
return messageFactory_;
}
@ -172,14 +172,13 @@ public:
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
void setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection);
void setPeerConnection(PeerConnection* peerConnection);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
void setBtMessageFactory(BtMessageFactory* factory);
void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory);
void setBtRequestFactory(BtRequestFactory* factory);
const std::string& getName() const
{

View file

@ -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<Request> 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> 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<Request> 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<std::string>& AbstractCommand::getResolvedAddresses()
void AbstractCommand::setNameResolverCheck
(const SharedHandle<AsyncNameResolver>& resolver) {
if(!resolver.isNull()) {
if(resolver) {
nameResolverCheck_ = true;
e_->addNameResolverCheck(resolver, this);
}
@ -717,7 +717,7 @@ void AbstractCommand::setNameResolverCheck
void AbstractCommand::disableNameResolverCheck
(const SharedHandle<AsyncNameResolver>& 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);

View file

@ -68,7 +68,7 @@ AbstractProxyResponseCommand::~AbstractProxyResponseCommand() {}
bool AbstractProxyResponseCommand::executeInternal() {
SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(httpResponse.isNull()) {
if(!httpResponse) {
// the server has not responded our request yet.
getDownloadEngine()->addCommand(this);
return false;

View file

@ -135,7 +135,7 @@ bool ActivePeerConnectionCommand::execute() {
void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
{
if(peer.isNull()) {
if(!peer) {
return;
}
peer->usedBy(e_->newCUID());

View file

@ -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();

View file

@ -66,7 +66,7 @@ public:
virtual off_t getCurrentLength()
{
if(allocator_.isNull()) {
if(!allocator_) {
return offset_;
} else {
return allocator_->getCurrentLength();

View file

@ -266,7 +266,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull())
if(!ss)
continue;
if((int)ss->getSingleConnectionAvgSpeed() > max) {
@ -288,7 +288,7 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> 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<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull())
if(!ss)
return *i;
}
return A2STR::NIL;
@ -327,7 +327,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> 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<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
if(ss.isNull())
if(!ss)
++counter;
}
return uris.size() - counter;

View file

@ -97,7 +97,7 @@ AuthConfigFactory::createAuthConfig
SharedHandle<AuthConfig> 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> authConfig =
createHttpAuthResolver(op)->resolveAuthConfig(host);
if(authConfig.isNull()) {
if(!authConfig) {
return false;
} else {
BasicCred bc(authConfig->getUser(), authConfig->getPassword(),

View file

@ -78,7 +78,7 @@ void BNode::setBucket(const SharedHandle<DHTBucket>& 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<SharedHandle<DHTNode> >& nodes,
visited.push_back(bnode);
{
SharedHandle<DHTBucket> bucket = bnode->getBucket();
if(!bucket.isNull()) {
if(bucket) {
std::vector<SharedHandle<DHTNode> > goodNodes;
bucket->getGoodNodes(goodNodes);
size_t r = DHTBucket::K-nodes.size();
@ -187,7 +187,7 @@ void BNode::enumerateBucket(std::vector<SharedHandle<DHTBucket> >& 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()) {

View file

@ -51,7 +51,7 @@
namespace aria2 {
BtDependency::BtDependency(const WeakHandle<RequestGroup>& dependant,
BtDependency::BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee):
dependant_(dependant),
dependee_(dependee),

View file

@ -46,11 +46,11 @@ class Logger;
class BtDependency : public Dependency
{
private:
WeakHandle<RequestGroup> dependant_;
RequestGroup* dependant_;
SharedHandle<RequestGroup> dependee_;
Logger* logger_;
public:
BtDependency(const WeakHandle<RequestGroup>& dependant,
BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee);
virtual ~BtDependency();

View file

@ -99,7 +99,7 @@ BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& 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<ExtensionMessageFactory>& factory,
void BtExtendedMessage::doReceivedAction()
{
if(!extensionMessage_.isNull()) {
if(extensionMessage_) {
extensionMessage_->doReceivedAction();
}
}

View file

@ -88,7 +88,6 @@ public:
};
typedef SharedHandle<BtMessageDispatcher> BtMessageDispatcherHandle;
typedef WeakHandle<BtMessageDispatcher> BtMessageDispatcherWeakHandle;
} // namespace aria2

View file

@ -98,7 +98,6 @@ public:
};
typedef SharedHandle<BtMessageFactory> BtMessageFactoryHandle;
typedef WeakHandle<BtMessageFactory> BtMessageFactoryWeakHandle;
} // namespace aria2

View file

@ -55,7 +55,6 @@ public:
};
typedef SharedHandle<BtMessageReceiver> BtMessageReceiverHandle;
typedef WeakHandle<BtMessageReceiver> BtMessageReceiverWeakHandle;
} // namespace aria2

View file

@ -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> BtPortMessage::create
(const unsigned char* data, size_t dataLength)
@ -66,7 +71,7 @@ SharedHandle<BtPortMessage> 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<DHTNode>& localNode)
void BtPortMessage::setLocalNode(DHTNode* localNode)
{
localNode_ = localNode;
}
void BtPortMessage::setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable)
void BtPortMessage::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}
void BtPortMessage::setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue)
void BtPortMessage::setTaskQueue(DHTTaskQueue* taskQueue)
{
taskQueue_ = taskQueue;
}
void BtPortMessage::setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory)
void BtPortMessage::setTaskFactory(DHTTaskFactory* taskFactory)
{
taskFactory_ = taskFactory;
}

View file

@ -49,13 +49,13 @@ private:
uint16_t port_;
static const size_t MESSAGE_LENGTH = 7;
WeakHandle<DHTNode> localNode_;
DHTNode* localNode_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTRoutingTable* routingTable_;
WeakHandle<DHTTaskQueue> taskQueue_;
DHTTaskQueue* taskQueue_;
WeakHandle<DHTTaskFactory> taskFactory_;
DHTTaskFactory* taskFactory_;
public:
BtPortMessage(uint16_t port);
@ -76,13 +76,13 @@ public:
virtual std::string toString() const;
void setLocalNode(const WeakHandle<DHTNode>& localNode);
void setLocalNode(DHTNode* localNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue);
void setTaskQueue(DHTTaskQueue* taskQueue);
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory);
void setTaskFactory(DHTTaskFactory* taskFactory);
};
} // namespace aria2

View file

@ -84,7 +84,7 @@ void BtPostDownloadHandler::getNextRequestGroups
requestGroup->followedBy(newRgs.begin(), newRgs.end());
SharedHandle<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext());
if(!mi.isNull()) {
if(mi) {
setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
}
groups.insert(groups.end(), newRgs.begin(), newRgs.end());

View file

@ -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_;
}
};

View file

@ -88,7 +88,6 @@ public:
};
typedef SharedHandle<BtRequestFactory> BtRequestFactoryHandle;
typedef WeakHandle<BtRequestFactory> BtRequestFactoryWeakHandle;
} // namespace aria2

View file

@ -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();

View file

@ -121,7 +121,7 @@ void printProgress
#ifdef ENABLE_BITTORRENT
SharedHandle<PeerStorage> ps =
e->getBtRegistry()->get(rg->getGID()).peerStorage_;
if(!ps.isNull()) {
if(ps) {
std::vector<SharedHandle<Peer> > peers;
ps->getActivePeers(peers);
o << " " << "SEED:"
@ -280,7 +280,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
{
SharedHandle<FileAllocationEntry> entry =
e->getFileAllocationMan()->getPickedEntry();
if(!entry.isNull()) {
if(entry) {
o << " "
<< "[FileAlloc:"
<< "#" << entry->getRequestGroup()->getGID() << " "
@ -308,7 +308,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
{
SharedHandle<CheckIntegrityEntry> entry =
e->getCheckIntegrityMan()->getPickedEntry();
if(!entry.isNull()) {
if(entry) {
o << " "
<< "[Checksum:"
<< "#" << entry->getRequestGroup()->getGID() << " "

View file

@ -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.");

View file

@ -49,7 +49,12 @@ namespace aria2 {
DHTAbstractMessage::DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& 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<ssize_t>(message.size());
}
void DHTAbstractMessage::setConnection
(const WeakHandle<DHTConnection>& connection)
void DHTAbstractMessage::setConnection(DHTConnection* connection)
{
connection_ = connection;
}
void DHTAbstractMessage::setMessageDispatcher
(const WeakHandle<DHTMessageDispatcher>& dispatcher)
void DHTAbstractMessage::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DHTAbstractMessage::setMessageFactory
(const WeakHandle<DHTMessageFactory>& factory)
void DHTAbstractMessage::setMessageFactory(DHTMessageFactory* factory)
{
factory_ = factory;
}
void DHTAbstractMessage::setRoutingTable
(const WeakHandle<DHTRoutingTable>& routingTable)
void DHTAbstractMessage::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}

View file

@ -48,13 +48,13 @@ class DHTRoutingTable;
class DHTAbstractMessage:public DHTMessage {
private:
WeakHandle<DHTConnection> connection_;
DHTConnection* connection_;
WeakHandle<DHTMessageDispatcher> dispatcher_;
DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_;
DHTMessageFactory* factory_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTRoutingTable* routingTable_;
public:
DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
@ -70,33 +70,33 @@ public:
std::string getBencodedMessage();
const WeakHandle<DHTConnection>& getConnection() const
DHTConnection* getConnection() const
{
return connection_;
}
void setConnection(const WeakHandle<DHTConnection>& connection);
void setConnection(DHTConnection* connection);
const WeakHandle<DHTMessageDispatcher>& getMessageDispatcher() const
DHTMessageDispatcher* getMessageDispatcher() const
{
return dispatcher_;
}
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher);
void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
const WeakHandle<DHTMessageFactory>& getMessageFactory() const
DHTMessageFactory* getMessageFactory() const
{
return factory_;
}
void setMessageFactory(const WeakHandle<DHTMessageFactory>& factory);
void setMessageFactory(DHTMessageFactory* factory);
const WeakHandle<DHTRoutingTable>& getRoutingTable() const
DHTRoutingTable* getRoutingTable() const
{
return routingTable_;
}
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
};
} // namespace aria2

View file

@ -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<DHTRoutingTable> routingTable)
void DHTAbstractTask::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}
void DHTAbstractTask::setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher)
void DHTAbstractTask::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DHTAbstractTask::setMessageFactory(const WeakHandle<DHTMessageFactory> factory)
void DHTAbstractTask::setMessageFactory(DHTMessageFactory* factory)
{
factory_ = factory;
}
void DHTAbstractTask::setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue)
void DHTAbstractTask::setTaskQueue(DHTTaskQueue* taskQueue)
{
taskQueue_ = taskQueue;
}

View file

@ -58,13 +58,13 @@ private:
SharedHandle<DHTNode> localNode_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTRoutingTable* routingTable_;
WeakHandle<DHTMessageDispatcher> dispatcher_;
DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_;
DHTMessageFactory* factory_;
WeakHandle<DHTTaskQueue> taskQueue_;
DHTTaskQueue* taskQueue_;
protected:
void setFinished(bool f)
{
@ -80,33 +80,33 @@ public:
virtual bool finished();
const WeakHandle<DHTRoutingTable>& getRoutingTable() const
DHTRoutingTable* getRoutingTable() const
{
return routingTable_;
}
void setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
const WeakHandle<DHTMessageDispatcher>& getMessageDispatcher() const
DHTMessageDispatcher* getMessageDispatcher() const
{
return dispatcher_;
}
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher);
void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
const WeakHandle<DHTMessageFactory>& getMessageFactory() const
DHTMessageFactory* getMessageFactory() const
{
return factory_;
}
void setMessageFactory(const WeakHandle<DHTMessageFactory> factory);
void setMessageFactory(DHTMessageFactory* factory);
const WeakHandle<DHTTaskQueue>& getTaskQueue() const
DHTTaskQueue* getTaskQueue() const
{
return taskQueue_;
}
void setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue);
void setTaskQueue(DHTTaskQueue* taskQueue);
const SharedHandle<DHTNode>& getLocalNode() const
{

View file

@ -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<DHTPeerAnnounceStorage>& storage)
(DHTPeerAnnounceStorage* storage)
{
peerAnnounceStorage_ = storage;
}
void DHTAnnouncePeerMessage::setTokenTracker
(const WeakHandle<DHTTokenTracker>& tokenTracker)
void DHTAnnouncePeerMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
{
tokenTracker_ = tokenTracker;
}

View file

@ -52,9 +52,9 @@ private:
uint16_t tcpPort_;
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_;
DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> tokenTracker_;
DHTTokenTracker* tokenTracker_;
protected:
virtual std::string toStringOptional() const;
public:
@ -90,9 +90,9 @@ public:
return tcpPort_;
}
void setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
void setTokenTracker(DHTTokenTracker* tokenTracker);
static const std::string ANNOUNCE_PEER;

View file

@ -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;

View file

@ -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_;

View file

@ -56,7 +56,9 @@ DHTGetPeersMessage::DHTGetPeersMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& 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<DHTPeerAnnounceStorage>& storage)
void DHTGetPeersMessage::setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage)
{
peerAnnounceStorage_ = storage;
}
void DHTGetPeersMessage::setTokenTracker
(const WeakHandle<DHTTokenTracker>& tokenTracker)
void DHTGetPeersMessage::setTokenTracker(DHTTokenTracker* tokenTracker)
{
tokenTracker_ = tokenTracker;
}

View file

@ -48,9 +48,9 @@ class DHTGetPeersMessage:public DHTQueryMessage {
private:
unsigned char infoHash_[DHT_ID_LENGTH];
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_;
DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> tokenTracker_;
DHTTokenTracker* tokenTracker_;
protected:
virtual std::string toStringOptional() const;
public:
@ -72,10 +72,9 @@ public:
return infoHash_;
}
void setPeerAnnounceStorage
(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
void setTokenTracker(DHTTokenTracker* tokenTracker);
static const std::string GET_PEERS;

View file

@ -82,7 +82,7 @@ bool DHTInteractionCommand::execute()
for(size_t i = 0; i < 20; ++i) {
SharedHandle<DHTMessage> m = receiver_->receiveMessage();
if(m.isNull()) {
if(!m) {
break;
}
}

View file

@ -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<DHTNode> 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<DHTMessageFactory> factory(this);
m->setMessageFactory(factory);
m->setMessageFactory(this);
m->setVersion(getDefaultVersion());
}
@ -506,32 +510,29 @@ DHTMessageFactoryImpl::createUnknownMessage
return m;
}
void DHTMessageFactoryImpl::setRoutingTable
(const WeakHandle<DHTRoutingTable>& routingTable)
void DHTMessageFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}
void DHTMessageFactoryImpl::setConnection
(const WeakHandle<DHTConnection>& connection)
void DHTMessageFactoryImpl::setConnection(DHTConnection* connection)
{
connection_ = connection;
}
void DHTMessageFactoryImpl::setMessageDispatcher
(const WeakHandle<DHTMessageDispatcher>& dispatcher)
(DHTMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DHTMessageFactoryImpl::setPeerAnnounceStorage
(const WeakHandle<DHTPeerAnnounceStorage>& storage)
(DHTPeerAnnounceStorage* storage)
{
peerAnnounceStorage_ = storage;
}
void DHTMessageFactoryImpl::setTokenTracker
(const WeakHandle<DHTTokenTracker>& tokenTracker)
void DHTMessageFactoryImpl::setTokenTracker(DHTTokenTracker* tokenTracker)
{
tokenTracker_ = tokenTracker;
}

View file

@ -55,15 +55,15 @@ private:
SharedHandle<DHTNode> localNode_;
WeakHandle<DHTConnection> connection_;
DHTConnection* connection_;
WeakHandle<DHTMessageDispatcher> dispatcher_;
DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTRoutingTable* routingTable_;
WeakHandle<DHTPeerAnnounceStorage> peerAnnounceStorage_;
DHTPeerAnnounceStorage* peerAnnounceStorage_;
WeakHandle<DHTTokenTracker> 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<DHTRoutingTable>& routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
void setConnection(const WeakHandle<DHTConnection>& connection);
void setConnection(DHTConnection* connection);
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher);
void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
void setPeerAnnounceStorage
(const WeakHandle<DHTPeerAnnounceStorage>& storage);
void setPeerAnnounceStorage(DHTPeerAnnounceStorage* storage);
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
void setTokenTracker(DHTTokenTracker* tokenTracker);
void setLocalNode(const SharedHandle<DHTNode>& localNode);
};

View file

@ -97,12 +97,12 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
std::pair<SharedHandle<DHTResponseMessage>,
SharedHandle<DHTMessageCallback> > 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;

View file

@ -129,7 +129,7 @@ void DHTMessageTracker::handleTimeoutEntry
routingTable_->dropNode(node);
}
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
if(!callback.isNull()) {
if(callback) {
callback->onTimeout(node);
}
} catch(RecoverableException& e) {

View file

@ -41,7 +41,7 @@ DHTNodeLookupEntry::DHTNodeLookupEntry(const SharedHandle<DHTNode>& node):
node(node), used(false) {}
DHTNodeLookupEntry::DHTNodeLookupEntry():
node(0), used(false) {}
used(false) {}
bool DHTNodeLookupEntry::operator==(const DHTNodeLookupEntry& entry) const
{

View file

@ -62,7 +62,7 @@ void DHTReplaceNodeTask::startup()
void DHTReplaceNodeTask::sendMessage()
{
SharedHandle<DHTNode> questionableNode = bucket_->getLRUQuestionableNode();
if(questionableNode.isNull()) {
if(!questionableNode) {
setFinished(true);
} else {
SharedHandle<DHTMessage> m =

View file

@ -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

View file

@ -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<DHTAbstractTask>&
task->setLocalNode(localNode_);
}
void DHTTaskFactoryImpl::setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable)
void DHTTaskFactoryImpl::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}
void DHTTaskFactoryImpl::setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher)
void DHTTaskFactoryImpl::setMessageDispatcher(DHTMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DHTTaskFactoryImpl::setMessageFactory(const WeakHandle<DHTMessageFactory> factory)
void DHTTaskFactoryImpl::setMessageFactory(DHTMessageFactory* factory)
{
factory_ = factory;
}
void DHTTaskFactoryImpl::setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue)
void DHTTaskFactoryImpl::setTaskQueue(DHTTaskQueue* taskQueue)
{
taskQueue_ = taskQueue;
}

View file

@ -52,13 +52,13 @@ class DHTTaskFactoryImpl:public DHTTaskFactory {
private:
SharedHandle<DHTNode> localNode_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTRoutingTable* routingTable_;
WeakHandle<DHTMessageDispatcher> dispatcher_;
DHTMessageDispatcher* dispatcher_;
WeakHandle<DHTMessageFactory> factory_;
DHTMessageFactory* factory_;
WeakHandle<DHTTaskQueue> taskQueue_;
DHTTaskQueue* taskQueue_;
time_t timeout_;
@ -91,13 +91,13 @@ public:
createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
const SharedHandle<DHTNode>& newNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable> routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher> dispatcher);
void setMessageDispatcher(DHTMessageDispatcher* dispatcher);
void setMessageFactory(const WeakHandle<DHTMessageFactory> factory);
void setMessageFactory(DHTMessageFactory* factory);
void setTaskQueue(const WeakHandle<DHTTaskQueue> taskQueue);
void setTaskQueue(DHTTaskQueue* taskQueue);
void setLocalNode(const SharedHandle<DHTNode>& localNode);

View file

@ -40,7 +40,7 @@ namespace aria2 {
AuthConfigHandle DefaultAuthResolver::resolveAuthConfig
(const std::string& hostname)
{
if(getUserDefinedAuthConfig().isNull()) {
if(!getUserDefinedAuthConfig()) {
return getDefaultAuthConfig();
} else {
return getUserDefinedAuthConfig();

View file

@ -276,7 +276,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
}
}
const SharedHandle<ValueBase>& 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<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
if(peer6Data.isNull()) {
if(!peer6Data) {
logger_->info("No peers6 received.");
} else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {

View file

@ -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<BtHandshakeMessage> message =
btMessageReceiver_->receiveHandshake(quickReply);
if(message.isNull()) {
if(!message) {
return SharedHandle<BtMessage>();
}
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<DHTNode>& node)
void DefaultBtInteractive::setLocalNode(DHTNode* node)
{
localNode_ = node;
}
@ -657,8 +659,7 @@ void DefaultBtInteractive::setBtMessageFactory
messageFactory_ = factory;
}
void DefaultBtInteractive::setRequestGroupMan
(const WeakHandle<RequestGroupMan>& rgman)
void DefaultBtInteractive::setRequestGroupMan(RequestGroupMan* rgman)
{
requestGroupMan_ = rgman;
}

View file

@ -124,7 +124,7 @@ private:
bool metadataGetMode_;
WeakHandle<DHTNode> localNode_;
DHTNode* localNode_;
Logger* logger_;
size_t allowedFastSetSize_;
@ -143,7 +143,7 @@ private:
size_t maxOutstandingRequest_;
WeakHandle<RequestGroupMan> requestGroupMan_;
RequestGroupMan* requestGroupMan_;
static const time_t FLOODING_CHECK_INTERVAL = 5;
@ -232,14 +232,14 @@ public:
utPexEnabled_ = f;
}
void setLocalNode(const WeakHandle<DHTNode>& node);
void setLocalNode(DHTNode* node);
void setDHTEnabled(bool f)
{
dhtEnabled_ = f;
}
void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman);
void setRequestGroupMan(RequestGroupMan* rgman);
void setUTMetadataRequestTracker
(const SharedHandle<UTMetadataRequestTracker>& tracker)

View file

@ -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> peer_;
SharedHandle<PieceStorage> pieceStorage_;
BtMessageDispatcher* messageDispatcher_;
WeakHandle<BtMessageFactory> messageFactory_;
BtMessageFactory* messageFactory_;
time_t requestTimeout_;
Logger* logger_;
public:
ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer,
const SharedHandle<PieceStorage>& pieceStorage,
BtMessageDispatcher* dispatcher,
const WeakHandle<BtMessageFactory>& factory,
BtMessageFactory* factory,
time_t requestTimeout):
cuid_(cuid),
peer_(peer),
@ -453,14 +455,12 @@ void DefaultBtMessageDispatcher::setPeerStorage
peerStorage_ = peerStorage;
}
void DefaultBtMessageDispatcher::setBtMessageFactory
(const WeakHandle<BtMessageFactory>& factory)
void DefaultBtMessageDispatcher::setBtMessageFactory(BtMessageFactory* factory)
{
messageFactory_ = factory;
}
void DefaultBtMessageDispatcher::setRequestGroupMan
(const WeakHandle<RequestGroupMan>& rgman)
void DefaultBtMessageDispatcher::setRequestGroupMan(RequestGroupMan* rgman)
{
requestGroupMan_ = rgman;
}

View file

@ -62,9 +62,9 @@ private:
SharedHandle<DownloadContext> downloadContext_;
SharedHandle<PeerStorage> peerStorage_;
SharedHandle<PieceStorage> pieceStorage_;
WeakHandle<BtMessageFactory> messageFactory_;
BtMessageFactory* messageFactory_;
SharedHandle<Peer> peer_;
WeakHandle<RequestGroupMan> requestGroupMan_;
RequestGroupMan* requestGroupMan_;
time_t requestTimeout_;
Logger* logger_;
public:
@ -130,9 +130,9 @@ public:
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
void setBtMessageFactory(BtMessageFactory* factory);
void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman);
void setRequestGroupMan(RequestGroupMan* rgman);
void setCuid(cuid_t cuid)
{

View file

@ -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<BtMessageFactory>(this));
msg->setBtMessageFactory(this);
msg->setPeerConnection(peerConnection_);
if(metadataGetMode_) {
msg->enableMetadataGetMode();
@ -460,14 +468,12 @@ DefaultBtMessageFactory::createBtExtendedMessage
return m;
}
void DefaultBtMessageFactory::setTaskQueue
(const WeakHandle<DHTTaskQueue>& taskQueue)
void DefaultBtMessageFactory::setTaskQueue(DHTTaskQueue* taskQueue)
{
taskQueue_ = taskQueue;
}
void DefaultBtMessageFactory::setTaskFactory
(const WeakHandle<DHTTaskFactory>& taskFactory)
void DefaultBtMessageFactory::setTaskFactory(DHTTaskFactory* taskFactory)
{
taskFactory_ = taskFactory;
}
@ -496,7 +502,7 @@ void DefaultBtMessageFactory::setPeerStorage
}
void DefaultBtMessageFactory::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher)
(BtMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
@ -507,25 +513,22 @@ void DefaultBtMessageFactory::setExtensionMessageFactory
extensionMessageFactory_ = factory;
}
void DefaultBtMessageFactory::setLocalNode(const WeakHandle<DHTNode>& localNode)
void DefaultBtMessageFactory::setLocalNode(DHTNode* localNode)
{
localNode_ = localNode;
}
void DefaultBtMessageFactory::setRoutingTable
(const WeakHandle<DHTRoutingTable>& routingTable)
void DefaultBtMessageFactory::setRoutingTable(DHTRoutingTable* routingTable)
{
routingTable_ = routingTable;
}
void DefaultBtMessageFactory::setBtRequestFactory
(const WeakHandle<BtRequestFactory>& factory)
void DefaultBtMessageFactory::setBtRequestFactory(BtRequestFactory* factory)
{
requestFactory_ = factory;
}
void DefaultBtMessageFactory::setPeerConnection
(const WeakHandle<PeerConnection>& connection)
void DefaultBtMessageFactory::setPeerConnection(PeerConnection* connection)
{
peerConnection_ = connection;
}

View file

@ -64,21 +64,21 @@ private:
bool dhtEnabled_;
WeakHandle<BtMessageDispatcher> dispatcher_;
BtMessageDispatcher* dispatcher_;
WeakHandle<BtRequestFactory> requestFactory_;
BtRequestFactory* requestFactory_;
WeakHandle<PeerConnection> peerConnection_;
PeerConnection* peerConnection_;
SharedHandle<ExtensionMessageFactory> extensionMessageFactory_;
DHTNode* localNode_;
WeakHandle<DHTNode> localNode_;
DHTRoutingTable* routingTable_;
WeakHandle<DHTRoutingTable> routingTable_;
DHTTaskQueue* taskQueue_;
WeakHandle<DHTTaskQueue> taskQueue_;
WeakHandle<DHTTaskFactory> taskFactory_;
DHTTaskFactory* taskFactory_;
bool metadataGetMode_;
@ -153,22 +153,22 @@ public:
}
void setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher);
(BtMessageDispatcher* dispatcher);
void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory);
void setBtRequestFactory(BtRequestFactory* factory);
void setPeerConnection(const WeakHandle<PeerConnection>& connection);
void setPeerConnection(PeerConnection* connection);
void setExtensionMessageFactory
(const SharedHandle<ExtensionMessageFactory>& factory);
void setLocalNode(const WeakHandle<DHTNode>& localNode);
void setLocalNode(DHTNode* localNode);
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable);
void setRoutingTable(DHTRoutingTable* routingTable);
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue);
void setTaskQueue(DHTTaskQueue* taskQueue);
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory);
void setTaskFactory(DHTTaskFactory* taskFactory);
void enableMetadataGetMode()
{

View file

@ -51,7 +51,10 @@
namespace aria2 {
DefaultBtMessageReceiver::DefaultBtMessageReceiver():
handshakeSent_(false)
handshakeSent_(false),
peerConnection_(0),
dispatcher_(0),
messageFactory_(0)
{}
SharedHandle<BtHandshakeMessage>
@ -115,20 +118,17 @@ void DefaultBtMessageReceiver::setDownloadContext
downloadContext_ = downloadContext;
}
void DefaultBtMessageReceiver::setPeerConnection
(const WeakHandle<PeerConnection>& peerConnection)
void DefaultBtMessageReceiver::setPeerConnection(PeerConnection* peerConnection)
{
peerConnection_ = peerConnection;
}
void DefaultBtMessageReceiver::setDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher)
void DefaultBtMessageReceiver::setDispatcher(BtMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DefaultBtMessageReceiver::setBtMessageFactory
(const WeakHandle<BtMessageFactory>& factory)
void DefaultBtMessageReceiver::setBtMessageFactory(BtMessageFactory* factory)
{
messageFactory_ = factory;
}

View file

@ -51,9 +51,9 @@ class DefaultBtMessageReceiver : public BtMessageReceiver {
private:
bool handshakeSent_;
SharedHandle<DownloadContext> downloadContext_;
WeakHandle<PeerConnection> peerConnection_;
WeakHandle<BtMessageDispatcher> dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_;
PeerConnection* peerConnection_;
BtMessageDispatcher* dispatcher_;
BtMessageFactory* messageFactory_;
void sendHandshake();
public:
@ -68,11 +68,11 @@ public:
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection);
void setPeerConnection(PeerConnection* peerConnection);
void setDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setDispatcher(BtMessageDispatcher* dispatcher);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
void setBtMessageFactory(BtMessageFactory* factory);
};
typedef SharedHandle<DefaultBtMessageReceiver> DefaultBtMessageReceiverHandle;

View file

@ -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

View file

@ -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<BtMessageDispatcher> dispatcher_;
BtMessageDispatcher* dispatcher_;
public:
AbortCompletedPieceRequest(const WeakHandle<BtMessageDispatcher>& dispatcher):
AbortCompletedPieceRequest(BtMessageDispatcher* dispatcher):
dispatcher_(dispatcher) {}
void operator()(const SharedHandle<Piece>& piece)
@ -110,10 +112,10 @@ namespace {
class ProcessChokedPiece {
private:
SharedHandle<Peer> peer_;
WeakHandle<PieceStorage> pieceStorage_;
SharedHandle<PieceStorage> pieceStorage_;
public:
ProcessChokedPiece(const SharedHandle<Peer>& peer,
const WeakHandle<PieceStorage>& pieceStorage):
const SharedHandle<PieceStorage>& pieceStorage):
peer_(peer),
pieceStorage_(pieceStorage) {}
@ -280,13 +282,12 @@ void DefaultBtRequestFactory::setPeer(const SharedHandle<Peer>& peer)
}
void DefaultBtRequestFactory::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher)
(BtMessageDispatcher* dispatcher)
{
dispatcher_ = dispatcher;
}
void DefaultBtRequestFactory::setBtMessageFactory
(const WeakHandle<BtMessageFactory>& factory)
void DefaultBtRequestFactory::setBtMessageFactory(BtMessageFactory* factory)
{
messageFactory_ = factory;
}

View file

@ -54,8 +54,8 @@ class DefaultBtRequestFactory : public BtRequestFactory {
private:
SharedHandle<PieceStorage> pieceStorage_;
SharedHandle<Peer> peer_;
WeakHandle<BtMessageDispatcher> dispatcher_;
WeakHandle<BtMessageFactory> messageFactory_;
BtMessageDispatcher* dispatcher_;
BtMessageFactory* messageFactory_;
std::deque<SharedHandle<Piece> > pieces_;
Logger* logger_;
public:
@ -96,10 +96,9 @@ public:
void setPeer(const SharedHandle<Peer>& peer);
void setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dispatcher);
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
void setBtMessageFactory(BtMessageFactory* factory);
};
typedef SharedHandle<DefaultBtRequestFactory> DefaultBtRequestFactoryHandle;

View file

@ -57,6 +57,9 @@
namespace aria2 {
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory():
messageFactory_(0),
dispatcher_(0),
tracker_(0),
logger_(LogFactory::getInstance()) {}
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory

View file

@ -58,11 +58,11 @@ private:
SharedHandle<DownloadContext> dctx_;
WeakHandle<BtMessageFactory> messageFactory_;
BtMessageFactory* messageFactory_;
WeakHandle<BtMessageDispatcher> dispatcher_;
BtMessageDispatcher* dispatcher_;
WeakHandle<UTMetadataRequestTracker> tracker_;
UTMetadataRequestTracker* tracker_;
Logger* logger_;
@ -93,18 +93,17 @@ public:
dctx_ = dctx;
}
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory)
void setBtMessageFactory(BtMessageFactory* factory)
{
messageFactory_ = factory;
}
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& disp)
void setBtMessageDispatcher(BtMessageDispatcher* disp)
{
dispatcher_ = disp;
}
void setUTMetadataRequestTracker
(const WeakHandle<UTMetadataRequestTracker>& tracker)
void setUTMetadataRequestTracker(UTMetadataRequestTracker* tracker)
{
tracker_ = tracker;
}

View file

@ -92,7 +92,7 @@ bool DefaultPeerStorage::isPeerAlreadyAdded(const SharedHandle<Peer>& peer)
namespace {
size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& 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 {

View file

@ -89,7 +89,7 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece(size_t index)
bitfieldMan_->setUseBit(index);
SharedHandle<Piece> 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<Piece> DefaultPieceStorage::getPiece(size_t index)
SharedHandle<Piece> 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<Piece> 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<Piece> DefaultPieceStorage::getMissingPiece(size_t index)
void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
{
if(piece.isNull()) {
if(!piece) {
return;
}
std::deque<SharedHandle<Piece> >::iterator i =
@ -412,7 +412,7 @@ void DefaultPieceStorage::deleteUsedPiece(const SharedHandle<Piece>& piece)
void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
{
if(piece.isNull()) {
if(!piece) {
return;
}
deleteUsedPiece(piece);
@ -456,7 +456,7 @@ bool DefaultPieceStorage::isSelectiveDownloadingMode()
// not unittested
void DefaultPieceStorage::cancelPiece(const SharedHandle<Piece>& piece)
{
if(piece.isNull()) {
if(!piece) {
return;
}
bitfieldMan_->unsetUseBit(piece->getIndex());

View file

@ -315,11 +315,11 @@ bool DownloadCommand::prepareForNextSegment() {
}
SharedHandle<Segment> 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>& segment,
void DownloadCommand::installStreamFilter
(const SharedHandle<StreamFilter>& streamFilter)
{
if(streamFilter.isNull()) {
if(!streamFilter) {
return;
}
streamFilter->installDelegate(streamFilter_);

View file

@ -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>& request,
const SharedHandle<SocketCore>& socket,
time_t timeout)
{
if(proxyRequest.isNull()) {
if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo);
poolSocket(peerInfo.first, peerInfo.second,
@ -381,7 +381,7 @@ void DownloadEngine::poolSocket
const std::map<std::string, std::string>& options,
time_t timeout)
{
if(proxyRequest.isNull()) {
if(!proxyRequest) {
std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo);
poolSocket(peerInfo.first, peerInfo.second, username,
@ -456,7 +456,7 @@ DownloadEngine::popPooledSocket
for(std::vector<std::string>::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<std::string>::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;
}
}

View file

@ -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)

View file

@ -69,7 +69,7 @@ DownloadHandlerFactory::btMetadataPostDownloadHandler_;
SharedHandle<MemoryBufferPreDownloadHandler>
DownloadHandlerFactory::getMetalinkPreDownloadHandler()
{
if(metalinkPreDownloadHandler_.isNull()) {
if(!metalinkPreDownloadHandler_) {
metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
RequestGroupCriteriaHandle criteria
@ -86,7 +86,7 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler()
SharedHandle<MetalinkPostDownloadHandler>
DownloadHandlerFactory::getMetalinkPostDownloadHandler()
{
if(metalinkPostDownloadHandler_.isNull()) {
if(!metalinkPostDownloadHandler_) {
metalinkPostDownloadHandler_.reset(new MetalinkPostDownloadHandler());
}
return metalinkPostDownloadHandler_;
@ -99,7 +99,7 @@ DownloadHandlerFactory::getMetalinkPostDownloadHandler()
SharedHandle<MemoryBufferPreDownloadHandler>
DownloadHandlerFactory::getBtPreDownloadHandler()
{
if(btPreDownloadHandler_.isNull()) {
if(!btPreDownloadHandler_) {
btPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
RequestGroupCriteriaHandle criteria
@ -116,7 +116,7 @@ DownloadHandlerFactory::getBtPreDownloadHandler()
SharedHandle<BtPostDownloadHandler>
DownloadHandlerFactory::getBtPostDownloadHandler()
{
if(btPostDownloadHandler_.isNull()) {
if(!btPostDownloadHandler_) {
btPostDownloadHandler_.reset(new BtPostDownloadHandler());
}
return btPostDownloadHandler_;
@ -125,7 +125,7 @@ DownloadHandlerFactory::getBtPostDownloadHandler()
SharedHandle<UTMetadataPostDownloadHandler>
DownloadHandlerFactory::getUTMetadataPostDownloadHandler()
{
if(btMetadataPostDownloadHandler_.isNull()) {
if(!btMetadataPostDownloadHandler_) {
btMetadataPostDownloadHandler_.reset(new UTMetadataPostDownloadHandler());
}
return btMetadataPostDownloadHandler_;

View file

@ -64,7 +64,7 @@ std::string Exception::stackTrace() const
}
s << what() << "\n";
SharedHandle<Exception> e = cause_;
while(!e.isNull()) {
while(e) {
s << " -> " << "[" << e->file_ << ":" << e->line_ << "] "
<< e->what() << "\n";
e = e->cause_;

View file

@ -122,7 +122,7 @@ FeatureConfig::FeatureConfig() {
const SharedHandle<FeatureConfig>& FeatureConfig::getInstance()
{
if(featureConfig_.isNull()) {
if(!featureConfig_) {
featureConfig_.reset(new FeatureConfig());
}
return featureConfig_;

View file

@ -115,7 +115,7 @@ std::string FeedbackURISelector::selectRarer
}
SharedHandle<ServerStat> 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<ServerStat> 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) {

View file

@ -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<Request>& base)
return SharedHandle<Request>();
}
const SharedHandle<PeerStat>& fastest = requestPool_.front()->getPeerStat();
if(fastest.isNull()) {
if(!fastest) {
return SharedHandle<Request>();
}
const SharedHandle<PeerStat>& 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<Request>& lhs,
const SharedHandle<Request>& 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>& request)
{
const SharedHandle<PeerStat>& 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();

View file

@ -315,7 +315,7 @@ void writeFilePath
(InputIterator first, InputIterator last, std::ostream& o, bool memory)
{
SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
if(e.isNull()) {
if(!e) {
o << "n/a";
} else {
if(e->getPath().empty()) {

View file

@ -291,7 +291,7 @@ bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
{
if(socketBuffer_.sendBufferIsEmpty()) {
std::string request = "REST ";
if(segment.isNull()) {
if(!segment) {
request += "0";
} else {
request += util::itos(segment->getPositionToWrite());

View file

@ -77,7 +77,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
const SharedHandle<Request>& proxyRequest)
{
Command* command;
if(!proxyRequest.isNull()) {
if(proxyRequest) {
std::map<std::string, std::string> options;
SharedHandle<SocketCore> 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);

View file

@ -444,7 +444,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
SharedHandle<CheckIntegrityEntry> 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> 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>& 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);
}

View file

@ -65,7 +65,7 @@ void HaveEraseCommand::process()
PieceStorageHandle ps =
getDownloadEngine()->getRequestGroupMan()->getRequestGroup(i)->
getPieceStorage();
if(!ps.isNull()) {
if(ps) {
ps->removeAdvertisedPiece(5);
}
}

View file

@ -71,13 +71,13 @@ Command* HttpInitiateConnectionCommand::createNextCommand
const SharedHandle<Request>& proxyRequest)
{
Command* command;
if(!proxyRequest.isNull()) {
if(proxyRequest) {
SharedHandle<SocketCore> 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<SocketCore> 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);

View file

@ -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();

View file

@ -74,7 +74,7 @@ void HttpRequest::setRequest(const SharedHandle<Request>& 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<Range>(new Range());
} else {
return SharedHandle<Range>(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<Cookie> 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<Request>& proxyRequest)
bool HttpRequest::isProxyRequestSet() const
{
return !proxyRequest_.isNull();
return proxyRequest_;
}
bool HttpRequest::authenticationUsed() const
{
return !authConfig_.isNull();
return authConfig_;
}
const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const

View file

@ -106,7 +106,7 @@ public:
uint64_t getEntityLength() const
{
assert(!fileEntry_.isNull());
assert(fileEntry_);
return fileEntry_->getLength();
}

View file

@ -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

View file

@ -217,7 +217,7 @@ SharedHandle<StreamFilter> 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<std::string, std::string> p;

View file

@ -87,7 +87,7 @@ SharedHandle<StreamFilter> getTransferEncodingStreamFilter
SharedHandle<StreamFilter> 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<StreamFilter> getTransferEncodingStreamFilter
filter->init();
filter->installDelegate(delegate);
}
if(filter.isNull()) {
if(!filter) {
filter = delegate;
}
return filter;
@ -110,7 +110,7 @@ SharedHandle<StreamFilter> getContentEncodingStreamFilter
SharedHandle<StreamFilter> 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<StreamFilter> getContentEncodingStreamFilter
filter->installDelegate(delegate);
}
}
if(filter.isNull()) {
if(!filter) {
filter = delegate;
}
return filter;
@ -146,7 +146,7 @@ bool HttpResponseCommand::executeInternal()
{
SharedHandle<HttpRequest> httpRequest =httpConnection_->getFirstHttpRequest();
SharedHandle<HttpResponse> 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<CheckIntegrityEntry> 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<StreamFilter>& filter)
{
#ifdef HAVE_LIBZ
for(SharedHandle<StreamFilter> f = filter; !f.isNull(); f = f->getDelegate()){
for(SharedHandle<StreamFilter> 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.

View file

@ -82,7 +82,7 @@ SharedHandle<HttpHeader> HttpServer::receiveRequest()
socket_->readData(buf, size);
SharedHandle<HttpHeader> header = headerProcessor_->getHttpRequestHeader();
if(!header.isNull()) {
if(header) {
logger_->info("HTTP Server received request\n%s",
headerProcessor_->getHeaderString().c_str());
lastRequestHeader_ = header;

View file

@ -101,7 +101,7 @@ bool HttpServerCommand::execute()
header = httpServer_->receiveRequest();
if(header.isNull()) {
if(!header) {
e_->addCommand(this);
return false;
}

View file

@ -87,7 +87,7 @@ HttpSkipResponseCommand::~HttpSkipResponseCommand() {}
void HttpSkipResponseCommand::installStreamFilter
(const SharedHandle<StreamFilter>& streamFilter)
{
if(streamFilter.isNull()) {
if(!streamFilter) {
return;
}
streamFilter->installDelegate(streamFilter_);

View file

@ -77,7 +77,7 @@ bool InitiateConnectionCommand::executeInternal() {
std::string hostname;
uint16_t port;
SharedHandle<Request> proxyRequest = createProxyRequest();
if(proxyRequest.isNull()) {
if(!proxyRequest) {
hostname = getRequest()->getHost();
port = getRequest()->getPort();
} else {

View file

@ -84,17 +84,17 @@ bool LpdReceiveMessageCommand::execute()
}
for(size_t i = 0; i < 20; ++i) {
SharedHandle<LpdMessage> m = receiver_->receiveMessage();
if(m.isNull()) {
if(!m) {
break;
}
if(m->getPeer().isNull()) {
if(!m->getPeer()) {
// bad message
continue;
}
SharedHandle<BtRegistry> reg = e_->getBtRegistry();
SharedHandle<DownloadContext> 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> peerStorage = btobj.peerStorage_;
assert(!peerStorage.isNull());
assert(peerStorage);
SharedHandle<Peer> peer = m->getPeer();
if(peerStorage->addPeer(peer)) {
if(getLogger()->debug()) {

View file

@ -492,7 +492,7 @@ bool MSEHandshake::receiveReceiverHashAndPadCLength
break;
}
}
if(downloadContext.isNull()) {
if(!downloadContext) {
throw DL_ABORT_EX("Unknown info hash.");
}
initCipher(bittorrent::getInfoHash(downloadContext));

View file

@ -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<Dependency> dep(new BtDependency(rg, torrentRg));
// torrentRg is true
if(torrentRg) {
SharedHandle<Dependency> dep(new BtDependency(rg.get(), torrentRg));
rg->dependsOn(dep);
torrentRg->belongsTo(rg->getGID());
// metadata download may take very long time. If URIs are

View file

@ -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<std::string> 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

View file

@ -80,7 +80,7 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
requestGroup->followedBy(newRgs.begin(), newRgs.end());
SharedHandle<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext());
if(!mi.isNull()) {
if(mi) {
setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
}
groups.insert(groups.end(), newRgs.begin(), newRgs.end());

View file

@ -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();

View file

@ -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();

View file

@ -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>& authenticator)
{
if(!authenticator.isNull()) {
if(authenticator) {
authenticators_.push_back(authenticator);
}
}

View file

@ -43,7 +43,7 @@ NetrcAuthResolver::NetrcAuthResolver():ignoreDefault_(false) {}
SharedHandle<AuthConfig>
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<AuthConfig>
NetrcAuthResolver::findNetrcAuthenticator(const std::string& hostname) const
{
if(netrc_.isNull()) {
if(!netrc_) {
return getDefaultAuthConfig();
} else {
SharedHandle<Authenticator> auth = netrc_->findAuthenticator(hostname);
if(auth.isNull()) {
if(!auth) {
return getDefaultAuthConfig();
} else {
if(ignoreDefault_ && auth->getMachine().empty()) {

View file

@ -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::optionParser_;
const SharedHandle<OptionParser>& OptionParser::getInstance()
{
if(optionParser_.isNull()) {
if(!optionParser_) {
optionParser_.reset(new OptionParser());
optionParser_->setOptionHandlers(OptionHandlerFactory::createOptionHandlers());
}

View file

@ -54,7 +54,7 @@ void PStringBuildVisitor::visit(PStringSegment& segment)
uris_.push_back(uri);
}
if(!segment.getNext().isNull()) {
if(segment.getNext()) {
segment.getNext()->accept(*this);
}

View file

@ -58,7 +58,7 @@ const std::string& PStringSegment::getValue() const
bool PStringSegment::hasNext() const
{
return !next_.isNull();
return next_;
}
SharedHandle<PStringDatum> PStringSegment::getNext() const

View file

@ -404,7 +404,7 @@ void Peer::setFirstContactTime(const Timer& time)
firstContactTime_ = time;
}
void Peer::setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt)
void Peer::setBtMessageDispatcher(BtMessageDispatcher* dpt)
{
assert(res_);
res_->setBtMessageDispatcher(dpt);

View file

@ -322,7 +322,7 @@ public:
disconnectedGracefully_ = f;
}
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt);
void setBtMessageDispatcher(BtMessageDispatcher* dpt);
size_t countOutstandingUpload() const;
};

Some files were not shown because too many files have changed in this diff Show more