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 # Check pkg-config is available
PKG_PROG_PKG_CONFIG([0.20]) PKG_PROG_PKG_CONFIG([0.20])
CXXFLAGS="-std=c++11 $CXXFLAGS"
# Check static build is requested # Check static build is requested
if test "x$ARIA2_STATIC" = "xyes"; then if test "x$ARIA2_STATIC" = "xyes"; then
case "$host" in case "$host" in

View File

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

View File

@ -41,24 +41,24 @@ namespace aria2 {
class AbstractAuthResolver : public AuthResolver { class AbstractAuthResolver : public AuthResolver {
private: private:
SharedHandle<AuthConfig> userDefinedAuthConfig_; std::shared_ptr<AuthConfig> userDefinedAuthConfig_;
SharedHandle<AuthConfig> defaultAuthConfig_; std::shared_ptr<AuthConfig> defaultAuthConfig_;
public: public:
AbstractAuthResolver(); AbstractAuthResolver();
virtual ~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_; 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_; return defaultAuthConfig_;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,9 @@
#define D_ACTIVE_PEER_CONNECTION_COMMAND_H #define D_ACTIVE_PEER_CONNECTION_COMMAND_H
#include "Command.h" #include "Command.h"
#include "SharedHandle.h"
#include <memory>
#include "TimerA2.h" #include "TimerA2.h"
namespace aria2 { namespace aria2 {
@ -52,10 +54,10 @@ class BtAnnounce;
class ActivePeerConnectionCommand : public Command { class ActivePeerConnectionCommand : public Command {
private: private:
RequestGroup* requestGroup_; RequestGroup* requestGroup_;
SharedHandle<BtRuntime> btRuntime_; std::shared_ptr<BtRuntime> btRuntime_;
SharedHandle<PieceStorage> pieceStorage_; std::shared_ptr<PieceStorage> pieceStorage_;
SharedHandle<PeerStorage> peerStorage_; std::shared_ptr<PeerStorage> peerStorage_;
SharedHandle<BtAnnounce> btAnnounce_; std::shared_ptr<BtAnnounce> btAnnounce_;
time_t interval_; // UNIT: sec time_t interval_; // UNIT: sec
DownloadEngine* e_; DownloadEngine* e_;
@ -78,13 +80,13 @@ public:
numNewConnection_ = numNewConnection; 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 } // namespace aria2

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -47,9 +47,9 @@ public:
AnonDiskWriterFactory() {} AnonDiskWriterFactory() {}
virtual ~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> CC_SHA512_Final>
MessageDigestSHA512; 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) (const std::string& hashType)
{ {
if (hashType == "sha-1") { if (hashType == "sha-1") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA1()); return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA1());
} }
if (hashType == "sha-224") { if (hashType == "sha-224") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA224()); return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA224());
} }
if (hashType == "sha-256") { if (hashType == "sha-256") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA256()); return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA256());
} }
if (hashType == "sha-384") { if (hashType == "sha-384") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA384()); return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA384());
} }
if (hashType == "sha-512") { if (hashType == "sha-512") {
return SharedHandle<MessageDigestImpl>(new MessageDigestSHA512()); return std::shared_ptr<MessageDigestImpl>(new MessageDigestSHA512());
} }
if (hashType == "md5") { 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) 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) size_t MessageDigestImpl::getDigestLength(const std::string& hashType)
{ {
SharedHandle<MessageDigestImpl> impl = create(hashType); std::shared_ptr<MessageDigestImpl> impl = create(hashType);
if (!impl) { if (!impl) {
return 0; return 0;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -51,7 +51,7 @@ BackupConnectInfo::BackupConnectInfo()
BackupIPv4ConnectCommand::BackupIPv4ConnectCommand BackupIPv4ConnectCommand::BackupIPv4ConnectCommand
(cuid_t cuid, const std::string& ipaddr, uint16_t port, (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) RequestGroup* requestGroup, DownloadEngine* e)
: Command(cuid), : Command(cuid),
ipaddr_(ipaddr), ipaddr_(ipaddr),
@ -83,14 +83,15 @@ bool BackupIPv4ConnectCommand::execute()
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) { if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
retval = true; retval = true;
} else if(info_->cancel) { } 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; retval = true;
} else if(socket_) { } else if(socket_) {
if(writeEventEnabled()) { if(writeEventEnabled()) {
try { try {
std::string error = socket_->getSocketError(); std::string error = socket_->getSocketError();
if(error.empty()) { 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())); "established", getCuid(), ipaddr_.c_str()));
info_->ipaddr = ipaddr_; info_->ipaddr = ipaddr_;
e_->deleteSocketForWriteCheck(socket_, this); e_->deleteSocketForWriteCheck(socket_, this);
@ -99,12 +100,12 @@ bool BackupIPv4ConnectCommand::execute()
e_->setNoWait(true); e_->setNoWait(true);
retval = true; retval = true;
} else { } 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())); getCuid(), error.c_str()));
retval = true; retval = true;
} }
} catch(RecoverableException& e) { } 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); getCuid()), e);
retval = true; retval = true;
} }
@ -120,14 +121,14 @@ bool BackupIPv4ConnectCommand::execute()
e_->addSocketForWriteCheck(socket_, this); e_->addSocketForWriteCheck(socket_, this);
timeoutCheck_ = global::wallclock(); timeoutCheck_ = global::wallclock();
} catch(RecoverableException& e) { } 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); getCuid()), e);
socket_.reset(); socket_.reset();
retval = true; retval = true;
} }
} }
} else if(timeoutCheck_.difference(global::wallclock()) >= timeout_) { } 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())); getCuid()));
retval = true; retval = true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -60,7 +60,7 @@ public:
*/ */
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId); 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); create(const unsigned char* data, size_t dataLength);
virtual ~BtHandshakeMessage() { virtual ~BtHandshakeMessage() {

View File

@ -36,7 +36,8 @@
#define D_BT_INTERACTIVE_H #define D_BT_INTERACTIVE_H
#include "common.h" #include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 { namespace aria2 {
@ -48,9 +49,9 @@ public:
virtual void initiateHandshake() = 0; 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; virtual void doPostHandshakeProcessing() = 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,8 @@
#define D_BT_MESSAGE_FACTORY_H #define D_BT_MESSAGE_FACTORY_H
#include "common.h" #include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 { namespace aria2 {
@ -49,52 +50,52 @@ class BtMessageFactory {
public: public:
virtual ~BtMessageFactory() {} virtual ~BtMessageFactory() {}
virtual SharedHandle<BtMessage> virtual std::shared_ptr<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength) = 0; 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; createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0;
virtual SharedHandle<BtHandshakeMessage> virtual std::shared_ptr<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash, createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId) = 0; const unsigned char* peerId) = 0;
virtual SharedHandle<BtMessage> virtual std::shared_ptr<BtMessage>
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0; 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; 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; 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; 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> virtual std::shared_ptr<BtMessage>
createBtExtendedMessage(const SharedHandle<ExtensionMessage>& msg) = 0; createBtExtendedMessage(const std::shared_ptr<ExtensionMessage>& msg) = 0;
}; };
} // namespace aria2 } // namespace aria2

View File

@ -36,7 +36,8 @@
#define D_BT_MESSAGE_RECEIVER_H #define D_BT_MESSAGE_RECEIVER_H
#include "common.h" #include "common.h"
#include "SharedHandle.h"
#include <memory>
namespace aria2 { namespace aria2 {
@ -47,11 +48,11 @@ class BtMessageReceiver {
public: public:
virtual ~BtMessageReceiver() {} 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 } // namespace aria2

View File

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

View File

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

View File

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

View File

@ -49,16 +49,16 @@ private:
int32_t begin_; int32_t begin_;
int32_t blockLength_; int32_t blockLength_;
const unsigned char* data_; const unsigned char* data_;
SharedHandle<DownloadContext> downloadContext_; std::shared_ptr<DownloadContext> downloadContext_;
SharedHandle<PeerStorage> peerStorage_; std::shared_ptr<PeerStorage> peerStorage_;
static size_t MESSAGE_HEADER_LENGTH; 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; void pushPieceData(int64_t offset, int32_t length) const;
public: public:
@ -88,9 +88,9 @@ public:
void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; } 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); 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 // 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. // 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->setIPAddress(getPeer()->getIPAddress());
node->setPort(port_); node->setPort(port_);
{ {
SharedHandle<DHTTask> task = taskFactory_->createPingTask(node); std::shared_ptr<DHTTask> task = taskFactory_->createPingTask(node);
taskQueue_->addImmediateTask(task); taskQueue_->addImmediateTask(task);
} }
if(routingTable_->getNumBucket() == 1) { if(routingTable_->getNumBucket() == 1) {

View File

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

View File

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

View File

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

View File

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

View File

@ -38,8 +38,7 @@
#include "common.h" #include "common.h"
#include <vector> #include <vector>
#include <memory>
#include "SharedHandle.h"
namespace aria2 { namespace aria2 {
@ -50,9 +49,9 @@ class BtRequestFactory {
public: public:
virtual ~BtRequestFactory() {} 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; virtual void removeAllTargetPiece() = 0;
@ -70,14 +69,14 @@ public:
* The number of objects returned is capped by max. * The number of objects returned is capped by max.
*/ */
virtual void createRequestMessages 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. * Use this method in end game mode.
* *
*/ */
virtual void createRequestMessagesOnEndGame 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 * 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()->amChoking() && (getPeer()->amChoking() &&
getPeer()->isInAmAllowedIndexSet(getIndex())))) { getPeer()->isInAmAllowedIndexSet(getIndex())))) {
SharedHandle<BtMessage> msg = std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createPieceMessage getBtMessageFactory()->createPieceMessage
(getIndex(), getBegin(), getLength()); (getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg); getBtMessageDispatcher()->addMessageToQueue(msg);
} else { } else {
if(getPeer()->isFastExtensionEnabled()) { if(getPeer()->isFastExtensionEnabled()) {
SharedHandle<BtMessage> msg = std::shared_ptr<BtMessage> msg =
getBtMessageFactory()->createRejectMessage getBtMessageFactory()->createRejectMessage
(getIndex(), getBegin(), getLength()); (getIndex(), getBegin(), getLength());
getBtMessageDispatcher()->addMessageToQueue(msg); getBtMessageDispatcher()->addMessageToQueue(msg);

View File

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

View File

@ -38,8 +38,8 @@
#include "common.h" #include "common.h"
#include <vector> #include <vector>
#include <memory>
#include "SharedHandle.h"
#include "TimerA2.h" #include "TimerA2.h"
#include "PeerStorage.h" #include "PeerStorage.h"
@ -55,7 +55,7 @@ private:
class PeerEntry { class PeerEntry {
private: private:
SharedHandle<Peer> peer_; std::shared_ptr<Peer> peer_;
size_t outstandingUpload_; size_t outstandingUpload_;
Timer lastAmUnchoking_; Timer lastAmUnchoking_;
bool recentUnchoking_; bool recentUnchoking_;
@ -63,7 +63,7 @@ private:
const static time_t TIME_FRAME = 20; const static time_t TIME_FRAME = 20;
public: public:
PeerEntry(const SharedHandle<Peer>& peer); PeerEntry(const std::shared_ptr<Peer>& peer);
PeerEntry(const PeerEntry& c); PeerEntry(const PeerEntry& c);
~PeerEntry(); ~PeerEntry();
@ -73,7 +73,7 @@ private:
bool operator<(const PeerEntry& rhs) const; 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_; } 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)){ if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){
return; return;
} }
SharedHandle<TorrentAttribute> torrentAttrs = std::shared_ptr<TorrentAttribute> torrentAttrs =
bittorrent::getTorrentAttrs(requestGroup->getDownloadContext()); bittorrent::getTorrentAttrs(requestGroup->getDownloadContext());
bool metadataGetMode = torrentAttrs->metadata.empty(); bool metadataGetMode = torrentAttrs->metadata.empty();
const SharedHandle<BtRegistry>& btReg = e->getBtRegistry(); const std::shared_ptr<BtRegistry>& btReg = e->getBtRegistry();
const SharedHandle<BtObject>& btObject = btReg->get(requestGroup->getGID()); const std::shared_ptr<BtObject>& btObject = btReg->get(requestGroup->getGID());
const SharedHandle<PieceStorage>& pieceStorage = btObject->pieceStorage; const std::shared_ptr<PieceStorage>& pieceStorage = btObject->pieceStorage;
const SharedHandle<PeerStorage>& peerStorage = btObject->peerStorage; const std::shared_ptr<PeerStorage>& peerStorage = btObject->peerStorage;
const SharedHandle<BtRuntime>& btRuntime = btObject->btRuntime; const std::shared_ptr<BtRuntime>& btRuntime = btObject->btRuntime;
const SharedHandle<BtAnnounce>& btAnnounce = btObject->btAnnounce; const std::shared_ptr<BtAnnounce>& btAnnounce = btObject->btAnnounce;
// commands // commands
{ {
TrackerWatcherCommand* c = TrackerWatcherCommand* c =
@ -159,16 +159,16 @@ void BtSetup::setup(std::vector<Command*>& commands,
} }
} }
if(!metadataGetMode) { if(!metadataGetMode) {
SharedHandle<UnionSeedCriteria> unionCri(new UnionSeedCriteria()); std::shared_ptr<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
if(option->defined(PREF_SEED_TIME)) { if(option->defined(PREF_SEED_TIME)) {
SharedHandle<SeedCriteria> cri std::shared_ptr<SeedCriteria> cri
(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60)); (new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60));
unionCri->addSeedCriteria(cri); unionCri->addSeedCriteria(cri);
} }
{ {
double ratio = option->getAsDouble(PREF_SEED_RATIO); double ratio = option->getAsDouble(PREF_SEED_RATIO);
if(ratio > 0.0) { if(ratio > 0.0) {
SharedHandle<ShareRatioSeedCriteria> cri std::shared_ptr<ShareRatioSeedCriteria> cri
(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO), (new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO),
requestGroup->getDownloadContext())); requestGroup->getDownloadContext()));
cri->setPieceStorage(pieceStorage); cri->setPieceStorage(pieceStorage);
@ -223,7 +223,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
(metadataGetMode || !torrentAttrs->privateTorrent)) { (metadataGetMode || !torrentAttrs->privateTorrent)) {
if(!btReg->getLpdMessageReceiver()) { if(!btReg->getLpdMessageReceiver()) {
A2_LOG_INFO("Initializing LpdMessageReceiver."); A2_LOG_INFO("Initializing LpdMessageReceiver.");
SharedHandle<LpdMessageReceiver> receiver std::shared_ptr<LpdMessageReceiver> receiver
(new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT)); (new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
bool initialized = false; bool initialized = false;
const std::string& lpdInterface = const std::string& lpdInterface =
@ -263,7 +263,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
const unsigned char* infoHash = const unsigned char* infoHash =
bittorrent::getInfoHash(requestGroup->getDownloadContext()); bittorrent::getInfoHash(requestGroup->getDownloadContext());
A2_LOG_INFO("Initializing LpdMessageDispatcher."); A2_LOG_INFO("Initializing LpdMessageDispatcher.");
SharedHandle<LpdMessageDispatcher> dispatcher std::shared_ptr<LpdMessageDispatcher> dispatcher
(new LpdMessageDispatcher (new LpdMessageDispatcher
(std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]), (std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]),
btReg->getTcpPort(), btReg->getTcpPort(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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