Require -std=c++11 and use std::shared_ptr instead of SharedHandle

pull/103/head
Tatsuhiro Tsujikawa 2013-06-22 01:10:38 +09:00
parent 126a4bde61
commit 07d270c87e
709 changed files with 6305 additions and 6878 deletions

View File

@ -93,6 +93,8 @@ AC_LANG([C++])
# Check pkg-config is available
PKG_PROG_PKG_CONFIG([0.20])
CXXFLAGS="-std=c++11 $CXXFLAGS"
# Check static build is requested
if test "x$ARIA2_STATIC" = "xyes"; then
case "$host" in

View File

@ -42,13 +42,13 @@ AbstractAuthResolver::AbstractAuthResolver() {}
AbstractAuthResolver::~AbstractAuthResolver() {}
void AbstractAuthResolver::setUserDefinedAuthConfig
(const SharedHandle<AuthConfig>& authConfig)
(const std::shared_ptr<AuthConfig>& authConfig)
{
userDefinedAuthConfig_ = authConfig;
}
void AbstractAuthResolver::setDefaultAuthConfig
(const SharedHandle<AuthConfig>& authConfig)
(const std::shared_ptr<AuthConfig>& authConfig)
{
defaultAuthConfig_ = authConfig;
}

View File

@ -41,24 +41,24 @@ namespace aria2 {
class AbstractAuthResolver : public AuthResolver {
private:
SharedHandle<AuthConfig> userDefinedAuthConfig_;
std::shared_ptr<AuthConfig> userDefinedAuthConfig_;
SharedHandle<AuthConfig> defaultAuthConfig_;
std::shared_ptr<AuthConfig> defaultAuthConfig_;
public:
AbstractAuthResolver();
virtual ~AbstractAuthResolver();
void setUserDefinedAuthConfig(const SharedHandle<AuthConfig>& authConfig);
void setUserDefinedAuthConfig(const std::shared_ptr<AuthConfig>& authConfig);
const SharedHandle<AuthConfig>& getUserDefinedAuthConfig() const
const std::shared_ptr<AuthConfig>& getUserDefinedAuthConfig() const
{
return userDefinedAuthConfig_;
}
void setDefaultAuthConfig(const SharedHandle<AuthConfig>& authConfig);
void setDefaultAuthConfig(const std::shared_ptr<AuthConfig>& authConfig);
const SharedHandle<AuthConfig>& getDefaultAuthConfig() const
const std::shared_ptr<AuthConfig>& getDefaultAuthConfig() const
{
return defaultAuthConfig_;
}

View File

@ -54,7 +54,7 @@ AbstractBtMessage::AbstractBtMessage(uint8_t id, const char* name)
AbstractBtMessage::~AbstractBtMessage() {}
void AbstractBtMessage::setPeer(const SharedHandle<Peer>& peer)
void AbstractBtMessage::setPeer(const std::shared_ptr<Peer>& peer)
{
peer_ = peer;
}
@ -67,12 +67,12 @@ void AbstractBtMessage::validate()
}
void
AbstractBtMessage::setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator) {
AbstractBtMessage::setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator) {
validator_ = validator;
}
void AbstractBtMessage::setPieceStorage
(const SharedHandle<PieceStorage>& pieceStorage)
(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}

View File

@ -56,9 +56,9 @@ private:
const char* name_;
SharedHandle<PieceStorage> pieceStorage_;
std::shared_ptr<PieceStorage> pieceStorage_;
SharedHandle<Peer> peer_;
std::shared_ptr<Peer> peer_;
BtMessageDispatcher* dispatcher_;
@ -68,11 +68,11 @@ private:
PeerConnection* peerConnection_;
SharedHandle<BtMessageValidator> validator_;
std::shared_ptr<BtMessageValidator> validator_;
bool metadataGetMode_;
protected:
const SharedHandle<PieceStorage>& getPieceStorage() const
const std::shared_ptr<PieceStorage>& getPieceStorage() const
{
return pieceStorage_;
}
@ -130,12 +130,12 @@ public:
cuid_ = cuid;
}
const SharedHandle<Peer>& getPeer() const
const std::shared_ptr<Peer>& getPeer() const
{
return peer_;
}
void setPeer(const SharedHandle<Peer>& peer);
void setPeer(const std::shared_ptr<Peer>& peer);
virtual void doReceivedAction() {}
@ -151,9 +151,9 @@ public:
virtual void onChokingEvent(const BtChokingEvent& event) {}
void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
void setBtMessageValidator(const std::shared_ptr<BtMessageValidator>& validator);
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
void setBtMessageDispatcher(BtMessageDispatcher* dispatcher);

View File

@ -79,12 +79,12 @@ namespace aria2 {
AbstractCommand::AbstractCommand
(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<SocketCore>& s,
const SharedHandle<SocketRecvBuffer>& socketRecvBuffer,
const std::shared_ptr<SocketCore>& s,
const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer,
bool incNumConnection)
: Command(cuid), checkPoint_(global::wallclock()),
timeout_(requestGroup->getTimeout()),
@ -125,7 +125,7 @@ AbstractCommand::~AbstractCommand() {
}
void AbstractCommand::useFasterRequest
(const SharedHandle<Request>& fasterRequest)
(const std::shared_ptr<Request>& fasterRequest)
{
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use faster Request hostname=%s, port=%u",
getCuid(),
@ -180,7 +180,7 @@ bool AbstractCommand::execute() {
if(req_ && fileEntry_->countPooledRequest() > 0 &&
requestGroup_->getTotalLength()-requestGroup_->getCompletedLength()
< calculateMinSplitSize()*2) {
SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
std::shared_ptr<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
if(fasterRequest) {
useFasterRequest(fasterRequest);
return true;
@ -197,7 +197,7 @@ bool AbstractCommand::execute() {
if(getOption()->getAsBool(PREF_SELECT_LEAST_USED_HOST)) {
getDownloadEngine()->getRequestGroupMan()->getUsedHosts(usedHosts);
}
SharedHandle<Request> fasterRequest =
std::shared_ptr<Request> fasterRequest =
fileEntry_->findFasterRequest
(req_, usedHosts, e_->getRequestGroupMan()->getServerStatMan());
if(fasterRequest) {
@ -230,7 +230,7 @@ bool AbstractCommand::execute() {
size_t maxSegments = req_?req_->getMaxPipelinedRequest():1;
size_t minSplitSize = calculateMinSplitSize();
while(segments_.size() < maxSegments) {
SharedHandle<Segment> segment =
std::shared_ptr<Segment> segment =
getSegmentMan()->getSegment(getCuid(), minSplitSize);
if(!segment) {
break;
@ -276,7 +276,7 @@ bool AbstractCommand::execute() {
} else {
if(checkPoint_.difference(global::wallclock()) >= timeout_) {
// timeout triggers ServerStat error state.
SharedHandle<ServerStat> ss =
std::shared_ptr<ServerStat> ss =
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
req_->getProtocol());
ss->setError();
@ -375,7 +375,7 @@ bool AbstractCommand::execute() {
void AbstractCommand::tryReserved() {
if(getDownloadContext()->getFileEntries().size() == 1) {
const SharedHandle<FileEntry>& entry =
const std::shared_ptr<FileEntry>& entry =
getDownloadContext()->getFirstFileEntry();
// Don't create new command if currently file length is unknown
// and there are no URI left. Because file length is unknown, we
@ -490,7 +490,7 @@ void AbstractCommand::disableReadCheckSocket() {
}
void AbstractCommand::setReadCheckSocket
(const SharedHandle<SocketCore>& socket) {
(const std::shared_ptr<SocketCore>& socket) {
if(!socket->isOpen()) {
disableReadCheckSocket();
} else {
@ -509,7 +509,7 @@ void AbstractCommand::setReadCheckSocket
}
void AbstractCommand::setReadCheckSocketIf
(const SharedHandle<SocketCore>& socket, bool pred)
(const std::shared_ptr<SocketCore>& socket, bool pred)
{
if(pred) {
setReadCheckSocket(socket);
@ -527,7 +527,7 @@ void AbstractCommand::disableWriteCheckSocket() {
}
void AbstractCommand::setWriteCheckSocket
(const SharedHandle<SocketCore>& socket) {
(const std::shared_ptr<SocketCore>& socket) {
if(!socket->isOpen()) {
disableWriteCheckSocket();
} else {
@ -546,7 +546,7 @@ void AbstractCommand::setWriteCheckSocket
}
void AbstractCommand::setWriteCheckSocketIf
(const SharedHandle<SocketCore>& socket, bool pred)
(const std::shared_ptr<SocketCore>& socket, bool pred)
{
if(pred) {
setWriteCheckSocket(socket);
@ -555,7 +555,7 @@ void AbstractCommand::setWriteCheckSocketIf
}
}
void AbstractCommand::swapSocket(SharedHandle<SocketCore>& socket)
void AbstractCommand::swapSocket(std::shared_ptr<SocketCore>& socket)
{
disableReadCheckSocket();
disableWriteCheckSocket();
@ -634,7 +634,7 @@ namespace {
// Returns true if proxy is defined for the given protocol. Otherwise
// returns false.
bool isProxyRequest
(const std::string& protocol, const SharedHandle<Option>& option)
(const std::string& protocol, const std::shared_ptr<Option>& option)
{
std::string proxyUri = getProxyUri(protocol, option.get());
return !proxyUri.empty();
@ -642,7 +642,7 @@ bool isProxyRequest
} // namespace
namespace {
bool inNoProxy(const SharedHandle<Request>& req,
bool inNoProxy(const std::shared_ptr<Request>& req,
const std::string& noProxy)
{
std::vector<Scip> entries;
@ -685,9 +685,9 @@ bool AbstractCommand::isProxyDefined() const
!inNoProxy(req_, getOption()->get(PREF_NO_PROXY));
}
SharedHandle<Request> AbstractCommand::createProxyRequest() const
std::shared_ptr<Request> AbstractCommand::createProxyRequest() const
{
SharedHandle<Request> proxyRequest;
std::shared_ptr<Request> proxyRequest;
if(inNoProxy(req_, getOption()->get(PREF_NO_PROXY))) {
return proxyRequest;
}
@ -772,7 +772,7 @@ std::string AbstractCommand::resolveHostname
}
void AbstractCommand::prepareForNextAction
(const SharedHandle<CheckIntegrityEntry>& checkEntry)
(const std::shared_ptr<CheckIntegrityEntry>& checkEntry)
{
std::vector<Command*>* commands = new std::vector<Command*>();
auto_delete_container<std::vector<Command*> > commandsDel(commands);
@ -783,7 +783,7 @@ void AbstractCommand::prepareForNextAction
}
bool AbstractCommand::checkIfConnectionEstablished
(const SharedHandle<SocketCore>& socket,
(const std::shared_ptr<SocketCore>& socket,
const std::string& connectedHostname,
const std::string& connectedAddr,
uint16_t connectedPort)
@ -827,7 +827,7 @@ const std::string& AbstractCommand::resolveProxyMethod
}
}
const SharedHandle<Option>& AbstractCommand::getOption() const
const std::shared_ptr<Option>& AbstractCommand::getOption() const
{
return requestGroup_->getOption();
}
@ -846,7 +846,7 @@ int32_t AbstractCommand::calculateMinSplitSize() const
}
}
void AbstractCommand::setRequest(const SharedHandle<Request>& request)
void AbstractCommand::setRequest(const std::shared_ptr<Request>& request)
{
req_ = request;
}
@ -856,27 +856,27 @@ void AbstractCommand::resetRequest()
req_.reset();
}
void AbstractCommand::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
void AbstractCommand::setFileEntry(const std::shared_ptr<FileEntry>& fileEntry)
{
fileEntry_ = fileEntry;
}
void AbstractCommand::setSocket(const SharedHandle<SocketCore>& s)
void AbstractCommand::setSocket(const std::shared_ptr<SocketCore>& s)
{
socket_ = s;
}
const SharedHandle<DownloadContext>& AbstractCommand::getDownloadContext() const
const std::shared_ptr<DownloadContext>& AbstractCommand::getDownloadContext() const
{
return requestGroup_->getDownloadContext();
}
const SharedHandle<SegmentMan>& AbstractCommand::getSegmentMan() const
const std::shared_ptr<SegmentMan>& AbstractCommand::getSegmentMan() const
{
return requestGroup_->getSegmentMan();
}
const SharedHandle<PieceStorage>& AbstractCommand::getPieceStorage() const
const std::shared_ptr<PieceStorage>& AbstractCommand::getPieceStorage() const
{
return requestGroup_->getPieceStorage();
}

View File

@ -39,8 +39,8 @@
#include <vector>
#include <string>
#include <memory>
#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@ -68,76 +68,76 @@ private:
time_t timeout_;
RequestGroup* requestGroup_;
SharedHandle<Request> req_;
SharedHandle<FileEntry> fileEntry_;
std::shared_ptr<Request> req_;
std::shared_ptr<FileEntry> fileEntry_;
DownloadEngine* e_;
SharedHandle<SocketCore> socket_;
SharedHandle<SocketRecvBuffer> socketRecvBuffer_;
std::vector<SharedHandle<Segment> > segments_;
std::shared_ptr<SocketCore> socket_;
std::shared_ptr<SocketRecvBuffer> socketRecvBuffer_;
std::vector<std::shared_ptr<Segment> > segments_;
#ifdef ENABLE_ASYNC_DNS
SharedHandle<AsyncNameResolverMan> asyncNameResolverMan_;
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS
bool checkSocketIsReadable_;
bool checkSocketIsWritable_;
SharedHandle<SocketCore> readCheckTarget_;
SharedHandle<SocketCore> writeCheckTarget_;
std::shared_ptr<SocketCore> readCheckTarget_;
std::shared_ptr<SocketCore> writeCheckTarget_;
bool incNumConnection_;
Timer serverStatTimer_;
int32_t calculateMinSplitSize() const;
void useFasterRequest(const SharedHandle<Request>& fasterRequest);
void useFasterRequest(const std::shared_ptr<Request>& fasterRequest);
public:
RequestGroup* getRequestGroup() const
{
return requestGroup_;
}
const SharedHandle<Request>& getRequest() const
const std::shared_ptr<Request>& getRequest() const
{
return req_;
}
void setRequest(const SharedHandle<Request>& request);
void setRequest(const std::shared_ptr<Request>& request);
// Resets request_. This method is more efficient than
// setRequest(SharedHandle<Request>());
// setRequest(std::shared_ptr<Request>());
void resetRequest();
const SharedHandle<FileEntry>& getFileEntry() const
const std::shared_ptr<FileEntry>& getFileEntry() const
{
return fileEntry_;
}
void setFileEntry(const SharedHandle<FileEntry>& fileEntry);
void setFileEntry(const std::shared_ptr<FileEntry>& fileEntry);
DownloadEngine* getDownloadEngine() const
{
return e_;
}
const SharedHandle<SocketCore>& getSocket() const
const std::shared_ptr<SocketCore>& getSocket() const
{
return socket_;
}
SharedHandle<SocketCore>& getSocket()
std::shared_ptr<SocketCore>& getSocket()
{
return socket_;
}
void setSocket(const SharedHandle<SocketCore>& s);
void setSocket(const std::shared_ptr<SocketCore>& s);
void createSocket();
const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
const std::shared_ptr<SocketRecvBuffer>& getSocketRecvBuffer() const
{
return socketRecvBuffer_;
}
const std::vector<SharedHandle<Segment> >& getSegments() const
const std::vector<std::shared_ptr<Segment> >& getSegments() const
{
return segments_;
}
@ -152,8 +152,8 @@ public:
void tryReserved();
void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
void setWriteCheckSocket(const SharedHandle<SocketCore>& socket);
void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
void setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket);
void disableReadCheckSocket();
void disableWriteCheckSocket();
@ -161,16 +161,16 @@ public:
* If pred == true, calls setReadCheckSocket(socket). Otherwise, calls
* disableReadCheckSocket().
*/
void setReadCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
void setReadCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
/**
* If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls
* disableWriteCheckSocket().
*/
void setWriteCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
void setWriteCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
// Swaps socket_ with socket. This disables current read and write
// check.
void swapSocket(SharedHandle<SocketCore>& socket);
void swapSocket(std::shared_ptr<SocketCore>& socket);
time_t getTimeout() const
{
@ -180,7 +180,7 @@ public:
void setTimeout(time_t timeout) { timeout_ = timeout; }
void prepareForNextAction
(const SharedHandle<CheckIntegrityEntry>& checkEntry);
(const std::shared_ptr<CheckIntegrityEntry>& checkEntry);
// Check if socket is connected. If socket is not connected and
// there are other addresses to try, command is created using
@ -188,7 +188,7 @@ public:
// DownloadEngine and returns false. If no addresses left, DlRetryEx
// exception is thrown.
bool checkIfConnectionEstablished
(const SharedHandle<SocketCore>& socket,
(const std::shared_ptr<SocketCore>& socket,
const std::string& connectedHostname,
const std::string& connectedAddr,
uint16_t connectedPort);
@ -201,19 +201,19 @@ public:
/*
* Creates Request object for proxy URI and returns it.
* If no valid proxy is defined, then returns SharedHandle<Request>().
* If no valid proxy is defined, then returns std::shared_ptr<Request>().
*/
SharedHandle<Request> createProxyRequest() const;
std::shared_ptr<Request> createProxyRequest() const;
// Returns proxy method for given protocol. Either V_GET or V_TUNNEL
// is returned. For HTTPS, always returns V_TUNNEL.
const std::string& resolveProxyMethod(const std::string& protocol) const;
const SharedHandle<Option>& getOption() const;
const std::shared_ptr<Option>& getOption() const;
const SharedHandle<DownloadContext>& getDownloadContext() const;
const SharedHandle<SegmentMan>& getSegmentMan() const;
const SharedHandle<PieceStorage>& getPieceStorage() const;
const std::shared_ptr<DownloadContext>& getDownloadContext() const;
const std::shared_ptr<SegmentMan>& getSegmentMan() const;
const std::shared_ptr<PieceStorage>& getPieceStorage() const;
Timer& getCheckPoint()
{
@ -235,12 +235,12 @@ protected:
public:
AbstractCommand
(cuid_t cuid, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
(cuid_t cuid, const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup, DownloadEngine* e,
const SharedHandle<SocketCore>& s = SharedHandle<SocketCore>(),
const SharedHandle<SocketRecvBuffer>& socketRecvBuffer
= SharedHandle<SocketRecvBuffer>(),
const std::shared_ptr<SocketCore>& s = std::shared_ptr<SocketCore>(),
const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer
= std::shared_ptr<SocketRecvBuffer>(),
bool incNumConnection = true);
virtual ~AbstractCommand();

View File

@ -49,9 +49,9 @@ namespace aria2 {
AbstractHttpServerResponseCommand::AbstractHttpServerResponseCommand
(cuid_t cuid,
const SharedHandle<HttpServer>& httpServer,
const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
const SharedHandle<SocketCore>& socket)
const std::shared_ptr<SocketCore>& socket)
: Command(cuid),
e_(e),
socket_(socket),
@ -107,20 +107,21 @@ bool AbstractHttpServerResponseCommand::execute()
}
} catch(RecoverableException& e) {
A2_LOG_INFO_EX
(fmt("CUID#%"PRId64" - Error occurred while transmitting response body.",
(fmt("CUID#%" PRId64
" - Error occurred while transmitting response body.",
getCuid()),
e);
return true;
}
if(httpServer_->sendBufferIsEmpty()) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - HttpServer: all response transmitted.",
A2_LOG_INFO(fmt("CUID#%" PRId64 " - HttpServer: all response transmitted.",
getCuid()));
afterSend(httpServer_, e_);
return true;
} else {
if(timeoutTimer_.difference(global::wallclock()) >= 30) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - HttpServer: Timeout while trasmitting"
" response.",
A2_LOG_INFO(fmt("CUID#%" PRId64
" - HttpServer: Timeout while trasmitting response.",
getCuid()));
return true;
} else {

View File

@ -36,7 +36,9 @@
#define D_ABSTRACT_HTTP_SERVER_RESPONSE_COMMAND_H
#include "Command.h"
#include "SharedHandle.h"
#include <memory>
#include "TimerA2.h"
namespace aria2 {
@ -48,8 +50,8 @@ class HttpServer;
class AbstractHttpServerResponseCommand : public Command {
private:
DownloadEngine* e_;
SharedHandle<SocketCore> socket_;
SharedHandle<HttpServer> httpServer_;
std::shared_ptr<SocketCore> socket_;
std::shared_ptr<HttpServer> httpServer_;
Timer timeoutTimer_;
bool readCheck_;
bool writeCheck_;
@ -61,13 +63,13 @@ protected:
return e_;
}
// Called after content body is completely sent.
virtual void afterSend(const SharedHandle<HttpServer>& httpServer,
virtual void afterSend(const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e) = 0;
public:
AbstractHttpServerResponseCommand(cuid_t cuid,
const SharedHandle<HttpServer>& httpServer,
const std::shared_ptr<HttpServer>& httpServer,
DownloadEngine* e,
const SharedHandle<SocketCore>& socket);
const std::shared_ptr<SocketCore>& socket);
virtual ~AbstractHttpServerResponseCommand();

View File

@ -51,18 +51,18 @@ namespace aria2 {
AbstractProxyRequestCommand::AbstractProxyRequestCommand
(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s)
const std::shared_ptr<Request>& proxyRequest,
const std::shared_ptr<SocketCore>& s)
:
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
proxyRequest_(proxyRequest),
httpConnection_
(new HttpConnection
(cuid, s, SharedHandle<SocketRecvBuffer>(new SocketRecvBuffer(s))))
(cuid, s, std::shared_ptr<SocketRecvBuffer>(new SocketRecvBuffer(s))))
{
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket();
@ -74,7 +74,7 @@ AbstractProxyRequestCommand::~AbstractProxyRequestCommand() {}
bool AbstractProxyRequestCommand::executeInternal() {
//socket->setBlockingMode();
if(httpConnection_->sendBufferIsEmpty()) {
SharedHandle<HttpRequest> httpRequest(new HttpRequest());
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
httpRequest->setRequest(getRequest());
httpRequest->setProxyRequest(proxyRequest_);

View File

@ -44,29 +44,29 @@ class SocketCore;
class AbstractProxyRequestCommand : public AbstractCommand {
private:
SharedHandle<Request> proxyRequest_;
std::shared_ptr<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_;
std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool executeInternal();
const SharedHandle<HttpConnection>& getHttpConnection() const
const std::shared_ptr<HttpConnection>& getHttpConnection() const
{
return httpConnection_;
}
const SharedHandle<Request>& getProxyRequest() const
const std::shared_ptr<Request>& getProxyRequest() const
{
return proxyRequest_;
}
public:
AbstractProxyRequestCommand(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s);
const std::shared_ptr<Request>& proxyRequest,
const std::shared_ptr<SocketCore>& s);
virtual ~AbstractProxyRequestCommand();

View File

@ -52,19 +52,19 @@ namespace aria2 {
AbstractProxyResponseCommand::AbstractProxyResponseCommand
(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
const SharedHandle<HttpConnection>& httpConnection,
const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
const SharedHandle<SocketCore>& s)
const std::shared_ptr<SocketCore>& s)
:AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
httpConnection_(httpConnection) {}
AbstractProxyResponseCommand::~AbstractProxyResponseCommand() {}
bool AbstractProxyResponseCommand::executeInternal() {
SharedHandle<HttpResponse> httpResponse = httpConnection_->receiveResponse();
std::shared_ptr<HttpResponse> httpResponse = httpConnection_->receiveResponse();
if(!httpResponse) {
// the server has not responded our request yet.
getDownloadEngine()->addCommand(this);

View File

@ -44,23 +44,23 @@ class SocketCore;
class AbstractProxyResponseCommand : public AbstractCommand {
private:
SharedHandle<HttpConnection> httpConnection_;
std::shared_ptr<HttpConnection> httpConnection_;
protected:
virtual bool executeInternal();
const SharedHandle<HttpConnection>& getHttpConnection() const
const std::shared_ptr<HttpConnection>& getHttpConnection() const
{
return httpConnection_;
}
public:
AbstractProxyResponseCommand
(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
const SharedHandle<HttpConnection>& httpConnection,
const std::shared_ptr<HttpConnection>& httpConnection,
DownloadEngine* e,
const SharedHandle<SocketCore>& s);
const std::shared_ptr<SocketCore>& s);
virtual ~AbstractProxyResponseCommand();

View File

@ -97,7 +97,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
for(WrDiskCacheEntry::DataCellSet::const_iterator i = dataSet.begin(),
eoi = dataSet.end(); i != eoi; ++i) {
if(start+static_cast<ssize_t>(buflen) < (*i)->goff) {
A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
start = (*i)->goff;
@ -105,7 +105,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
}
if(buflen == 0 && ((*i)->goff & 0xfff) == 0 && ((*i)->len & 0xfff) == 0) {
// Already aligned. Write it without copy.
A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>((*i)->len)));
writeData((*i)->data + (*i)->offset, (*i)->len, start);
start += (*i)->len;
@ -117,7 +117,7 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
memcpy(buf+buflen, (*i)->data+(*i)->offset, wlen);
buflen += wlen;
if(buflen == sizeof(buf)) {
A2_LOG_DEBUG(fmt("Cache flush goff=%"PRId64", len=%lu",
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
memcpy(buf, (*i)->data + (*i)->offset + wlen, (*i)->len - wlen);
@ -145,26 +145,26 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length)
diskWriter_->truncate(length);
}
SharedHandle<FileAllocationIterator>
std::shared_ptr<FileAllocationIterator>
AbstractSingleDiskAdaptor::fileAllocationIterator()
{
switch(getFileAllocationMethod()) {
#ifdef HAVE_SOME_FALLOCATE
case(DiskAdaptor::FILE_ALLOC_FALLOC): {
SharedHandle<FallocFileAllocationIterator> h
std::shared_ptr<FallocFileAllocationIterator> h
(new FallocFileAllocationIterator
(diskWriter_.get(), size() ,totalLength_));
return h;
}
#endif // HAVE_SOME_FALLOCATE
case(DiskAdaptor::FILE_ALLOC_TRUNC): {
SharedHandle<TruncFileAllocationIterator> h
std::shared_ptr<TruncFileAllocationIterator> h
(new TruncFileAllocationIterator
(diskWriter_.get(), size(), totalLength_));
return h;
}
default: {
SharedHandle<AdaptiveFileAllocationIterator> h
std::shared_ptr<AdaptiveFileAllocationIterator> h
(new AdaptiveFileAllocationIterator
(diskWriter_.get(), size(), totalLength_));
return h;
@ -197,7 +197,7 @@ void AbstractSingleDiskAdaptor::cutTrailingGarbage()
}
void AbstractSingleDiskAdaptor::setDiskWriter
(const SharedHandle<DiskWriter>& diskWriter)
(const std::shared_ptr<DiskWriter>& diskWriter)
{
diskWriter_ = diskWriter;
}

View File

@ -44,7 +44,7 @@ class FileAllocationIterator;
class AbstractSingleDiskAdaptor : public DiskAdaptor {
private:
SharedHandle<DiskWriter> diskWriter_;
std::shared_ptr<DiskWriter> diskWriter_;
int64_t totalLength_;
bool readOnly_;
public:
@ -73,7 +73,7 @@ public:
virtual void truncate(int64_t length);
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
virtual std::shared_ptr<FileAllocationIterator> fileAllocationIterator();
// Make sure that DiskWriter is set before calling this function.
virtual void enableReadOnly();
@ -89,9 +89,9 @@ public:
virtual const std::string& getFilePath() = 0;
void setDiskWriter(const SharedHandle<DiskWriter>& diskWriter);
void setDiskWriter(const std::shared_ptr<DiskWriter>& diskWriter);
const SharedHandle<DiskWriter>& getDiskWriter() const
const std::shared_ptr<DiskWriter>& getDiskWriter() const
{
return diskWriter_;
}

View File

@ -131,7 +131,7 @@ void ActivePeerConnectionCommand::makeNewConnections(int num)
{
for(; num && peerStorage_->isPeerAvailable(); --num) {
cuid_t ncuid = e_->newCUID();
SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid);
std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
// sanity check
if(!peer) {
break;
@ -148,25 +148,25 @@ void ActivePeerConnectionCommand::makeNewConnections(int num)
}
void ActivePeerConnectionCommand::setBtRuntime
(const SharedHandle<BtRuntime>& btRuntime)
(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void ActivePeerConnectionCommand::setPieceStorage
(const SharedHandle<PieceStorage>& pieceStorage)
(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}
void ActivePeerConnectionCommand::setPeerStorage
(const SharedHandle<PeerStorage>& peerStorage)
(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}
void ActivePeerConnectionCommand::setBtAnnounce
(const SharedHandle<BtAnnounce>& btAnnounce)
(const std::shared_ptr<BtAnnounce>& btAnnounce)
{
btAnnounce_ = btAnnounce;
}

View File

@ -36,7 +36,9 @@
#define D_ACTIVE_PEER_CONNECTION_COMMAND_H
#include "Command.h"
#include "SharedHandle.h"
#include <memory>
#include "TimerA2.h"
namespace aria2 {
@ -52,10 +54,10 @@ class BtAnnounce;
class ActivePeerConnectionCommand : public Command {
private:
RequestGroup* requestGroup_;
SharedHandle<BtRuntime> btRuntime_;
SharedHandle<PieceStorage> pieceStorage_;
SharedHandle<PeerStorage> peerStorage_;
SharedHandle<BtAnnounce> btAnnounce_;
std::shared_ptr<BtRuntime> btRuntime_;
std::shared_ptr<PieceStorage> pieceStorage_;
std::shared_ptr<PeerStorage> peerStorage_;
std::shared_ptr<BtAnnounce> btAnnounce_;
time_t interval_; // UNIT: sec
DownloadEngine* e_;
@ -78,13 +80,13 @@ public:
numNewConnection_ = numNewConnection;
}
void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime);
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage);
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage);
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
void setBtAnnounce(const SharedHandle<BtAnnounce>& btAnnounce);
void setBtAnnounce(const std::shared_ptr<BtAnnounce>& btAnnounce);
};
} // namespace aria2

View File

@ -70,13 +70,13 @@ void AdaptiveFileAllocationIterator::allocateChunk()
(new FallocFileAllocationIterator(stream_, offset_, totalLength_));
} catch(RecoverableException& e) {
A2_LOG_DEBUG("File system does not support fallocate.");
SharedHandle<SingleFileAllocationIterator> salloc
std::shared_ptr<SingleFileAllocationIterator> salloc
(new SingleFileAllocationIterator(stream_, offset_, totalLength_));
salloc->init();
allocator_ = salloc;
}
#else // !HAVE_FALLOCATE
SharedHandle<SingleFileAllocationIterator> salloc
std::shared_ptr<SingleFileAllocationIterator> salloc
(new SingleFileAllocationIterator(stream_, offset_, totalLength_));
salloc->init();
allocator_ = salloc;

View File

@ -37,6 +37,8 @@
#include "FileAllocationIterator.h"
#include <memory>
namespace aria2 {
class BinaryStream;
@ -44,7 +46,7 @@ class BinaryStream;
class AdaptiveFileAllocationIterator:public FileAllocationIterator
{
private:
SharedHandle<FileAllocationIterator> allocator_;
std::shared_ptr<FileAllocationIterator> allocator_;
BinaryStream* stream_;

View File

@ -66,7 +66,7 @@ namespace aria2 {
*/
AdaptiveURISelector::AdaptiveURISelector
(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
(const std::shared_ptr<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
: serverStatMan_(serverStatMan),
requestGroup_(requestGroup)
{
@ -242,7 +242,7 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
}
namespace {
int getUriMaxSpeed(SharedHandle<ServerStat> ss)
int getUriMaxSpeed(std::shared_ptr<ServerStat> ss)
{
return std::max(ss->getSingleConnectionAvgSpeed(),
ss->getMultiConnectionAvgSpeed());
@ -265,7 +265,7 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
std::string uri = A2STR::NIL;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
@ -287,7 +287,7 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
std::deque<std::string> bests;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
if(ss->getSingleConnectionAvgSpeed() > min ||
@ -312,7 +312,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);
std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
return *i;
}
@ -326,7 +326,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
int power;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
continue;
counter = ss->getCounter();
@ -342,7 +342,7 @@ std::string AdaptiveURISelector::getFirstToTestUri
return A2STR::NIL;
}
SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
std::shared_ptr<ServerStat> AdaptiveURISelector::getServerStats
(const std::string& uri) const
{
uri_split_result us;
@ -351,7 +351,7 @@ SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
std::string protocol = uri::getFieldString(us, USR_SCHEME, uri.c_str());
return serverStatMan_->find(host, protocol);
} else {
return SharedHandle<ServerStat>();
return std::shared_ptr<ServerStat>();
}
}
@ -361,7 +361,7 @@ int AdaptiveURISelector::getNbTestedServers
int counter = 0;
for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) {
SharedHandle<ServerStat> ss = getServerStats(*i);
std::shared_ptr<ServerStat> ss = getServerStats(*i);
if(!ss)
++counter;
}

View File

@ -36,7 +36,8 @@
#ifndef D_ADAPTIVE_URI_SELECTOR_H
#define D_ADAPTIVE_URI_SELECTOR_H
#include "URISelector.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -46,7 +47,7 @@ class ServerStat;
class AdaptiveURISelector:public URISelector {
private:
SharedHandle<ServerStatMan> serverStatMan_;
std::shared_ptr<ServerStatMan> serverStatMan_;
// No need to delete requestGroup_
RequestGroup* requestGroup_;
int nbServerToEvaluate_;
@ -66,11 +67,11 @@ private:
std::string selectRandomUri(const std::deque<std::string>& uris) const;
std::string getFirstNotTestedUri(const std::deque<std::string>& uris) const;
std::string getFirstToTestUri(const std::deque<std::string>& uris) const;
SharedHandle<ServerStat> getServerStats(const std::string& uri) const;
std::shared_ptr<ServerStat> getServerStats(const std::string& uri) const;
int getNbTestedServers(const std::deque<std::string>& uris) const;
std::string getBestMirror(const std::deque<std::string>& uris) const;
public:
AdaptiveURISelector(const SharedHandle<ServerStatMan>& serverStatMan,
AdaptiveURISelector(const std::shared_ptr<ServerStatMan>& serverStatMan,
RequestGroup* requestGroup);
virtual ~AdaptiveURISelector();

View File

@ -51,7 +51,7 @@ AnnounceList::AnnounceList
}
AnnounceList::AnnounceList
(const std::deque<SharedHandle<AnnounceTier> >& announceTiers):
(const std::deque<std::shared_ptr<AnnounceTier> >& announceTiers):
tiers_(announceTiers), currentTrackerInitialized_(false) {
resetIterator();
}
@ -67,7 +67,7 @@ void AnnounceList::reconfigure
continue;
}
std::deque<std::string> urls((*itr).begin(), (*itr).end());
SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
std::shared_ptr<AnnounceTier> tier(new AnnounceTier(urls));
tiers_.push_back(tier);
}
resetIterator();
@ -76,7 +76,7 @@ void AnnounceList::reconfigure
void AnnounceList::reconfigure(const std::string& url) {
std::deque<std::string> urls;
urls.push_back(url);
SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
std::shared_ptr<AnnounceTier> tier(new AnnounceTier(urls));
tiers_.push_back(tier);
resetIterator();
}
@ -161,7 +161,7 @@ const char* AnnounceList::getEventString() const {
namespace {
class FindStoppedAllowedTier {
public:
bool operator()(const SharedHandle<AnnounceTier>& tier) const {
bool operator()(const std::shared_ptr<AnnounceTier>& tier) const {
switch(tier->event) {
case AnnounceTier::DOWNLOADING:
case AnnounceTier::STOPPED:
@ -178,7 +178,7 @@ public:
namespace {
class FindCompletedAllowedTier {
public:
bool operator()(const SharedHandle<AnnounceTier>& tier) const {
bool operator()(const std::shared_ptr<AnnounceTier>& tier) const {
switch(tier->event) {
case AnnounceTier::DOWNLOADING:
case AnnounceTier::COMPLETED:
@ -199,7 +199,7 @@ size_t AnnounceList::countCompletedAllowedTier() const {
}
void AnnounceList::setCurrentTier
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr) {
(const std::deque<std::shared_ptr<AnnounceTier> >::iterator& itr) {
if(itr != tiers_.end()) {
currentTier_ = itr;
currentTracker_ = (*currentTier_)->urls.begin();
@ -207,7 +207,7 @@ void AnnounceList::setCurrentTier
}
void AnnounceList::moveToStoppedAllowedTier() {
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
std::deque<std::shared_ptr<AnnounceTier> >::iterator itr =
find_wrap_if(tiers_.begin(), tiers_.end(),
currentTier_,
FindStoppedAllowedTier());
@ -215,7 +215,7 @@ void AnnounceList::moveToStoppedAllowedTier() {
}
void AnnounceList::moveToCompletedAllowedTier() {
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
std::deque<std::shared_ptr<AnnounceTier> >::iterator itr =
find_wrap_if(tiers_.begin(), tiers_.end(),
currentTier_,
FindCompletedAllowedTier());
@ -223,7 +223,7 @@ void AnnounceList::moveToCompletedAllowedTier() {
}
void AnnounceList::shuffle() {
for(std::deque<SharedHandle<AnnounceTier> >::const_iterator itr =
for(std::deque<std::shared_ptr<AnnounceTier> >::const_iterator itr =
tiers_.begin(), eoi = tiers_.end(); itr != eoi; ++itr) {
std::deque<std::string>& urls = (*itr)->urls;
std::random_shuffle(urls.begin(), urls.end(),

View File

@ -36,7 +36,9 @@
#define D_ANNOUNCE_LIST_H
#include "common.h"
#include "SharedHandle.h"
#include <memory>
#include "AnnounceTier.h"
#include "ValueBase.h"
@ -45,18 +47,18 @@ namespace aria2 {
class AnnounceList {
public:
private:
std::deque<SharedHandle<AnnounceTier> > tiers_;
std::deque<SharedHandle<AnnounceTier> >::iterator currentTier_;
std::deque<std::shared_ptr<AnnounceTier> > tiers_;
std::deque<std::shared_ptr<AnnounceTier> >::iterator currentTier_;
std::deque<std::string>::iterator currentTracker_;
bool currentTrackerInitialized_;
void resetIterator();
void setCurrentTier
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
(const std::deque<std::shared_ptr<AnnounceTier> >::iterator& itr);
public:
AnnounceList();
AnnounceList(const std::vector<std::vector<std::string> >& announceList);
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
AnnounceList(const std::deque<std::shared_ptr<AnnounceTier> >& tiers);
~AnnounceList();
// Don't allow copying

View File

@ -40,8 +40,6 @@
#include <string>
#include <deque>
#include "SharedHandle.h"
namespace aria2 {
class AnnounceTier {

View File

@ -47,9 +47,9 @@ public:
AnonDiskWriterFactory() {}
virtual ~AnonDiskWriterFactory() {}
virtual SharedHandle<DiskWriter> newDiskWriter(const std::string& filename)
virtual std::shared_ptr<DiskWriter> newDiskWriter(const std::string& filename)
{
return SharedHandle<DiskWriter>(new DiskWriterType());
return std::shared_ptr<DiskWriter>(new DiskWriterType());
}
};

View File

@ -108,33 +108,33 @@ typedef MessageDigestBase<CC_SHA512_DIGEST_LENGTH,
CC_SHA512_Final>
MessageDigestSHA512;
SharedHandle<MessageDigestImpl> MessageDigestImpl::sha1()
std::shared_ptr<MessageDigestImpl> MessageDigestImpl::sha1()
{
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA1());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA1());
}
SharedHandle<MessageDigestImpl> MessageDigestImpl::create
std::shared_ptr<MessageDigestImpl> MessageDigestImpl::create
(const std::string& hashType)
{
if (hashType == "sha-1") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA1());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA1());
}
if (hashType == "sha-224") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA224());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA224());
}
if (hashType == "sha-256") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA256());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA256());
}
if (hashType == "sha-384") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA384());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA384());
}
if (hashType == "sha-512") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA512());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA512());
}
if (hashType == "md5") {
return SharedHandle<MessageDigestImpl>(new MessageDigestMD5());
return std::shared_ptr<MessageDigestImpl>(new MessageDigestMD5());
}
return SharedHandle<MessageDigestImpl>();
return std::shared_ptr<MessageDigestImpl>();
}
bool MessageDigestImpl::supports(const std::string& hashType)
@ -144,7 +144,7 @@ bool MessageDigestImpl::supports(const std::string& hashType)
size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{
SharedHandle<MessageDigestImpl> impl = create(hashType);
std::shared_ptr<MessageDigestImpl> impl = create(hashType);
if (!impl) {
return 0;
}

View File

@ -38,16 +38,15 @@
#include "common.h"
#include <string>
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
class MessageDigestImpl {
public:
virtual ~MessageDigestImpl() {}
static SharedHandle<MessageDigestImpl> sha1();
static SharedHandle<MessageDigestImpl> create(const std::string& hashType);
static std::shared_ptr<MessageDigestImpl> sha1();
static std::shared_ptr<MessageDigestImpl> create(const std::string& hashType);
static bool supports(const std::string& hashType);
static size_t getDigestLength(const std::string& hashType);

View File

@ -42,7 +42,6 @@
#include <ares.h>
#include "SharedHandle.h"
#include "a2netcompat.h"
namespace aria2 {

View File

@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "AsyncNameResolverMan.h"
#include <cassert>
#include "AsyncNameResolver.h"
#include "DownloadEngine.h"
#include "Command.h"

View File

@ -39,8 +39,7 @@
#include <vector>
#include <string>
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -97,7 +96,7 @@ private:
void disableNameResolverCheck(size_t index, DownloadEngine* e,
Command* command);
SharedHandle<AsyncNameResolver> asyncNameResolver_[2];
std::shared_ptr<AsyncNameResolver> asyncNameResolver_[2];
size_t numResolver_;
int resolverCheck_;
bool ipv4_;

View File

@ -58,7 +58,7 @@ std::string AuthConfig::getAuthText() const
}
std::ostream& operator<<(std::ostream& o,
const SharedHandle<AuthConfig>& authConfig)
const std::shared_ptr<AuthConfig>& authConfig)
{
o << authConfig->getAuthText();
return o;

View File

@ -39,8 +39,7 @@
#include <string>
#include <iosfwd>
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -72,7 +71,7 @@ public:
};
std::ostream& operator<<(std::ostream& o,
const SharedHandle<AuthConfig>& authConfig);
const std::shared_ptr<AuthConfig>& authConfig);
} // namespace aria2

View File

@ -56,15 +56,15 @@ AuthConfigFactory::AuthConfigFactory() {}
AuthConfigFactory::~AuthConfigFactory() {}
SharedHandle<AuthConfig>
std::shared_ptr<AuthConfig>
AuthConfigFactory::createAuthConfig
(const SharedHandle<Request>& request, const Option* op)
(const std::shared_ptr<Request>& request, const Option* op)
{
if(request->getProtocol() == "http" || request->getProtocol() == "https") {
if(op->getAsBool(PREF_HTTP_AUTH_CHALLENGE)) {
if(!request->getUsername().empty()) {
SharedHandle<BasicCred> bc(new BasicCred(request->getUsername(),
std::shared_ptr<BasicCred> bc(new BasicCred(request->getUsername(),
request->getPassword(),
request->getHost(),
request->getPort(),
@ -76,7 +76,7 @@ AuthConfigFactory::createAuthConfig
findBasicCred(request->getHost(), request->getPort(),
request->getDir());
if(i == basicCreds_.end()) {
return SharedHandle<AuthConfig>();
return std::shared_ptr<AuthConfig>();
} else {
return createAuthConfig((*i)->user_, (*i)->password_);
}
@ -99,7 +99,7 @@ AuthConfigFactory::createAuthConfig
NetrcAuthResolver authResolver;
authResolver.setNetrc(netrc_);
SharedHandle<AuthConfig> ac =
std::shared_ptr<AuthConfig> ac =
authResolver.resolveAuthConfig(request->getHost());
if(ac && ac->getUser() == request->getUsername()) {
return ac;
@ -115,21 +115,21 @@ AuthConfigFactory::createAuthConfig
createFtpAuthResolver(op)->resolveAuthConfig(request->getHost());
}
} else {
return SharedHandle<AuthConfig>();
return std::shared_ptr<AuthConfig>();
}
}
SharedHandle<AuthConfig>
std::shared_ptr<AuthConfig>
AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
{
SharedHandle<AuthConfig> ac;
std::shared_ptr<AuthConfig> ac;
if(!user.empty()) {
ac.reset(new AuthConfig(user, password));
}
return ac;
}
SharedHandle<AuthResolver> AuthConfigFactory::createHttpAuthResolver
std::shared_ptr<AuthResolver> AuthConfigFactory::createHttpAuthResolver
(const Option* op) const
{
AbstractAuthResolver* resolver;
@ -143,10 +143,10 @@ SharedHandle<AuthResolver> AuthConfigFactory::createHttpAuthResolver
}
resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_HTTP_USER), op->get(PREF_HTTP_PASSWD)));
return SharedHandle<AuthResolver>(resolver);
return std::shared_ptr<AuthResolver>(resolver);
}
SharedHandle<AuthResolver> AuthConfigFactory::createFtpAuthResolver
std::shared_ptr<AuthResolver> AuthConfigFactory::createFtpAuthResolver
(const Option* op) const
{
AbstractAuthResolver* resolver;
@ -159,19 +159,19 @@ SharedHandle<AuthResolver> AuthConfigFactory::createFtpAuthResolver
}
resolver->setUserDefinedAuthConfig
(createAuthConfig(op->get(PREF_FTP_USER), op->get(PREF_FTP_PASSWD)));
SharedHandle<AuthConfig> defaultAuthConfig
std::shared_ptr<AuthConfig> defaultAuthConfig
(new AuthConfig(AUTH_DEFAULT_USER, AUTH_DEFAULT_PASSWD));
resolver->setDefaultAuthConfig(defaultAuthConfig);
return SharedHandle<AuthResolver>(resolver);
return std::shared_ptr<AuthResolver>(resolver);
}
void AuthConfigFactory::setNetrc(const SharedHandle<Netrc>& netrc)
void AuthConfigFactory::setNetrc(const std::shared_ptr<Netrc>& netrc)
{
netrc_ = netrc;
}
void AuthConfigFactory::updateBasicCred
(const SharedHandle<BasicCred>& basicCred)
(const std::shared_ptr<BasicCred>& basicCred)
{
BasicCredSet::iterator i = basicCreds_.lower_bound(basicCred);
if(i != basicCreds_.end() && *(*i) == *basicCred) {
@ -189,12 +189,12 @@ bool AuthConfigFactory::activateBasicCred
{
BasicCredSet::iterator i = findBasicCred(host, port, path);
if(i == basicCreds_.end()) {
SharedHandle<AuthConfig> authConfig =
std::shared_ptr<AuthConfig> authConfig =
createHttpAuthResolver(op)->resolveAuthConfig(host);
if(!authConfig) {
return false;
} else {
SharedHandle<BasicCred> bc
std::shared_ptr<BasicCred> bc
(new BasicCred(authConfig->getUser(), authConfig->getPassword(),
host, port, path, true));
basicCreds_.insert(bc);
@ -246,7 +246,7 @@ AuthConfigFactory::findBasicCred
uint16_t port,
const std::string& path)
{
SharedHandle<BasicCred> bc(new BasicCred("", "", host, port, path));
std::shared_ptr<BasicCred> bc(new BasicCred("", "", host, port, path));
BasicCredSet::iterator i = basicCreds_.lower_bound(bc);
for(; i != basicCreds_.end() && (*i)->host_ == host && (*i)->port_ == port;
++i) {

View File

@ -39,8 +39,8 @@
#include <string>
#include <set>
#include <memory>
#include "SharedHandle.h"
#include "SingletonHolder.h"
#include "a2functional.h"
@ -54,14 +54,14 @@ class AuthResolver;
class AuthConfigFactory {
private:
SharedHandle<Netrc> netrc_;
std::shared_ptr<Netrc> netrc_;
SharedHandle<AuthConfig> createAuthConfig(const std::string& user,
std::shared_ptr<AuthConfig> createAuthConfig(const std::string& user,
const std::string& password) const;
SharedHandle<AuthResolver> createHttpAuthResolver(const Option* op) const;
std::shared_ptr<AuthResolver> createHttpAuthResolver(const Option* op) const;
SharedHandle<AuthResolver> createFtpAuthResolver(const Option* op) const;
std::shared_ptr<AuthResolver> createFtpAuthResolver(const Option* op) const;
public:
class BasicCred {
public:
@ -85,8 +85,8 @@ public:
bool operator<(const BasicCred& cred) const;
};
typedef std::set<SharedHandle<BasicCred>,
DerefLess<SharedHandle<BasicCred> > > BasicCredSet;
typedef std::set<std::shared_ptr<BasicCred>,
DerefLess<std::shared_ptr<BasicCred> > > BasicCredSet;
private:
BasicCredSet basicCreds_;
public:
@ -98,10 +98,10 @@ public:
// are used in this method: PREF_HTTP_USER, PREF_HTTP_PASSWD,
// PREF_FTP_USER, PREF_FTP_PASSWD, PREF_NO_NETRC and
// PREF_HTTP_AUTH_CHALLENGE.
SharedHandle<AuthConfig> createAuthConfig
(const SharedHandle<Request>& request, const Option* op);
std::shared_ptr<AuthConfig> createAuthConfig
(const std::shared_ptr<Request>& request, const Option* op);
void setNetrc(const SharedHandle<Netrc>& netrc);
void setNetrc(const std::shared_ptr<Netrc>& netrc);
// Find a BasicCred using findBasicCred() and activate it then
// return true. If matching BasicCred is not found, AuthConfig
@ -127,7 +127,7 @@ public:
// If the same BasicCred is already added, then it is replaced with
// given basicCred. Otherwise, insert given basicCred to
// basicCreds_.
void updateBasicCred(const SharedHandle<BasicCred>& basicCred);
void updateBasicCred(const std::shared_ptr<BasicCred>& basicCred);
};
} // namespace aria2

View File

@ -38,8 +38,7 @@
#include "common.h"
#include <string>
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -49,7 +48,7 @@ class AuthResolver {
public:
virtual ~AuthResolver() {}
virtual SharedHandle<AuthConfig> resolveAuthConfig(const std::string& hostname) = 0;
virtual std::shared_ptr<AuthConfig> resolveAuthConfig(const std::string& hostname) = 0;
};
} // namespace aria2

View File

@ -51,7 +51,7 @@ BackupConnectInfo::BackupConnectInfo()
BackupIPv4ConnectCommand::BackupIPv4ConnectCommand
(cuid_t cuid, const std::string& ipaddr, uint16_t port,
const SharedHandle<BackupConnectInfo>& info, Command* mainCommand,
const std::shared_ptr<BackupConnectInfo>& info, Command* mainCommand,
RequestGroup* requestGroup, DownloadEngine* e)
: Command(cuid),
ipaddr_(ipaddr),
@ -83,14 +83,15 @@ bool BackupIPv4ConnectCommand::execute()
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
retval = true;
} else if(info_->cancel) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection canceled", getCuid()));
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection canceled",
getCuid()));
retval = true;
} else if(socket_) {
if(writeEventEnabled()) {
try {
std::string error = socket_->getSocketError();
if(error.empty()) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection to %s "
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection to %s "
"established", getCuid(), ipaddr_.c_str()));
info_->ipaddr = ipaddr_;
e_->deleteSocketForWriteCheck(socket_, this);
@ -99,12 +100,12 @@ bool BackupIPv4ConnectCommand::execute()
e_->setNoWait(true);
retval = true;
} else {
A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection failed: %s",
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection failed: %s",
getCuid(), error.c_str()));
retval = true;
}
} catch(RecoverableException& e) {
A2_LOG_INFO_EX(fmt("CUID#%"PRId64" - Backup connection failed",
A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Backup connection failed",
getCuid()), e);
retval = true;
}
@ -120,14 +121,14 @@ bool BackupIPv4ConnectCommand::execute()
e_->addSocketForWriteCheck(socket_, this);
timeoutCheck_ = global::wallclock();
} catch(RecoverableException& e) {
A2_LOG_INFO_EX(fmt("CUID#%"PRId64" - Backup connection failed",
A2_LOG_INFO_EX(fmt("CUID#%" PRId64 " - Backup connection failed",
getCuid()), e);
socket_.reset();
retval = true;
}
}
} else if(timeoutCheck_.difference(global::wallclock()) >= timeout_) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - Backup connection command timeout",
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Backup connection command timeout",
getCuid()));
retval = true;
}

View File

@ -38,8 +38,8 @@
#include "Command.h"
#include <string>
#include <memory>
#include "SharedHandle.h"
#include "TimerA2.h"
namespace aria2 {
@ -55,7 +55,7 @@ class SocketCore;
// member becomes true.
struct BackupConnectInfo {
std::string ipaddr;
SharedHandle<SocketCore> socket;
std::shared_ptr<SocketCore> socket;
bool cancel;
BackupConnectInfo();
};
@ -66,7 +66,7 @@ class BackupIPv4ConnectCommand : public Command {
public:
BackupIPv4ConnectCommand(cuid_t cuid,
const std::string& ipaddr, uint16_t port,
const SharedHandle<BackupConnectInfo>& info,
const std::shared_ptr<BackupConnectInfo>& info,
Command* mainCommand,
RequestGroup* requestGroup, DownloadEngine* e);
~BackupIPv4ConnectCommand();
@ -74,8 +74,8 @@ public:
private:
std::string ipaddr_;
uint16_t port_;
SharedHandle<SocketCore> socket_;
SharedHandle<BackupConnectInfo> info_;
std::shared_ptr<SocketCore> socket_;
std::shared_ptr<BackupConnectInfo> info_;
Command* mainCommand_;
RequestGroup* requestGroup_;
DownloadEngine* e_;

View File

@ -33,6 +33,9 @@
*/
/* copyright --> */
#include "BencodeParser.h"
#include <cassert>
#include "StructParserStateMachine.h"
#include "util.h"

View File

@ -39,8 +39,6 @@
#include <vector>
#include "SharedHandle.h"
namespace aria2 {
class BitfieldMan {

View File

@ -38,7 +38,7 @@
namespace aria2 {
BtAbortOutstandingRequestEvent::BtAbortOutstandingRequestEvent
(const SharedHandle<Piece>& piece)
(const std::shared_ptr<Piece>& piece)
: piece_(piece)
{}

View File

@ -36,7 +36,8 @@
#define D_BT_ABORT_OUTSTANDING_REQUEST_EVENT_H
#include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -44,12 +45,12 @@ class Piece;
class BtAbortOutstandingRequestEvent {
private:
SharedHandle<Piece> piece_;
std::shared_ptr<Piece> piece_;
public:
BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece);
BtAbortOutstandingRequestEvent(const std::shared_ptr<Piece>& piece);
~BtAbortOutstandingRequestEvent();
const SharedHandle<Piece>& getPiece() const { return piece_; }
const std::shared_ptr<Piece>& getPiece() const { return piece_; }
};
} // namespace aria2

View File

@ -65,7 +65,7 @@ void BtAllowedFastMessage::doReceivedAction() {
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
ThisProgressUpdate(const SharedHandle<Peer>& peer, size_t index)
ThisProgressUpdate(const std::shared_ptr<Peer>& peer, size_t index)
: peer(peer), index(index) {}
virtual void update(size_t length, bool complete)
{
@ -73,7 +73,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->addAmAllowedIndex(index);
}
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
size_t index;
};
} // namespace

View File

@ -38,9 +38,9 @@
#include "common.h"
#include <string>
#include <memory>
#include "a2time.h"
#include "SharedHandle.h"
namespace aria2 {
@ -68,7 +68,7 @@ public:
*/
virtual std::string getAnnounceUrl() = 0;
virtual SharedHandle<UDPTrackerRequest>
virtual std::shared_ptr<UDPTrackerRequest>
createUDPTrackerRequest(const std::string& remoteAddr, uint16_t remotePort,
uint16_t localPort) = 0;
@ -104,7 +104,7 @@ public:
size_t trackerResponseLength) = 0;
virtual void processUDPTrackerResponse
(const SharedHandle<UDPTrackerRequest>& req) = 0;
(const std::shared_ptr<UDPTrackerRequest>& req) = 0;
/**
* Returns true if no more announce is needed.

View File

@ -51,19 +51,19 @@ BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
void BtCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e)
{
const SharedHandle<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
const std::shared_ptr<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
ps->onDownloadIncomplete();
if(getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY)) {
return;
}
const SharedHandle<DiskAdaptor>& diskAdaptor = ps->getDiskAdaptor();
const std::shared_ptr<DiskAdaptor>& diskAdaptor = ps->getDiskAdaptor();
if(diskAdaptor->isReadOnlyEnabled()) {
// Now reopen DiskAdaptor with read only disabled.
diskAdaptor->closeFile();
diskAdaptor->disableReadOnly();
diskAdaptor->openFile();
}
SharedHandle<BtFileAllocationEntry> entry
std::shared_ptr<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e);
}
@ -77,7 +77,7 @@ void BtCheckIntegrityEntry::onDownloadFinished
// behavior.
if(!getRequestGroup()->getOption()->getAsBool(PREF_HASH_CHECK_ONLY) &&
getRequestGroup()->getOption()->getAsBool(PREF_BT_HASH_CHECK_SEED)) {
SharedHandle<BtFileAllocationEntry> entry
std::shared_ptr<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e);
}

View File

@ -67,7 +67,7 @@ bool BtChokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
ThisProgressUpdate(const SharedHandle<Peer>& peer,
ThisProgressUpdate(const std::shared_ptr<Peer>& peer,
BtMessageDispatcher* disp)
: peer(peer), disp(disp) {}
virtual void update(size_t length, bool complete)
@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
disp->doChokingAction();
}
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
BtMessageDispatcher* disp;
};
} // namespace

View File

@ -54,7 +54,7 @@ namespace aria2 {
BtDependency::BtDependency
(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee)
const std::shared_ptr<RequestGroup>& dependee)
: dependant_(dependant),
dependee_(dependee)
{}
@ -62,8 +62,8 @@ BtDependency::BtDependency
BtDependency::~BtDependency() {}
namespace {
void copyValues(const SharedHandle<FileEntry>& d,
const SharedHandle<FileEntry>& s)
void copyValues(const std::shared_ptr<FileEntry>& d,
const std::shared_ptr<FileEntry>& s)
{
d->setRequested(true);
d->setPath(s->getPath());
@ -77,8 +77,8 @@ void copyValues(const SharedHandle<FileEntry>& d,
namespace {
struct EntryCmp {
bool operator()
(const SharedHandle<FileEntry>& lhs,
const SharedHandle<FileEntry>& rhs) const
(const std::shared_ptr<FileEntry>& lhs,
const std::shared_ptr<FileEntry>& rhs) const
{
return lhs->getOriginalName() < rhs->getOriginalName();
}
@ -91,17 +91,17 @@ bool BtDependency::resolve()
return true;
}
if(dependee_->getNumCommand() == 0 && dependee_->downloadFinished()) {
SharedHandle<RequestGroup> dependee = dependee_;
std::shared_ptr<RequestGroup> dependee = dependee_;
// cut reference here
dependee_.reset();
SharedHandle<DownloadContext> context(new DownloadContext());
std::shared_ptr<DownloadContext> context(new DownloadContext());
try {
SharedHandle<DiskAdaptor> diskAdaptor =
std::shared_ptr<DiskAdaptor> diskAdaptor =
dependee->getPieceStorage()->getDiskAdaptor();
diskAdaptor->openExistingFile();
std::string content = util::toString(diskAdaptor);
if(dependee->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) {
SharedHandle<TorrentAttribute> attrs =
std::shared_ptr<TorrentAttribute> attrs =
bittorrent::getTorrentAttrs(dependee->getDownloadContext());
bittorrent::loadFromMemory
(bittorrent::metadata2Torrent(content, attrs), context,
@ -115,9 +115,9 @@ bool BtDependency::resolve()
bittorrent::adjustAnnounceUri(bittorrent::getTorrentAttrs(context),
dependant_->getOption());
}
const std::vector<SharedHandle<FileEntry> >& fileEntries =
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
context->getFileEntries();
const std::vector<SharedHandle<FileEntry> >& dependantFileEntries =
const std::vector<std::shared_ptr<FileEntry> >& dependantFileEntries =
dependant_->getDownloadContext()->getFileEntries();
// If dependant's FileEntry::getOriginalName() is empty, we
// assume that torrent is single file. In Metalink3, this is
@ -126,9 +126,9 @@ bool BtDependency::resolve()
dependantFileEntries[0]->getOriginalName().empty()) {
copyValues(fileEntries[0], dependantFileEntries[0]);
} else {
std::vector<SharedHandle<FileEntry> > destFiles;
std::vector<std::shared_ptr<FileEntry> > destFiles;
destFiles.reserve(fileEntries.size());
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
for(std::vector<std::shared_ptr<FileEntry> >::const_iterator i =
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
(*i)->setRequested(false);
destFiles.push_back(*i);
@ -137,10 +137,10 @@ bool BtDependency::resolve()
// Copy file path in dependant_'s FileEntries to newly created
// context's FileEntries to endorse the path structure of
// dependant_. URIs and singleHostMultiConnection are also copied.
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
for(std::vector<std::shared_ptr<FileEntry> >::const_iterator s =
dependantFileEntries.begin(), eoi = dependantFileEntries.end();
s != eoi; ++s){
std::vector<SharedHandle<FileEntry> >::const_iterator d =
std::vector<std::shared_ptr<FileEntry> >::const_iterator d =
std::lower_bound(destFiles.begin(), destFiles.end(), *s,
EntryCmp());
if(d == destFiles.end() ||

View File

@ -36,7 +36,8 @@
#define D_BT_DEPENDENCY_H
#include "Dependency.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -47,10 +48,10 @@ class BtDependency : public Dependency
{
private:
RequestGroup* dependant_;
SharedHandle<RequestGroup> dependee_;
std::shared_ptr<RequestGroup> dependee_;
public:
BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee);
const std::shared_ptr<RequestGroup>& dependee);
virtual ~BtDependency();

View File

@ -51,7 +51,7 @@ namespace aria2 {
const char BtExtendedMessage::NAME[] = "extended";
BtExtendedMessage::BtExtendedMessage
(const SharedHandle<ExtensionMessage>& extensionMessage):
(const std::shared_ptr<ExtensionMessage>& extensionMessage):
SimpleBtMessage(ID, NAME),
extensionMessage_(extensionMessage),
msgLength_(0)
@ -97,14 +97,14 @@ std::string BtExtendedMessage::toString() const {
}
BtExtendedMessage*
BtExtendedMessage::create(const SharedHandle<ExtensionMessageFactory>& factory,
const SharedHandle<Peer>& peer,
BtExtendedMessage::create(const std::shared_ptr<ExtensionMessageFactory>& factory,
const std::shared_ptr<Peer>& peer,
const unsigned char* data, size_t dataLength)
{
bittorrent::assertPayloadLengthGreater(1, dataLength, NAME);
bittorrent::assertID(ID, data, NAME);
assert(factory);
SharedHandle<ExtensionMessage> extmsg = factory->createMessage(data+1,
std::shared_ptr<ExtensionMessage> extmsg = factory->createMessage(data+1,
dataLength-1);
BtExtendedMessage* message(new BtExtendedMessage(extmsg));
return message;

View File

@ -44,12 +44,12 @@ class ExtensionMessageFactory;
class BtExtendedMessage:public SimpleBtMessage
{
private:
SharedHandle<ExtensionMessage> extensionMessage_;
std::shared_ptr<ExtensionMessage> extensionMessage_;
size_t msgLength_;
public:
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
SharedHandle<ExtensionMessage>());
BtExtendedMessage(const std::shared_ptr<ExtensionMessage>& extensionMessage =
std::shared_ptr<ExtensionMessage>());
virtual ~BtExtendedMessage();
static const uint8_t ID = 20;
@ -57,8 +57,8 @@ public:
static const char NAME[];
static BtExtendedMessage* create
(const SharedHandle<ExtensionMessageFactory>& factory,
const SharedHandle<Peer>& peer,
(const std::shared_ptr<ExtensionMessageFactory>& factory,
const std::shared_ptr<Peer>& peer,
const unsigned char* data,
size_t dataLength);
@ -72,7 +72,7 @@ public:
virtual std::string toString() const;
const SharedHandle<ExtensionMessage>& getExtensionMessage() const
const std::shared_ptr<ExtensionMessage>& getExtensionMessage() const
{
return extensionMessage_;
}

View File

@ -67,7 +67,7 @@ void BtFileAllocationEntry::prepareForNextAction
// For DownloadContext::resetDownloadStartTime(), see also
// RequestGroup::createInitialCommand()
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
const std::vector<SharedHandle<FileEntry> >& fileEntries =
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
getRequestGroup()->getDownloadContext()->getFileEntries();
if(isUriSuppliedForRequsetFileEntry
(fileEntries.begin(), fileEntries.end())) {
@ -75,7 +75,7 @@ void BtFileAllocationEntry::prepareForNextAction
}
} else {
#ifdef __MINGW32__
const SharedHandle<DiskAdaptor>& diskAdaptor =
const std::shared_ptr<DiskAdaptor>& diskAdaptor =
getRequestGroup()->getPieceStorage()->getDiskAdaptor();
if(!diskAdaptor->isReadOnlyEnabled()) {
// On Windows, if aria2 opens files with GENERIC_WRITE access

View File

@ -75,10 +75,10 @@ void BtHandshakeMessage::init() {
reserved_[5] |= 0x10u;
}
SharedHandle<BtHandshakeMessage>
std::shared_ptr<BtHandshakeMessage>
BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
{
SharedHandle<BtHandshakeMessage> message(new BtHandshakeMessage());
std::shared_ptr<BtHandshakeMessage> message(new BtHandshakeMessage());
message->pstrlen_ = data[0];
memcpy(message->pstr_, &data[1], PSTR_LENGTH);
memcpy(message->reserved_, &data[20], RESERVED_LENGTH);

View File

@ -60,7 +60,7 @@ public:
*/
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
static SharedHandle<BtHandshakeMessage>
static std::shared_ptr<BtHandshakeMessage>
create(const unsigned char* data, size_t dataLength);
virtual ~BtHandshakeMessage() {

View File

@ -36,7 +36,8 @@
#define D_BT_INTERACTIVE_H
#include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -48,9 +49,9 @@ public:
virtual void initiateHandshake() = 0;
virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false) = 0;
virtual std::shared_ptr<BtMessage> receiveHandshake(bool quickReply = false) = 0;
virtual SharedHandle<BtMessage> receiveAndSendHandshake() = 0;
virtual std::shared_ptr<BtMessage> receiveAndSendHandshake() = 0;
virtual void doPostHandshakeProcessing() = 0;

View File

@ -69,7 +69,7 @@ bool BtInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
ThisProgressUpdate(const SharedHandle<Peer>& peer)
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amInterested(true);
}
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
};
} // namespace
@ -87,7 +87,7 @@ ProgressUpdate* BtInterestedMessage::getProgressUpdate()
}
void BtInterestedMessage::setPeerStorage
(const SharedHandle<PeerStorage>& peerStorage)
(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}

View File

@ -44,7 +44,7 @@ class BtInterestedMessage;
class BtInterestedMessage : public ZeroBtMessage {
private:
SharedHandle<PeerStorage> peerStorage_;
std::shared_ptr<PeerStorage> peerStorage_;
public:
BtInterestedMessage();
virtual ~BtInterestedMessage();
@ -62,7 +62,7 @@ public:
virtual ProgressUpdate* getProgressUpdate();
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2

View File

@ -52,7 +52,7 @@ BtLeecherStateChoke::BtLeecherStateChoke()
BtLeecherStateChoke::~BtLeecherStateChoke() {}
BtLeecherStateChoke::PeerEntry::PeerEntry(const SharedHandle<Peer>& peer):
BtLeecherStateChoke::PeerEntry::PeerEntry(const std::shared_ptr<Peer>& peer):
peer_(peer), downloadSpeed_(peer->calculateDownloadSpeed()),
// peer must be interested to us and sent block in the last 30 seconds
regularUnchoker_
@ -86,7 +86,7 @@ BtLeecherStateChoke::PeerEntry& BtLeecherStateChoke::PeerEntry::operator=
BtLeecherStateChoke::PeerEntry::~PeerEntry() {}
const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
const std::shared_ptr<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
{
return peer_;
}

View File

@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
#include <memory>
#include "SharedHandle.h"
#include "TimerA2.h"
#include "PeerStorage.h"
@ -55,11 +55,11 @@ private:
class PeerEntry {
private:
SharedHandle<Peer> peer_;
std::shared_ptr<Peer> peer_;
int downloadSpeed_;
bool regularUnchoker_;
public:
PeerEntry(const SharedHandle<Peer>& peer);
PeerEntry(const std::shared_ptr<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
@ -69,7 +69,7 @@ private:
void swap(PeerEntry& c);
const SharedHandle<Peer>& getPeer() const;
const std::shared_ptr<Peer>& getPeer() const;
int getDownloadSpeed() const;

View File

@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
#include <memory>
#include "SharedHandle.h"
#include "RequestSlot.h"
namespace aria2 {
@ -51,19 +51,19 @@ class BtMessageDispatcher {
public:
virtual ~BtMessageDispatcher() {}
virtual void addMessageToQueue(const SharedHandle<BtMessage>& btMessage) = 0;
virtual void addMessageToQueue(const std::shared_ptr<BtMessage>& btMessage) = 0;
virtual void
addMessageToQueue(const std::vector<SharedHandle<BtMessage> >& btMessages) =0;
addMessageToQueue(const std::vector<std::shared_ptr<BtMessage> >& btMessages) =0;
virtual void sendMessages() = 0;
virtual void doCancelSendingPieceAction
(size_t index, int32_t begin, int32_t length) = 0;
virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) = 0;
virtual void doCancelSendingPieceAction(const std::shared_ptr<Piece>& piece) = 0;
virtual void doAbortOutstandingRequestAction(const SharedHandle<Piece>& piece) = 0;
virtual void doAbortOutstandingRequestAction(const std::shared_ptr<Piece>& piece) = 0;
virtual void doChokedAction() = 0;

View File

@ -36,7 +36,8 @@
#define D_BT_MESSAGE_FACTORY_H
#include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -49,52 +50,52 @@ class BtMessageFactory {
public:
virtual ~BtMessageFactory() {}
virtual SharedHandle<BtMessage>
virtual std::shared_ptr<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength) = 0;
virtual SharedHandle<BtHandshakeMessage>
virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0;
virtual SharedHandle<BtHandshakeMessage>
virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId) = 0;
virtual SharedHandle<BtMessage>
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0;
virtual std::shared_ptr<BtMessage>
createRequestMessage(const std::shared_ptr<Piece>& piece, size_t blockIndex) = 0;
virtual SharedHandle<BtMessage>
virtual std::shared_ptr<BtMessage>
createCancelMessage(size_t index, int32_t begin, int32_t length) = 0;
virtual SharedHandle<BtMessage>
virtual std::shared_ptr<BtMessage>
createPieceMessage(size_t index, int32_t begin, int32_t length) = 0;
virtual SharedHandle<BtMessage> createHaveMessage(size_t index) = 0;
virtual std::shared_ptr<BtMessage> createHaveMessage(size_t index) = 0;
virtual SharedHandle<BtMessage> createChokeMessage() = 0;
virtual std::shared_ptr<BtMessage> createChokeMessage() = 0;
virtual SharedHandle<BtMessage> createUnchokeMessage() = 0;
virtual std::shared_ptr<BtMessage> createUnchokeMessage() = 0;
virtual SharedHandle<BtMessage> createInterestedMessage() = 0;
virtual std::shared_ptr<BtMessage> createInterestedMessage() = 0;
virtual SharedHandle<BtMessage> createNotInterestedMessage() = 0;
virtual std::shared_ptr<BtMessage> createNotInterestedMessage() = 0;
virtual SharedHandle<BtMessage> createBitfieldMessage() = 0;
virtual std::shared_ptr<BtMessage> createBitfieldMessage() = 0;
virtual SharedHandle<BtMessage> createKeepAliveMessage() = 0;
virtual std::shared_ptr<BtMessage> createKeepAliveMessage() = 0;
virtual SharedHandle<BtMessage> createHaveAllMessage() = 0;
virtual std::shared_ptr<BtMessage> createHaveAllMessage() = 0;
virtual SharedHandle<BtMessage> createHaveNoneMessage() = 0;
virtual std::shared_ptr<BtMessage> createHaveNoneMessage() = 0;
virtual SharedHandle<BtMessage>
virtual std::shared_ptr<BtMessage>
createRejectMessage(size_t index, int32_t begin, int32_t length) = 0;
virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index) = 0;
virtual std::shared_ptr<BtMessage> createAllowedFastMessage(size_t index) = 0;
virtual SharedHandle<BtMessage> createPortMessage(uint16_t port) = 0;
virtual std::shared_ptr<BtMessage> createPortMessage(uint16_t port) = 0;
virtual SharedHandle<BtMessage>
createBtExtendedMessage(const SharedHandle<ExtensionMessage>& msg) = 0;
virtual std::shared_ptr<BtMessage>
createBtExtendedMessage(const std::shared_ptr<ExtensionMessage>& msg) = 0;
};
} // namespace aria2

View File

@ -36,7 +36,8 @@
#define D_BT_MESSAGE_RECEIVER_H
#include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -47,11 +48,11 @@ class BtMessageReceiver {
public:
virtual ~BtMessageReceiver() {}
virtual SharedHandle<BtHandshakeMessage> receiveHandshake(bool quickReply = false) = 0;
virtual std::shared_ptr<BtHandshakeMessage> receiveHandshake(bool quickReply = false) = 0;
virtual SharedHandle<BtHandshakeMessage> receiveAndSendHandshake() = 0;
virtual std::shared_ptr<BtHandshakeMessage> receiveAndSendHandshake() = 0;
virtual SharedHandle<BtMessage> receiveMessage() = 0;
virtual std::shared_ptr<BtMessage> receiveMessage() = 0;
};
} // namespace aria2

View File

@ -69,7 +69,7 @@ bool BtNotInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
ThisProgressUpdate(const SharedHandle<Peer>& peer)
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@ -77,7 +77,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amInterested(false);
}
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
};
} // namespace
@ -87,7 +87,7 @@ ProgressUpdate* BtNotInterestedMessage::getProgressUpdate()
}
void BtNotInterestedMessage::setPeerStorage
(const SharedHandle<PeerStorage>& peerStorage)
(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}

View File

@ -44,7 +44,7 @@ class BtNotInterestedMessage;
class BtNotInterestedMessage : public ZeroBtMessage {
private:
SharedHandle<PeerStorage> peerStorage_;
std::shared_ptr<PeerStorage> peerStorage_;
public:
BtNotInterestedMessage();
virtual ~BtNotInterestedMessage();
@ -62,7 +62,7 @@ public:
virtual ProgressUpdate* getProgressUpdate();
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
};
} // namespace aria2

View File

@ -107,7 +107,7 @@ void BtPieceMessage::doReceivedAction()
downloadContext_->updateDownloadLength(blockLength_);
if(!RequestSlot::isNull(slot)) {
getPeer()->snubbing(false);
SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
std::shared_ptr<Piece> piece = getPieceStorage()->getPiece(index_);
int64_t offset =
static_cast<int64_t>(index_)*downloadContext_->getPieceLength()+begin_;
A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
@ -179,7 +179,7 @@ size_t BtPieceMessage::getMessageHeaderLength()
namespace {
struct PieceSendUpdate : public ProgressUpdate {
PieceSendUpdate(const SharedHandle<Peer>& peer, size_t headerLength)
PieceSendUpdate(const std::shared_ptr<Peer>& peer, size_t headerLength)
: peer(peer), headerLength(headerLength) {}
virtual void update(size_t length, bool complete)
{
@ -190,7 +190,7 @@ struct PieceSendUpdate : public ProgressUpdate {
}
peer->updateUploadLength(length);
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
size_t headerLength;
};
} // namespace
@ -241,7 +241,7 @@ std::string BtPieceMessage::toString() const
begin_, blockLength_);
}
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
bool BtPieceMessage::checkPieceHash(const std::shared_ptr<Piece>& piece)
{
if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) {
A2_LOG_DEBUG(fmt("Hash is available!! index=%lu",
@ -262,7 +262,7 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
}
}
void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
void BtPieceMessage::onNewPiece(const std::shared_ptr<Piece>& piece)
{
if(piece->getWrDiskCacheEntry()) {
// We flush cached data whenever an whole piece is retrieved.
@ -283,7 +283,7 @@ void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
}
void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
void BtPieceMessage::onWrongPiece(const std::shared_ptr<Piece>& piece)
{
A2_LOG_INFO(fmt(MSG_GOT_WRONG_PIECE,
getCuid(),
@ -303,7 +303,7 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
begin_,
blockLength_));
if(getPeer()->isFastExtensionEnabled()) {
SharedHandle<BtMessage> rej =
std::shared_ptr<BtMessage> rej =
getBtMessageFactory()->createRejectMessage
(index_, begin_, blockLength_);
getBtMessageDispatcher()->addMessageToQueue(rej);
@ -325,7 +325,7 @@ void BtPieceMessage::onCancelSendingPieceEvent
begin_,
blockLength_));
if(getPeer()->isFastExtensionEnabled()) {
SharedHandle<BtMessage> rej =
std::shared_ptr<BtMessage> rej =
getBtMessageFactory()->createRejectMessage
(index_, begin_, blockLength_);
getBtMessageDispatcher()->addMessageToQueue(rej);
@ -335,13 +335,13 @@ void BtPieceMessage::onCancelSendingPieceEvent
}
void BtPieceMessage::setDownloadContext
(const SharedHandle<DownloadContext>& downloadContext)
(const std::shared_ptr<DownloadContext>& downloadContext)
{
downloadContext_ = downloadContext;
}
void BtPieceMessage::setPeerStorage
(const SharedHandle<PeerStorage>& peerStorage)
(const std::shared_ptr<PeerStorage>& peerStorage)
{
peerStorage_ = peerStorage;
}

View File

@ -49,16 +49,16 @@ private:
int32_t begin_;
int32_t blockLength_;
const unsigned char* data_;
SharedHandle<DownloadContext> downloadContext_;
SharedHandle<PeerStorage> peerStorage_;
std::shared_ptr<DownloadContext> downloadContext_;
std::shared_ptr<PeerStorage> peerStorage_;
static size_t MESSAGE_HEADER_LENGTH;
bool checkPieceHash(const SharedHandle<Piece>& piece);
bool checkPieceHash(const std::shared_ptr<Piece>& piece);
void onNewPiece(const SharedHandle<Piece>& piece);
void onNewPiece(const std::shared_ptr<Piece>& piece);
void onWrongPiece(const SharedHandle<Piece>& piece);
void onWrongPiece(const std::shared_ptr<Piece>& piece);
void pushPieceData(int64_t offset, int32_t length) const;
public:
@ -88,9 +88,9 @@ public:
void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; }
void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
void setDownloadContext(const std::shared_ptr<DownloadContext>& downloadContext);
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setPeerStorage(const std::shared_ptr<PeerStorage>& peerStorage);
static BtPieceMessage* create(const unsigned char* data, size_t dataLength);

View File

@ -80,11 +80,11 @@ void BtPortMessage::doReceivedAction()
}
// node id is random at this point. When ping reply received, new DHTNode
// instance created with proper node ID and is added to a routing table.
SharedHandle<DHTNode> node(new DHTNode());
std::shared_ptr<DHTNode> node(new DHTNode());
node->setIPAddress(getPeer()->getIPAddress());
node->setPort(port_);
{
SharedHandle<DHTTask> task = taskFactory_->createPingTask(node);
std::shared_ptr<DHTTask> task = taskFactory_->createPingTask(node);
taskQueue_->addImmediateTask(task);
}
if(routingTable_->getNumBucket() == 1) {

View File

@ -57,7 +57,7 @@ namespace aria2 {
BtPostDownloadHandler::BtPostDownloadHandler()
{
SharedHandle<RequestGroupCriteria> cri
std::shared_ptr<RequestGroupCriteria> cri
(new ContentTypeRequestGroupCriteria
(getBtContentTypes(), getBtExtensions()));
setCriteria(cri);
@ -66,18 +66,18 @@ BtPostDownloadHandler::BtPostDownloadHandler()
BtPostDownloadHandler::~BtPostDownloadHandler() {}
void BtPostDownloadHandler::getNextRequestGroups
(std::vector<SharedHandle<RequestGroup> >& groups,
(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup)
{
A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
requestGroup->getFirstFilePath().c_str()));
SharedHandle<ValueBase> torrent;
std::shared_ptr<ValueBase> torrent;
if(requestGroup->inMemoryDownload()) {
const SharedHandle<DiskWriter>& dw =
static_pointer_cast<AbstractSingleDiskAdaptor>
const std::shared_ptr<DiskWriter>& dw =
std::static_pointer_cast<AbstractSingleDiskAdaptor>
(requestGroup->getPieceStorage()->getDiskAdaptor())->getDiskWriter();
const SharedHandle<bittorrent::BencodeDiskWriter>& bdw =
static_pointer_cast<bittorrent::BencodeDiskWriter>(dw);
const std::shared_ptr<bittorrent::BencodeDiskWriter>& bdw =
std::static_pointer_cast<bittorrent::BencodeDiskWriter>(dw);
int error = bdw->finalize();
if(error == 0) {
torrent = bdw->getResult();
@ -101,13 +101,13 @@ void BtPostDownloadHandler::getNextRequestGroups
throw DL_ABORT_EX2("Could not parse BitTorrent metainfo",
error_code::BENCODE_PARSE_ERROR);
}
std::vector<SharedHandle<RequestGroup> > newRgs;
std::vector<std::shared_ptr<RequestGroup> > newRgs;
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
std::vector<std::string>(),
"",
torrent);
requestGroup->followedBy(newRgs.begin(), newRgs.end());
SharedHandle<MetadataInfo> mi =
std::shared_ptr<MetadataInfo> mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
requestGroup->getDownloadContext());
if(mi) {

View File

@ -47,7 +47,7 @@ public:
virtual ~BtPostDownloadHandler();
virtual void
getNextRequestGroups(std::vector<SharedHandle<RequestGroup> >& groups,
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
RequestGroup* requestGroup);
};

View File

@ -54,10 +54,10 @@ BtRegistry::BtRegistry()
BtRegistry::~BtRegistry() {}
const SharedHandle<DownloadContext>&
const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(a2_gid_t gid) const
{
const SharedHandle<BtObject>& res = get(gid);
const std::shared_ptr<BtObject>& res = get(gid);
if(res) {
return res->downloadContext;
} else {
@ -65,10 +65,10 @@ BtRegistry::getDownloadContext(a2_gid_t gid) const
}
}
const SharedHandle<DownloadContext>&
const std::shared_ptr<DownloadContext>&
BtRegistry::getDownloadContext(const std::string& infoHash) const
{
for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
if(bittorrent::getTorrentAttrs((*i).second->downloadContext)->infoHash ==
infoHash) {
@ -78,14 +78,14 @@ BtRegistry::getDownloadContext(const std::string& infoHash) const
return getNull<DownloadContext>();
}
void BtRegistry::put(a2_gid_t gid, const SharedHandle<BtObject>& obj)
void BtRegistry::put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj)
{
pool_[gid] = obj;
}
const SharedHandle<BtObject>& BtRegistry::get(a2_gid_t gid) const
const std::shared_ptr<BtObject>& BtRegistry::get(a2_gid_t gid) const
{
std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.find(gid);
if(i == pool_.end()) {
return getNull<BtObject>();
@ -104,24 +104,24 @@ void BtRegistry::removeAll() {
}
void BtRegistry::setLpdMessageReceiver
(const SharedHandle<LpdMessageReceiver>& receiver)
(const std::shared_ptr<LpdMessageReceiver>& receiver)
{
lpdMessageReceiver_ = receiver;
}
void BtRegistry::setUDPTrackerClient
(const SharedHandle<UDPTrackerClient>& tracker)
(const std::shared_ptr<UDPTrackerClient>& tracker)
{
udpTrackerClient_ = tracker;
}
BtObject::BtObject
(const SharedHandle<DownloadContext>& downloadContext,
const SharedHandle<PieceStorage>& pieceStorage,
const SharedHandle<PeerStorage>& peerStorage,
const SharedHandle<BtAnnounce>& btAnnounce,
const SharedHandle<BtRuntime>& btRuntime,
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
(const std::shared_ptr<DownloadContext>& downloadContext,
const std::shared_ptr<PieceStorage>& pieceStorage,
const std::shared_ptr<PeerStorage>& peerStorage,
const std::shared_ptr<BtAnnounce>& btAnnounce,
const std::shared_ptr<BtRuntime>& btRuntime,
const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile)
: downloadContext(downloadContext),
pieceStorage(pieceStorage),
peerStorage(peerStorage),

View File

@ -38,8 +38,8 @@
#include "common.h"
#include <map>
#include <memory>
#include "SharedHandle.h"
#include "RequestGroup.h"
namespace aria2 {
@ -54,19 +54,19 @@ class LpdMessageReceiver;
class UDPTrackerClient;
struct BtObject {
SharedHandle<DownloadContext> downloadContext;
SharedHandle<PieceStorage> pieceStorage;
SharedHandle<PeerStorage> peerStorage;
SharedHandle<BtAnnounce> btAnnounce;
SharedHandle<BtRuntime> btRuntime;
SharedHandle<BtProgressInfoFile> btProgressInfoFile;
std::shared_ptr<DownloadContext> downloadContext;
std::shared_ptr<PieceStorage> pieceStorage;
std::shared_ptr<PeerStorage> peerStorage;
std::shared_ptr<BtAnnounce> btAnnounce;
std::shared_ptr<BtRuntime> btRuntime;
std::shared_ptr<BtProgressInfoFile> btProgressInfoFile;
BtObject(const SharedHandle<DownloadContext>& downloadContext,
const SharedHandle<PieceStorage>& pieceStorage,
const SharedHandle<PeerStorage>& peerStorage,
const SharedHandle<BtAnnounce>& btAnnounce,
const SharedHandle<BtRuntime>& btRuntime,
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile);
BtObject(const std::shared_ptr<DownloadContext>& downloadContext,
const std::shared_ptr<PieceStorage>& pieceStorage,
const std::shared_ptr<PeerStorage>& peerStorage,
const std::shared_ptr<BtAnnounce>& btAnnounce,
const std::shared_ptr<BtRuntime>& btRuntime,
const std::shared_ptr<BtProgressInfoFile>& btProgressInfoFile);
BtObject();
@ -79,31 +79,31 @@ struct BtObject {
class BtRegistry {
private:
std::map<a2_gid_t, SharedHandle<BtObject> > pool_;
std::map<a2_gid_t, std::shared_ptr<BtObject> > pool_;
uint16_t tcpPort_;
// This is UDP port for DHT and UDP tracker. But currently UDP
// tracker is not supported in IPv6.
uint16_t udpPort_;
SharedHandle<LpdMessageReceiver> lpdMessageReceiver_;
SharedHandle<UDPTrackerClient> udpTrackerClient_;
std::shared_ptr<LpdMessageReceiver> lpdMessageReceiver_;
std::shared_ptr<UDPTrackerClient> udpTrackerClient_;
public:
BtRegistry();
~BtRegistry();
const SharedHandle<DownloadContext>&
const std::shared_ptr<DownloadContext>&
getDownloadContext(a2_gid_t gid) const;
const SharedHandle<DownloadContext>&
const std::shared_ptr<DownloadContext>&
getDownloadContext(const std::string& infoHash) const;
void put(a2_gid_t gid, const SharedHandle<BtObject>& obj);
void put(a2_gid_t gid, const std::shared_ptr<BtObject>& obj);
const SharedHandle<BtObject>& get(a2_gid_t gid) const;
const std::shared_ptr<BtObject>& get(a2_gid_t gid) const;
template<typename OutputIterator>
OutputIterator getAllDownloadContext(OutputIterator dest)
{
for(std::map<a2_gid_t, SharedHandle<BtObject> >::const_iterator i =
for(std::map<a2_gid_t, std::shared_ptr<BtObject> >::const_iterator i =
pool_.begin(), eoi = pool_.end(); i != eoi; ++i) {
*dest++ = (*i).second->downloadContext;
}
@ -132,14 +132,14 @@ public:
return udpPort_;
}
void setLpdMessageReceiver(const SharedHandle<LpdMessageReceiver>& receiver);
const SharedHandle<LpdMessageReceiver>& getLpdMessageReceiver() const
void setLpdMessageReceiver(const std::shared_ptr<LpdMessageReceiver>& receiver);
const std::shared_ptr<LpdMessageReceiver>& getLpdMessageReceiver() const
{
return lpdMessageReceiver_;
}
void setUDPTrackerClient(const SharedHandle<UDPTrackerClient>& tracker);
const SharedHandle<UDPTrackerClient>& getUDPTrackerClient() const
void setUDPTrackerClient(const std::shared_ptr<UDPTrackerClient>& tracker);
const std::shared_ptr<UDPTrackerClient>& getUDPTrackerClient() const
{
return udpTrackerClient_;
}

View File

@ -38,8 +38,7 @@
#include "common.h"
#include <vector>
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -50,9 +49,9 @@ class BtRequestFactory {
public:
virtual ~BtRequestFactory() {}
virtual void addTargetPiece(const SharedHandle<Piece>& piece) = 0;
virtual void addTargetPiece(const std::shared_ptr<Piece>& piece) = 0;
virtual void removeTargetPiece(const SharedHandle<Piece>& piece) = 0;
virtual void removeTargetPiece(const std::shared_ptr<Piece>& piece) = 0;
virtual void removeAllTargetPiece() = 0;
@ -70,14 +69,14 @@ public:
* The number of objects returned is capped by max.
*/
virtual void createRequestMessages
(std::vector<SharedHandle<BtMessage> >& requests, size_t max) = 0;
(std::vector<std::shared_ptr<BtMessage> >& requests, size_t max) = 0;
/**
* Use this method in end game mode.
*
*/
virtual void createRequestMessagesOnEndGame
(std::vector<SharedHandle<BtMessage> >& requests, size_t max) = 0;
(std::vector<std::shared_ptr<BtMessage> >& requests, size_t max) = 0;
/**
* Stores the list of index of pieces added using addTargetPiece() into

View File

@ -63,13 +63,13 @@ void BtRequestMessage::doReceivedAction()
(!getPeer()->amChoking() ||
(getPeer()->amChoking() &&
getPeer()->isInAmAllowedIndexSet(getIndex())))) {
SharedHandle<BtMessage> msg =
std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createPieceMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);
} else {
if(getPeer()->isFastExtensionEnabled()) {
SharedHandle<BtMessage> msg =
std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createRejectMessage
(getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg);

View File

@ -53,7 +53,7 @@ BtSeederStateChoke::BtSeederStateChoke()
BtSeederStateChoke::~BtSeederStateChoke() {}
BtSeederStateChoke::PeerEntry::PeerEntry
(const SharedHandle<Peer>& peer):
(const std::shared_ptr<Peer>& peer):
peer_(peer),
outstandingUpload_(peer->countOutstandingUpload()),
lastAmUnchoking_(peer->getLastAmUnchoking()),

View File

@ -38,8 +38,8 @@
#include "common.h"
#include <vector>
#include <memory>
#include "SharedHandle.h"
#include "TimerA2.h"
#include "PeerStorage.h"
@ -55,7 +55,7 @@ private:
class PeerEntry {
private:
SharedHandle<Peer> peer_;
std::shared_ptr<Peer> peer_;
size_t outstandingUpload_;
Timer lastAmUnchoking_;
bool recentUnchoking_;
@ -63,7 +63,7 @@ private:
const static time_t TIME_FRAME = 20;
public:
PeerEntry(const SharedHandle<Peer>& peer);
PeerEntry(const std::shared_ptr<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
@ -73,7 +73,7 @@ private:
bool operator<(const PeerEntry& rhs) const;
const SharedHandle<Peer>& getPeer() const { return peer_; }
const std::shared_ptr<Peer>& getPeer() const { return peer_; }
int getUploadSpeed() const { return uploadSpeed_; }

View File

@ -98,15 +98,15 @@ void BtSetup::setup(std::vector<Command*>& commands,
if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){
return;
}
SharedHandle<TorrentAttribute> torrentAttrs =
std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
bool metadataGetMode = torrentAttrs->metadata.empty();
const SharedHandle<BtRegistry>& btReg = e->getBtRegistry();
const SharedHandle<BtObject>& btObject = btReg->get(requestGroup->getGID());
const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage;
const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage;
const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime;
const SharedHandle<BtAnnounce>& btAnnounce = btObject->btAnnounce;
const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
const std::shared_ptr<BtObject>& btObject = btReg->get(requestGroup->getGID());
const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
const std::shared_ptr<BtAnnounce>& btAnnounce = btObject->btAnnounce;
// commands
{
TrackerWatcherCommand* c =
@ -159,16 +159,16 @@ void BtSetup::setup(std::vector<Command*>& commands,
}
}
if(!metadataGetMode) {
SharedHandle<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
std::shared_ptr<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
if(option->defined(PREF_SEED_TIME)) {
SharedHandle<SeedCriteria> cri
std::shared_ptr<SeedCriteria> cri
(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60));
unionCri->addSeedCriteria(cri);
}
{
double ratio = option->getAsDouble(PREF_SEED_RATIO);
if(ratio > 0.0) {
SharedHandle<ShareRatioSeedCriteria> cri
std::shared_ptr<ShareRatioSeedCriteria> cri
(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO),
requestGroup->getDownloadContext()));
cri->setPieceStorage(pieceStorage);
@ -223,7 +223,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
(metadataGetMode || !torrentAttrs->privateTorrent)) {
if(!btReg->getLpdMessageReceiver()) {
A2_LOG_INFO("Initializing LpdMessageReceiver.");
SharedHandle<LpdMessageReceiver> receiver
std::shared_ptr<LpdMessageReceiver> receiver
(new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
bool initialized = false;
const std::string& lpdInterface =
@ -263,7 +263,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
const unsigned char* infoHash =
bittorrent::getInfoHash(requestGroup->getDownloadContext());
A2_LOG_INFO("Initializing LpdMessageDispatcher.");
SharedHandle<LpdMessageDispatcher> dispatcher
std::shared_ptr<LpdMessageDispatcher> dispatcher
(new LpdMessageDispatcher
(std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]),
btReg->getTcpPort(),

View File

@ -36,7 +36,8 @@
#define D_BT_STOP_DOWNLOAD_COMMAND_H
#include "TimeBasedCommand.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -54,9 +55,9 @@ private:
Timer checkPoint_;
SharedHandle<BtRuntime> btRuntime_;
std::shared_ptr<BtRuntime> btRuntime_;
SharedHandle<PieceStorage> pieceStorage_;
std::shared_ptr<PieceStorage> pieceStorage_;
public:
BtStopDownloadCommand
(cuid_t cuid,
@ -68,12 +69,12 @@ public:
virtual void process();
void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
void setBtRuntime(const std::shared_ptr<BtRuntime>& btRuntime)
{
btRuntime_ = btRuntime;
}
void setPieceStorage(const SharedHandle<PieceStorage>& pieceStorage)
void setPieceStorage(const std::shared_ptr<PieceStorage>& pieceStorage)
{
pieceStorage_ = pieceStorage;
}

View File

@ -63,7 +63,7 @@ bool BtUnchokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
ThisProgressUpdate(const SharedHandle<Peer>& peer)
ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
: peer(peer) {}
virtual void update(size_t length, bool complete)
{
@ -71,7 +71,7 @@ struct ThisProgressUpdate : public ProgressUpdate {
peer->amChoking(false);
}
}
SharedHandle<Peer> peer;
std::shared_ptr<Peer> peer;
};
} // namespace

View File

@ -50,7 +50,7 @@ namespace aria2 {
CheckIntegrityCommand::CheckIntegrityCommand
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e,
const SharedHandle<CheckIntegrityEntry>& entry):
const std::shared_ptr<CheckIntegrityEntry>& entry):
RealtimeCommand(cuid, requestGroup, e),
entry_(entry)
{}

View File

@ -36,7 +36,8 @@
#define D_CHECK_INTEGRITY_COMMAND_H
#include "RealtimeCommand.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 {
@ -44,12 +45,12 @@ class CheckIntegrityEntry;
class CheckIntegrityCommand : public RealtimeCommand {
private:
SharedHandle<CheckIntegrityEntry> entry_;
std::shared_ptr<CheckIntegrityEntry> entry_;
public:
CheckIntegrityCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<CheckIntegrityEntry>& entry);
const std::shared_ptr<CheckIntegrityEntry>& entry);
virtual ~CheckIntegrityCommand();

View File

@ -45,7 +45,7 @@ namespace aria2 {
CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
(cuid_t cuid,
const SharedHandle<CheckIntegrityMan>& fileAllocMan,
const std::shared_ptr<CheckIntegrityMan>& fileAllocMan,
DownloadEngine* e)
: SequentialDispatcherCommand<CheckIntegrityEntry>(cuid, fileAllocMan, e)
{
@ -53,7 +53,7 @@ CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
}
Command* CheckIntegrityDispatcherCommand::createCommand
(const SharedHandle<CheckIntegrityEntry>& entry)
(const std::shared_ptr<CheckIntegrityEntry>& entry)
{
cuid_t newCUID = getDownloadEngine()->newCUID();
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Dispatching CheckIntegrityCommand CUID#%" PRId64 ".",

View File

@ -47,11 +47,11 @@ class CheckIntegrityDispatcherCommand :
public:
CheckIntegrityDispatcherCommand
(cuid_t cuid,
const SharedHandle<CheckIntegrityMan>& checkMan,
const std::shared_ptr<CheckIntegrityMan>& checkMan,
DownloadEngine* e);
protected:
virtual Command* createCommand
(const SharedHandle<CheckIntegrityEntry>& entry);
(const std::shared_ptr<CheckIntegrityEntry>& entry);
};
} // namespace aria2

View File

@ -86,7 +86,7 @@ void CheckIntegrityEntry::cutTrailingGarbage()
void CheckIntegrityEntry::proceedFileAllocation
(std::vector<Command*>& commands,
const SharedHandle<FileAllocationEntry>& entry,
const std::shared_ptr<FileAllocationEntry>& entry,
DownloadEngine* e)
{
if(getRequestGroup()->needsFileAllocation()) {
@ -97,7 +97,7 @@ void CheckIntegrityEntry::proceedFileAllocation
}
void CheckIntegrityEntry::setValidator
(const SharedHandle<IteratableValidator>& validator)
(const std::shared_ptr<IteratableValidator>& validator)
{
validator_ = validator;
}

View File

@ -38,8 +38,8 @@
#include "RequestGroupEntry.h"
#include <vector>
#include <memory>
#include "SharedHandle.h"
#include "ProgressAwareEntry.h"
namespace aria2 {
@ -51,12 +51,12 @@ class FileAllocationEntry;
class CheckIntegrityEntry : public RequestGroupEntry,
public ProgressAwareEntry {
private:
SharedHandle<IteratableValidator> validator_;
std::shared_ptr<IteratableValidator> validator_;
protected:
void setValidator(const SharedHandle<IteratableValidator>& validator);
void setValidator(const std::shared_ptr<IteratableValidator>& validator);
void proceedFileAllocation(std::vector<Command*>& commands,
const SharedHandle<FileAllocationEntry>& entry,
const std::shared_ptr<FileAllocationEntry>& entry,
DownloadEngine* e);
public:
CheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand = 0);

View File

@ -52,14 +52,14 @@ ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
bool ChecksumCheckIntegrityEntry::isValidationReady()
{
const SharedHandle<DownloadContext>& dctx =
const std::shared_ptr<DownloadContext>& dctx =
getRequestGroup()->getDownloadContext();
return dctx->isChecksumVerificationAvailable();
}
void ChecksumCheckIntegrityEntry::initValidator()
{
SharedHandle<IteratableChecksumValidator> validator
std::shared_ptr<IteratableChecksumValidator> validator
(new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(),
getRequestGroup()->getPieceStorage()));
validator->init();
@ -76,7 +76,7 @@ ChecksumCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e)
{
if(redownload_) {
SharedHandle<FileAllocationEntry> entry
std::shared_ptr<FileAllocationEntry> entry
(new StreamFileAllocationEntry(getRequestGroup(), popNextCommand()));
proceedFileAllocation(commands, entry, e);
}

View File

@ -40,8 +40,6 @@
#include <string>
#include <vector>
#include "SharedHandle.h"
namespace aria2 {
class ChunkChecksum {

View File

@ -65,7 +65,7 @@ enum {
} // namespace
ChunkedDecodingStreamFilter::ChunkedDecodingStreamFilter
(const SharedHandle<StreamFilter>& delegate):
(const std::shared_ptr<StreamFilter>& delegate):
StreamFilter(delegate),
state_(PREV_CHUNK_SIZE),
chunkSize_(0),
@ -77,8 +77,8 @@ ChunkedDecodingStreamFilter::~ChunkedDecodingStreamFilter() {}
void ChunkedDecodingStreamFilter::init() {}
ssize_t ChunkedDecodingStreamFilter::transform
(const SharedHandle<BinaryStream>& out,
const SharedHandle<Segment>& segment,
(const std::shared_ptr<BinaryStream>& out,
const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen)
{
ssize_t outlen = 0;

View File

@ -47,15 +47,15 @@ private:
size_t bytesProcessed_;
public:
ChunkedDecodingStreamFilter
(const SharedHandle<StreamFilter>& delegate = SharedHandle<StreamFilter>());
(const std::shared_ptr<StreamFilter>& delegate = std::shared_ptr<StreamFilter>());
virtual ~ChunkedDecodingStreamFilter();
virtual void init();
virtual ssize_t transform
(const SharedHandle<BinaryStream>& out,
const SharedHandle<Segment>& segment,
(const std::shared_ptr<BinaryStream>& out,
const std::shared_ptr<Segment>& segment,
const unsigned char* inbuf, size_t inlen);
virtual bool finished();

View File

@ -48,12 +48,12 @@
namespace aria2 {
ConnectCommand::ConnectCommand(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<Request>& proxyRequest,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<SocketCore>& s)
const std::shared_ptr<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
proxyRequest_(proxyRequest)
{
@ -70,18 +70,18 @@ ConnectCommand::~ConnectCommand()
}
void ConnectCommand::setControlChain
(const SharedHandle<ControlChain<ConnectCommand*> >& chain)
(const std::shared_ptr<ControlChain<ConnectCommand*> >& chain)
{
chain_ = chain;
}
void ConnectCommand::setBackupConnectInfo
(const SharedHandle<BackupConnectInfo>& info)
(const std::shared_ptr<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
const SharedHandle<Request>& ConnectCommand::getProxyRequest() const
const std::shared_ptr<Request>& ConnectCommand::getProxyRequest() const
{
return proxyRequest_;
}
@ -89,7 +89,7 @@ const SharedHandle<Request>& ConnectCommand::getProxyRequest() const
bool ConnectCommand::executeInternal()
{
if(backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty()) {
A2_LOG_INFO(fmt("CUID#%"PRId64" - Use backup connection address %s",
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Use backup connection address %s",
getCuid(), backupConnectionInfo_->ipaddr.c_str()));
getDownloadEngine()->markBadIPAddress
(getRequest()->getConnectedHostname(),

View File

@ -45,24 +45,24 @@ class BackupConnectInfo;
class ConnectCommand : public AbstractCommand {
public:
ConnectCommand(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<FileEntry>& fileEntry,
const std::shared_ptr<Request>& req,
const std::shared_ptr<Request>& proxyRequest,
const std::shared_ptr<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<SocketCore>& s);
const std::shared_ptr<SocketCore>& s);
virtual ~ConnectCommand();
void setControlChain
(const SharedHandle<ControlChain<ConnectCommand*> >& chain);
void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
const SharedHandle<Request>& getProxyRequest() const;
(const std::shared_ptr<ControlChain<ConnectCommand*> >& chain);
void setBackupConnectInfo(const std::shared_ptr<BackupConnectInfo>& info);
const std::shared_ptr<Request>& getProxyRequest() const;
protected:
virtual bool executeInternal();
virtual bool noCheck();
private:
SharedHandle<Request> proxyRequest_;
SharedHandle<BackupConnectInfo> backupConnectionInfo_;
SharedHandle<ControlChain<ConnectCommand*> > chain_;
std::shared_ptr<Request> proxyRequest_;
std::shared_ptr<BackupConnectInfo> backupConnectionInfo_;
std::shared_ptr<ControlChain<ConnectCommand*> > chain_;
};
} // namespace aria2

View File

@ -96,7 +96,7 @@ protected:
} // namespace
namespace {
void printSizeProgress(std::ostream& o, const SharedHandle<RequestGroup>& rg,
void printSizeProgress(std::ostream& o, const std::shared_ptr<RequestGroup>& rg,
const TransferStat& stat,
const SizeFormatter& sizeFormatter)
{
@ -144,7 +144,7 @@ void printProgressCompact(std::ostream& o, const DownloadEngine* e,
const size_t MAX_ITEM = 5;
for(RequestGroupList::const_iterator i = groups.begin(),
eoi = groups.end(); i != eoi && cnt < MAX_ITEM; ++i, ++cnt) {
const SharedHandle<RequestGroup>& rg = *i;
const std::shared_ptr<RequestGroup>& rg = *i;
TransferStat stat = rg->calculateStat();
o << "[#" << GroupId::toAbbrevHex(rg->getGID()) << " ";
printSizeProgress(o, rg, stat, sizeFormatter);
@ -158,7 +158,7 @@ void printProgressCompact(std::ostream& o, const DownloadEngine* e,
namespace {
void printProgress
(std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e,
(std::ostream& o, const std::shared_ptr<RequestGroup>& rg, const DownloadEngine* e,
const SizeFormatter& sizeFormatter)
{
TransferStat stat = rg->calculateStat();
@ -171,7 +171,7 @@ void printProgress
o << " CN:"
<< rg->getNumConnection();
#ifdef ENABLE_BITTORRENT
const SharedHandle<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
const std::shared_ptr<BtObject>& btObj = e->getBtRegistry()->get(rg->getGID());
if(btObj) {
const PeerSet& peers = btObj->peerStorage->getUsedPeers();
o << " SD:"
@ -214,7 +214,7 @@ public:
const char SEP_CHAR = '-';
std::stringstream o;
printProgress(o, rg, e_, sizeFormatter_);
const std::vector<SharedHandle<FileEntry> >& fileEntries =
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
rg->getDownloadContext()->getFileEntries();
o << "\nFILE: ";
writeFilePath(fileEntries.begin(), fileEntries.end(),
@ -321,7 +321,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
size_t numGroup = e->getRequestGroupMan()->countRequestGroup();
if(numGroup == 1) {
const SharedHandle<RequestGroup>& rg =
const std::shared_ptr<RequestGroup>& rg =
*e->getRequestGroupMan()->getRequestGroups().begin();
printProgress(o, rg, e, sizeFormatter);
} else if(numGroup > 1) {
@ -330,7 +330,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
{
const SharedHandle<FileAllocationEntry>& entry =
const std::shared_ptr<FileAllocationEntry>& entry =
e->getFileAllocationMan()->getPickedEntry();
if(entry) {
o << " [FileAlloc:#"
@ -350,7 +350,7 @@ ConsoleStatCalc::calculateStat(const DownloadEngine* e)
}
#ifdef ENABLE_MESSAGE_DIGEST
{
const SharedHandle<CheckIntegrityEntry>& entry =
const std::shared_ptr<CheckIntegrityEntry>& entry =
e->getCheckIntegrityMan()->getPickedEntry();
if(entry) {
o << " [Checksum:#"

View File

@ -39,6 +39,7 @@
#include <string>
#include <functional>
#include <memory>
#include "TimerA2.h"
@ -62,7 +63,7 @@ private:
time_t summaryInterval_;
SharedHandle<SizeFormatter> sizeFormatter_;
std::shared_ptr<SizeFormatter> sizeFormatter_;
bool readoutVisibility_;
bool truncate_;
bool isTTY_;

View File

@ -41,7 +41,6 @@
#include <vector>
#include <iostream>
#include "SharedHandle.h"
#include "LogFactory.h"
#include "Logger.h"
#include "util.h"
@ -86,13 +85,13 @@ extern int optind, opterr, optopt;
namespace aria2 {
SharedHandle<StatCalc> getStatCalc(const SharedHandle<Option>& op)
std::shared_ptr<StatCalc> getStatCalc(const std::shared_ptr<Option>& op)
{
SharedHandle<StatCalc> statCalc;
std::shared_ptr<StatCalc> statCalc;
if(op->getAsBool(PREF_QUIET)) {
statCalc.reset(new NullStatCalc());
} else {
SharedHandle<ConsoleStatCalc> impl
std::shared_ptr<ConsoleStatCalc> impl
(new ConsoleStatCalc(op->getAsInt(PREF_SUMMARY_INTERVAL),
op->getAsBool(PREF_HUMAN_READABLE)));
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
@ -102,10 +101,10 @@ SharedHandle<StatCalc> getStatCalc(const SharedHandle<Option>& op)
return statCalc;
}
SharedHandle<OutputFile> getSummaryOut(const SharedHandle<Option>& op)
std::shared_ptr<OutputFile> getSummaryOut(const std::shared_ptr<Option>& op)
{
if(op->getAsBool(PREF_QUIET)) {
return SharedHandle<OutputFile>(new NullOutputFile());
return std::shared_ptr<OutputFile>(new NullOutputFile());
} else {
return global::cout();
}
@ -115,8 +114,8 @@ SharedHandle<OutputFile> getSummaryOut(const SharedHandle<Option>& op)
namespace {
void showTorrentFile(const std::string& uri)
{
SharedHandle<Option> op(new Option());
SharedHandle<DownloadContext> dctx(new DownloadContext());
std::shared_ptr<Option> op(new Option());
std::shared_ptr<DownloadContext> dctx(new DownloadContext());
bittorrent::load(uri, dctx, op);
bittorrent::print(*global::cout(), dctx);
}
@ -126,12 +125,12 @@ void showTorrentFile(const std::string& uri)
#ifdef ENABLE_METALINK
namespace {
void showMetalinkFile
(const std::string& uri, const SharedHandle<Option>& op)
(const std::string& uri, const std::shared_ptr<Option>& op)
{
std::vector<SharedHandle<MetalinkEntry> > metalinkEntries;
std::vector<std::shared_ptr<MetalinkEntry> > metalinkEntries;
metalink::parseAndQuery(metalinkEntries, uri, op.get(),
op->get(PREF_METALINK_BASE_URI));
std::vector<SharedHandle<FileEntry> > fileEntries;
std::vector<std::shared_ptr<FileEntry> > fileEntries;
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
util::toStream(fileEntries.begin(), fileEntries.end(), *global::cout());
global::cout()->write("\n");
@ -143,7 +142,7 @@ void showMetalinkFile
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
namespace {
void showFiles
(const std::vector<std::string>& uris, const SharedHandle<Option>& op)
(const std::vector<std::string>& uris, const std::shared_ptr<Option>& op)
{
ProtocolDetector dt;
for(std::vector<std::string>::const_iterator i = uris.begin(),
@ -183,7 +182,7 @@ Context::Context(bool standalone,
int argc, char** argv, const KeyVals& options)
{
std::vector<std::string> args;
SharedHandle<Option> op(new Option());
std::shared_ptr<Option> op(new Option());
error_code::Value rv;
rv = option_processing(*op.get(), standalone, args, argc, argv, options);
if(rv != error_code::FINISHED) {
@ -222,8 +221,8 @@ Context::Context(bool standalone,
std::string iface = op->get(PREF_INTERFACE);
SocketCore::bindAddress(iface);
}
std::vector<SharedHandle<RequestGroup> > requestGroups;
SharedHandle<UriListParser> uriListParser;
std::vector<std::shared_ptr<RequestGroup> > requestGroups;
std::shared_ptr<UriListParser> uriListParser;
#ifdef ENABLE_BITTORRENT
if(!op->blank(PREF_TORRENT_FILE)) {
if(op->get(PREF_SHOW_FILES) == A2_V_TRUE) {
@ -266,7 +265,7 @@ Context::Context(bool standalone,
// command-line. If they are left, because op is used as a template
// for new RequestGroup(such as created in RPC command), they causes
// unintentional effect.
for(SharedHandle<Option> i = op; i; i = i->getParent()) {
for(std::shared_ptr<Option> i = op; i; i = i->getParent()) {
i->remove(PREF_OUT);
i->remove(PREF_FORCE_SEQUENTIAL);
i->remove(PREF_INPUT_FILE);

View File

@ -36,8 +36,10 @@
#define CONTEXT_H
#include "common.h"
#include <memory>
#include <aria2/aria2.h>
#include "SharedHandle.h"
namespace aria2 {
@ -51,7 +53,7 @@ struct Context {
// as a part of command-line arguments.
Context(bool standalone, int argc, char** argv, const KeyVals& options);
~Context();
SharedHandle<MultiUrlRequestInfo> reqinfo;
std::shared_ptr<MultiUrlRequestInfo> reqinfo;
};
} // namespace aria2

View File

@ -192,7 +192,7 @@ const double DOMAIN_EVICTION_RATE = 0.1;
bool CookieStorage::store(const Cookie& cookie, time_t now)
{
if(domains_.size() >= DOMAIN_EVICTION_TRIGGER) {
std::vector<SharedHandle<DomainEntry> > evictions(domains_.begin(),
std::vector<std::shared_ptr<DomainEntry> > evictions(domains_.begin(),
domains_.end());
std::sort(evictions.begin(), evictions.end(),
LeastRecentAccess<DomainEntry>());
@ -200,7 +200,7 @@ bool CookieStorage::store(const Cookie& cookie, time_t now)
domains_.clear();
domains_.insert(evictions.begin()+delnum, evictions.end());
}
SharedHandle<DomainEntry> v(new DomainEntry(cookie.getDomain()));
std::shared_ptr<DomainEntry> v(new DomainEntry(cookie.getDomain()));
DomainEntrySet::iterator i = domains_.lower_bound(v);
bool added = false;
if(i != domains_.end() && *(*i) == *v) {
@ -292,7 +292,7 @@ void CookieStorage::searchCookieByDomainSuffix
const std::string& requestPath,
time_t now, bool secure)
{
SharedHandle<DomainEntry> v(new DomainEntry(domain));
std::shared_ptr<DomainEntry> v(new DomainEntry(domain));
DomainEntrySet::iterator i = domains_.lower_bound(v);
if(i != domains_.end() && *(*i) == *v) {
(*i)->setLastAccessTime(now);
@ -302,7 +302,7 @@ void CookieStorage::searchCookieByDomainSuffix
bool CookieStorage::contains(const Cookie& cookie) const
{
SharedHandle<DomainEntry> v(new DomainEntry(cookie.getDomain()));
std::shared_ptr<DomainEntry> v(new DomainEntry(cookie.getDomain()));
DomainEntrySet::iterator i = domains_.find(v);
if(i != domains_.end()) {
return (*i)->contains(cookie);

View File

@ -114,8 +114,8 @@ public:
bool operator<(const DomainEntry& de) const;
};
private:
typedef std::set<SharedHandle<DomainEntry>,
DerefLess<SharedHandle<DomainEntry> > > DomainEntrySet;
typedef std::set<std::shared_ptr<DomainEntry>,
DerefLess<std::shared_ptr<DomainEntry> > > DomainEntrySet;
DomainEntrySet domains_;
template<typename InputIterator>

View File

@ -55,9 +55,9 @@ CreateRequestCommand::CreateRequestCommand(cuid_t cuid,
RequestGroup* requestGroup,
DownloadEngine* e):
AbstractCommand
(cuid, SharedHandle<Request>(), SharedHandle<FileEntry>(), requestGroup, e,
SharedHandle<SocketCore>(),
SharedHandle<SocketRecvBuffer>(),
(cuid, std::shared_ptr<Request>(), std::shared_ptr<FileEntry>(), requestGroup, e,
std::shared_ptr<SocketCore>(),
std::shared_ptr<SocketRecvBuffer>(),
false)
{
setStatus(Command::STATUS_ONESHOT_REALTIME);

View File

@ -46,8 +46,8 @@
namespace aria2 {
DHTAbstractMessage::DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
DHTAbstractMessage::DHTAbstractMessage(const std::shared_ptr<DHTNode>& localNode,
const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID):
DHTMessage(localNode, remoteNode, transactionID),
connection_(0),

View File

@ -56,8 +56,8 @@ private:
DHTRoutingTable* routingTable_;
public:
DHTAbstractMessage(const SharedHandle<DHTNode>& localNode,
const SharedHandle<DHTNode>& remoteNode,
DHTAbstractMessage(const std::shared_ptr<DHTNode>& localNode,
const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = A2STR::NIL);
virtual ~DHTAbstractMessage();

View File

@ -67,31 +67,31 @@ class DHTAbstractNodeLookupTask:public DHTAbstractTask {
private:
unsigned char targetID_[DHT_ID_LENGTH];
std::deque<SharedHandle<DHTNodeLookupEntry> > entries_;
std::deque<std::shared_ptr<DHTNodeLookupEntry> > entries_;
size_t inFlightMessage_;
template<typename Container>
void toEntries
(Container& entries, const std::vector<SharedHandle<DHTNode> >& nodes) const
(Container& entries, const std::vector<std::shared_ptr<DHTNode> >& nodes) const
{
for(std::vector<SharedHandle<DHTNode> >::const_iterator i = nodes.begin(),
for(std::vector<std::shared_ptr<DHTNode> >::const_iterator i = nodes.begin(),
eoi = nodes.end(); i != eoi; ++i) {
SharedHandle<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
std::shared_ptr<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
entries.push_back(e);
}
}
void sendMessage()
{
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end();
i != eoi && inFlightMessage_ < ALPHA; ++i) {
if((*i)->used == false) {
++inFlightMessage_;
(*i)->used = true;
SharedHandle<DHTMessage> m = createMessage((*i)->node);
SharedHandle<DHTMessageCallback> callback(createCallback());
std::shared_ptr<DHTMessage> m = createMessage((*i)->node);
std::shared_ptr<DHTMessageCallback> callback(createCallback());
getMessageDispatcher()->addMessageToQueue(m, callback);
}
}
@ -122,13 +122,13 @@ protected:
return targetID_;
}
const std::deque<SharedHandle<DHTNodeLookupEntry> >& getEntries() const
const std::deque<std::shared_ptr<DHTNodeLookupEntry> >& getEntries() const
{
return entries_;
}
virtual void getNodesFromMessage
(std::vector<SharedHandle<DHTNode> >& nodes,
(std::vector<std::shared_ptr<DHTNode> >& nodes,
const ResponseMessage* message) = 0;
virtual void onReceivedInternal
@ -138,10 +138,10 @@ protected:
virtual void onFinish() {}
virtual SharedHandle<DHTMessage> createMessage
(const SharedHandle<DHTNode>& remoteNode) = 0;
virtual std::shared_ptr<DHTMessage> createMessage
(const std::shared_ptr<DHTNode>& remoteNode) = 0;
virtual SharedHandle<DHTMessageCallback> createCallback() = 0;
virtual std::shared_ptr<DHTMessageCallback> createCallback() = 0;
public:
DHTAbstractNodeLookupTask(const unsigned char* targetID):
inFlightMessage_(0)
@ -153,7 +153,7 @@ public:
virtual void startup()
{
std::vector<SharedHandle<DHTNode> > nodes;
std::vector<std::shared_ptr<DHTNode> > nodes;
getRoutingTable()->getClosestKNodes(nodes, targetID_);
entries_.clear();
toEntries(entries_, nodes);
@ -174,7 +174,7 @@ public:
{
--inFlightMessage_;
// Replace old Node ID with new Node ID.
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->node->getIPAddress() == message->getRemoteNode()->getIPAddress()
&& (*i)->node->getPort() == message->getRemoteNode()->getPort()) {
@ -182,13 +182,13 @@ public:
}
}
onReceivedInternal(message);
std::vector<SharedHandle<DHTNode> > nodes;
std::vector<std::shared_ptr<DHTNode> > nodes;
getNodesFromMessage(nodes, message);
std::vector<SharedHandle<DHTNodeLookupEntry> > newEntries;
std::vector<std::shared_ptr<DHTNodeLookupEntry> > newEntries;
toEntries(newEntries, nodes);
size_t count = 0;
for(std::vector<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
for(std::vector<std::shared_ptr<DHTNodeLookupEntry> >::const_iterator i =
newEntries.begin(), eoi = newEntries.end(); i != eoi; ++i) {
if(memcmp(getLocalNode()->getID(), (*i)->node->getID(),
DHT_ID_LENGTH) != 0) {
@ -205,7 +205,7 @@ public:
std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
entries_.erase
(std::unique(entries_.begin(), entries_.end(),
DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()),
DerefEqualTo<std::shared_ptr<DHTNodeLookupEntry> >()),
entries_.end());
A2_LOG_DEBUG(fmt("%lu node lookup entries are unique.",
static_cast<unsigned long>(entries_.size())));
@ -215,12 +215,12 @@ public:
sendMessageAndCheckFinish();
}
void onTimeout(const SharedHandle<DHTNode>& node)
void onTimeout(const std::shared_ptr<DHTNode>& node)
{
A2_LOG_DEBUG(fmt("node lookup message timeout for node ID=%s",
util::toHex(node->getID(), DHT_ID_LENGTH).c_str()));
--inFlightMessage_;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
for(std::deque<std::shared_ptr<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if(*(*i)->node == *node) {
entries_.erase(i);

View File

@ -78,7 +78,7 @@ void DHTAbstractTask::setTaskQueue(DHTTaskQueue* taskQueue)
taskQueue_ = taskQueue;
}
void DHTAbstractTask::setLocalNode(const SharedHandle<DHTNode>& localNode)
void DHTAbstractTask::setLocalNode(const std::shared_ptr<DHTNode>& localNode)
{
localNode_ = localNode;
}

View File

@ -36,7 +36,9 @@
#define D_DHT_ABSTRACT_TASK_H
#include "DHTTask.h"
#include "SharedHandle.h"
#include <memory>
#include "DHTConstants.h"
namespace aria2 {
@ -52,7 +54,7 @@ class DHTAbstractTask:public DHTTask {
private:
bool finished_;
SharedHandle<DHTNode> localNode_;
std::shared_ptr<DHTNode> localNode_;
DHTRoutingTable* routingTable_;
@ -99,12 +101,12 @@ public:
void setTaskQueue(DHTTaskQueue* taskQueue);
const SharedHandle<DHTNode>& getLocalNode() const
const std::shared_ptr<DHTNode>& getLocalNode() const
{
return localNode_;
}
void setLocalNode(const SharedHandle<DHTNode>& localNode);
void setLocalNode(const std::shared_ptr<DHTNode>& localNode);
};
} // namespace aria2

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