diff options
| author | Nils Maier <maierman@web.de> | 2013-11-26 02:59:51 +0100 |
|---|---|---|
| committer | Nils Maier <maierman@web.de> | 2013-12-09 15:41:43 +0100 |
| commit | 2db0c81fc8067d73230fcbffc90bd7ad1f9c07b0 (patch) | |
| tree | a6c37eaa4de5ef4c8b4e982cb7d87c1f6ac5bf3b /src | |
| parent | 1323048ab1a254510e32d47f5549f4e30d273e5a (diff) | |
Stuff memory holes
Padding changes on x86_64:
- RequestGroup: 29 -> 5 bytes
- DownloadContext: 25 -> 1 bytes
- Cookie: 20 -> 4 bytes
- Command: 8 -> 0 bytes (affects many derived as well)
- HttpRequest: 20 -> 4 bytes
- DownloadCommand: 18 -> 2 bytes
- TimeBasedCommand: 14 -> 6 bytes
- AbstractCommand: 13 -> 5 bytes
- HttpSkipResponseCommand: 12 -> 4 bytes
- FileEntry: 10 -> 2 bytes
- DownloadResult: 15 -> 7 bytes
- UriStruct: 12 -> 4 bytes
- Piece: 11 -> 3 bytes
- BitfieldMan -> 11 -> 3 bytes
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractCommand.cc | 35 | ||||
| -rw-r--r-- | src/AbstractCommand.h | 34 | ||||
| -rw-r--r-- | src/BitfieldMan.cc | 54 | ||||
| -rw-r--r-- | src/BitfieldMan.h | 20 | ||||
| -rw-r--r-- | src/Command.cc | 4 | ||||
| -rw-r--r-- | src/Command.h | 7 | ||||
| -rw-r--r-- | src/Cookie.cc | 64 | ||||
| -rw-r--r-- | src/Cookie.h | 31 | ||||
| -rw-r--r-- | src/DownloadCommand.cc | 14 | ||||
| -rw-r--r-- | src/DownloadCommand.h | 17 | ||||
| -rw-r--r-- | src/DownloadContext.cc | 33 | ||||
| -rw-r--r-- | src/DownloadContext.h | 24 | ||||
| -rw-r--r-- | src/DownloadResult.cc | 9 | ||||
| -rw-r--r-- | src/DownloadResult.h | 36 | ||||
| -rw-r--r-- | src/FileEntry.cc | 23 | ||||
| -rw-r--r-- | src/FileEntry.h | 30 | ||||
| -rw-r--r-- | src/HttpRequest.cc | 12 | ||||
| -rw-r--r-- | src/HttpRequest.h | 31 | ||||
| -rw-r--r-- | src/HttpSkipResponseCommand.cc | 8 | ||||
| -rw-r--r-- | src/HttpSkipResponseCommand.h | 30 | ||||
| -rw-r--r-- | src/Piece.cc | 20 | ||||
| -rw-r--r-- | src/Piece.h | 27 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 38 | ||||
| -rw-r--r-- | src/RequestGroup.h | 92 | ||||
| -rw-r--r-- | src/TimeBasedCommand.cc | 11 | ||||
| -rw-r--r-- | src/TimeBasedCommand.h | 7 | ||||
| -rw-r--r-- | src/uri.cc | 6 | ||||
| -rw-r--r-- | src/uri.h | 2 |
28 files changed, 368 insertions, 351 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index a6b58260..5dad881a 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -76,26 +76,29 @@ namespace aria2 { -AbstractCommand::AbstractCommand -(cuid_t cuid, - const std::shared_ptr<Request>& req, - const std::shared_ptr<FileEntry>& fileEntry, - RequestGroup* requestGroup, - DownloadEngine* e, - const std::shared_ptr<SocketCore>& s, - const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer, - bool incNumConnection) - : Command(cuid), checkPoint_(global::wallclock()), - timeout_(requestGroup->getTimeout()), - requestGroup_(requestGroup), - req_(req), fileEntry_(fileEntry), e_(e), socket_(s), +AbstractCommand::AbstractCommand(cuid_t cuid, + const std::shared_ptr<Request>& req, + const std::shared_ptr<FileEntry>& fileEntry, + RequestGroup* requestGroup, DownloadEngine* e, + const std::shared_ptr<SocketCore>& s, + const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer, + bool incNumConnection) + : Command(cuid), + req_(req), + fileEntry_(fileEntry), + socket_(s), socketRecvBuffer_(socketRecvBuffer), #ifdef ENABLE_ASYNC_DNS asyncNameResolverMan_(make_unique<AsyncNameResolverMan>()), #endif // ENABLE_ASYNC_DNS - checkSocketIsReadable_(false), checkSocketIsWritable_(false), - incNumConnection_(incNumConnection), - serverStatTimer_(global::wallclock()) + requestGroup_(requestGroup), + e_(e), + checkPoint_(global::wallclock()), + serverStatTimer_(global::wallclock()), + timeout_(requestGroup->getTimeout()), + checkSocketIsReadable_(false), + checkSocketIsWritable_(false), + incNumConnection_(incNumConnection) { if(socket_ && socket_->isOpen()) { setReadCheckSocket(socket_); diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 23fb4950..7f6c9429 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -64,31 +64,34 @@ class AsyncNameResolverMan; class AbstractCommand : public Command { private: - Timer checkPoint_; - time_t timeout_; - - RequestGroup* requestGroup_; std::shared_ptr<Request> req_; std::shared_ptr<FileEntry> fileEntry_; - DownloadEngine* e_; std::shared_ptr<SocketCore> socket_; std::shared_ptr<SocketRecvBuffer> socketRecvBuffer_; - std::vector<std::shared_ptr<Segment> > segments_; + std::shared_ptr<SocketCore> readCheckTarget_; + std::shared_ptr<SocketCore> writeCheckTarget_; #ifdef ENABLE_ASYNC_DNS std::unique_ptr<AsyncNameResolverMan> asyncNameResolverMan_; #endif // ENABLE_ASYNC_DNS + RequestGroup* requestGroup_; + DownloadEngine* e_; + + std::vector<std::shared_ptr<Segment> > segments_; + + Timer checkPoint_; + Timer serverStatTimer_; + time_t timeout_; + bool checkSocketIsReadable_; bool checkSocketIsWritable_; - std::shared_ptr<SocketCore> readCheckTarget_; - std::shared_ptr<SocketCore> writeCheckTarget_; bool incNumConnection_; - Timer serverStatTimer_; int32_t calculateMinSplitSize() const; void useFasterRequest(const std::shared_ptr<Request>& fasterRequest); + public: RequestGroup* getRequestGroup() const { @@ -234,13 +237,12 @@ protected: } public: - AbstractCommand - (cuid_t cuid, const std::shared_ptr<Request>& req, - const std::shared_ptr<FileEntry>& fileEntry, - RequestGroup* requestGroup, DownloadEngine* e, - const std::shared_ptr<SocketCore>& s = nullptr, - const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer = nullptr, - bool incNumConnection = true); + AbstractCommand(cuid_t cuid, const std::shared_ptr<Request>& req, + const std::shared_ptr<FileEntry>& fileEntry, + RequestGroup* requestGroup, DownloadEngine* e, + const std::shared_ptr<SocketCore>& s = nullptr, + const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer = nullptr, + bool incNumConnection = true); virtual ~AbstractCommand(); virtual bool execute() CXX11_OVERRIDE; diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index 4cfc9994..c1904205 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -45,19 +45,19 @@ using namespace aria2::expr; namespace aria2 { BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength) - :blockLength_(blockLength), - totalLength_(totalLength), - bitfieldLength_(0), - blocks_(0), - filterEnabled_(false), - bitfield_(nullptr), - useBitfield_(nullptr), - filterBitfield_(nullptr), - cachedNumMissingBlock_(0), - cachedNumFilteredBlock_(0), - cachedCompletedLength_(0), - cachedFilteredCompletedLength_(0), - cachedFilteredTotalLength_(0) + : totalLength_(totalLength), + cachedCompletedLength_(0), + cachedFilteredCompletedLength_(0), + cachedFilteredTotalLength_(0), + bitfield_(nullptr), + useBitfield_(nullptr), + filterBitfield_(nullptr), + bitfieldLength_(0), + cachedNumMissingBlock_(0), + cachedNumFilteredBlock_(0), + blocks_(0), + blockLength_(blockLength), + filterEnabled_(false) { if(blockLength_ > 0 && totalLength_ > 0) { blocks_ = (totalLength_+blockLength_-1)/blockLength_; @@ -71,19 +71,19 @@ BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength) } BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan) - :blockLength_(bitfieldMan.blockLength_), - totalLength_(bitfieldMan.totalLength_), - bitfieldLength_(bitfieldMan.bitfieldLength_), - blocks_(bitfieldMan.blocks_), - filterEnabled_(bitfieldMan.filterEnabled_), - bitfield_(new unsigned char[bitfieldLength_]), - useBitfield_(new unsigned char[bitfieldLength_]), - filterBitfield_(nullptr), - cachedNumMissingBlock_(0), - cachedNumFilteredBlock_(0), - cachedCompletedLength_(0), - cachedFilteredCompletedLength_(0), - cachedFilteredTotalLength_(0) + : totalLength_(bitfieldMan.totalLength_), + cachedCompletedLength_(0), + cachedFilteredCompletedLength_(0), + cachedFilteredTotalLength_(0), + bitfield_(new unsigned char[bitfieldMan.bitfieldLength_]), + useBitfield_(new unsigned char[bitfieldMan.bitfieldLength_]), + filterBitfield_(nullptr), + bitfieldLength_(bitfieldMan.bitfieldLength_), + cachedNumMissingBlock_(0), + cachedNumFilteredBlock_(0), + blocks_(bitfieldMan.blocks_), + blockLength_(bitfieldMan.blockLength_), + filterEnabled_(bitfieldMan.filterEnabled_) { memcpy(bitfield_, bitfieldMan.bitfield_, bitfieldLength_); memcpy(useBitfield_, bitfieldMan.useBitfield_, bitfieldLength_); @@ -97,8 +97,8 @@ BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan) BitfieldMan& BitfieldMan::operator=(const BitfieldMan& bitfieldMan) { if(this != &bitfieldMan) { - blockLength_ = bitfieldMan.blockLength_; totalLength_ = bitfieldMan.totalLength_; + blockLength_ = bitfieldMan.blockLength_; blocks_ = bitfieldMan.blocks_; bitfieldLength_ = bitfieldMan.bitfieldLength_; filterEnabled_ = bitfieldMan.filterEnabled_; diff --git a/src/BitfieldMan.h b/src/BitfieldMan.h index fa0ac09f..60e44547 100644 --- a/src/BitfieldMan.h +++ b/src/BitfieldMan.h @@ -43,21 +43,23 @@ namespace aria2 { class BitfieldMan { private: - int32_t blockLength_; int64_t totalLength_; - size_t bitfieldLength_; - size_t blocks_; - bool filterEnabled_; + int64_t cachedCompletedLength_; + int64_t cachedFilteredCompletedLength_; + int64_t cachedFilteredTotalLength_; + unsigned char* bitfield_; unsigned char* useBitfield_; unsigned char* filterBitfield_; - // for caching + size_t bitfieldLength_; size_t cachedNumMissingBlock_; size_t cachedNumFilteredBlock_; - int64_t cachedCompletedLength_; - int64_t cachedFilteredCompletedLength_; - int64_t cachedFilteredTotalLength_; + size_t blocks_; + + int32_t blockLength_; + + bool filterEnabled_; bool setBitInternal(unsigned char* bitfield, size_t index, bool on); bool setFilterBit(size_t index); @@ -70,6 +72,7 @@ private: // If filterBitfield_ is 0, allocate bitfieldLength_ bytes to it and // set 0 to all bytes. void ensureFilterBitfield(); + public: // [startIndex, endIndex) struct Range { @@ -81,6 +84,7 @@ public: bool operator<(const Range& range) const; bool operator==(const Range& range) const; }; + public: BitfieldMan(int32_t blockLength, int64_t totalLength); BitfieldMan(const BitfieldMan& bitfieldMan); diff --git a/src/Command.cc b/src/Command.cc index 82db3178..b9e236b7 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -38,8 +38,8 @@ namespace aria2 { Command::Command(cuid_t cuid) - : status_(STATUS_INACTIVE), - cuid_(cuid), + : cuid_(cuid), + status_(STATUS_INACTIVE), readEvent_(false), writeEvent_(false), errorEvent_(false), diff --git a/src/Command.h b/src/Command.h index a164661d..07d4de6d 100644 --- a/src/Command.h +++ b/src/Command.h @@ -50,15 +50,17 @@ public: STATUS_REALTIME, STATUS_ONESHOT_REALTIME }; -private: - STATUS status_; +private: cuid_t cuid_; + STATUS status_; + bool readEvent_; bool writeEvent_; bool errorEvent_; bool hupEvent_; + protected: bool readEventEnabled() const { @@ -79,6 +81,7 @@ protected: { return hupEvent_; } + public: Command(cuid_t cuid); diff --git a/src/Cookie.cc b/src/Cookie.cc index 2c8b881e..7da196a1 100644 --- a/src/Cookie.cc +++ b/src/Cookie.cc @@ -42,37 +42,32 @@ namespace aria2 { -Cookie::Cookie -(std::string name, - std::string value, - time_t expiryTime, - bool persistent, - std::string domain, - bool hostOnly, - std::string path, - bool secure, - bool httpOnly, - time_t creationTime): - name_(std::move(name)), - value_(std::move(value)), - expiryTime_(expiryTime), - persistent_(persistent), - domain_(std::move(domain)), - hostOnly_(hostOnly), - path_(std::move(path)), - secure_(secure), - httpOnly_(httpOnly), - creationTime_(creationTime), - lastAccessTime_(creationTime) {} - -Cookie::Cookie(): - expiryTime_(0), - persistent_(false), - hostOnly_(false), - secure_(false), - httpOnly_(false), - creationTime_(0), - lastAccessTime_(0) {} +Cookie::Cookie(std::string name, std::string value, time_t expiryTime, + bool persistent, std::string domain, bool hostOnly, + std::string path, bool secure, bool httpOnly, + time_t creationTime) + : expiryTime_(expiryTime), + creationTime_(creationTime), + lastAccessTime_(creationTime), + name_(std::move(name)), + value_(std::move(value)), + domain_(std::move(domain)), + path_(std::move(path)), + persistent_(persistent), + hostOnly_(hostOnly), + secure_(secure), + httpOnly_(httpOnly) +{} + +Cookie::Cookie() + : expiryTime_(0), + creationTime_(0), + lastAccessTime_(0), + persistent_(false), + hostOnly_(false), + secure_(false), + httpOnly_(false) +{} std::string Cookie::toString() const { @@ -82,10 +77,9 @@ std::string Cookie::toString() const return s; } -bool Cookie::match -(const std::string& requestHost, - const std::string& requestPath, - time_t date, bool secure) const +bool Cookie::match(const std::string& requestHost, + const std::string& requestPath, + time_t date, bool secure) const { if((secure_ && !secure) || isExpired(date) || !cookie::pathMatch(requestPath, path_)) { diff --git a/src/Cookie.h b/src/Cookie.h index d97ddaeb..aa711724 100644 --- a/src/Cookie.h +++ b/src/Cookie.h @@ -45,40 +45,31 @@ namespace aria2 { class Cookie { private: + time_t expiryTime_; + time_t creationTime_; + time_t lastAccessTime_; std::string name_; std::string value_; - time_t expiryTime_; + std::string domain_; + std::string path_; // If persistent_ is false, this is a session scope cookie and it is // never expired during session. So isExpired() always returns // false. bool persistent_; - std::string domain_; bool hostOnly_; - std::string path_; bool secure_; bool httpOnly_; - time_t creationTime_; - time_t lastAccessTime_; + public: Cookie(); - - Cookie - (std::string name, - std::string value, - time_t expiryTime, - bool persistent, - std::string domain, - bool hostOnly, - std::string path, - bool secure, - bool httpOnly, - time_t creationTime); + Cookie(std::string name, std::string value, time_t expiryTime, + bool persistent, std::string domain, bool hostOnly, std::string path, + bool secure, bool httpOnly, time_t creationTime); std::string toString() const; - bool match - (const std::string& requestHost, const std::string& requestPath, - time_t date, bool secure) const; + bool match(const std::string& requestHost, const std::string& requestPath, + time_t date, bool secure) const; bool operator==(const Cookie& cookie) const; diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 4665efa8..f1563cfe 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -79,14 +79,12 @@ namespace { const size_t BUFSIZE = 16*1024; } // namespace -DownloadCommand::DownloadCommand -(cuid_t cuid, - const std::shared_ptr<Request>& req, - const std::shared_ptr<FileEntry>& fileEntry, - RequestGroup* requestGroup, - DownloadEngine* e, - const std::shared_ptr<SocketCore>& s, - const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer) +DownloadCommand::DownloadCommand(cuid_t cuid, + const std::shared_ptr<Request>& req, + const std::shared_ptr<FileEntry>& fileEntry, + RequestGroup* requestGroup, DownloadEngine* e, + const std::shared_ptr<SocketCore>& s, + const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer) : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s, socketRecvBuffer), startupIdleTime_(10), lowestDownloadSpeedLimit_(0), diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index 02520c2c..ddb87da1 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -49,18 +49,22 @@ class MessageDigest; class DownloadCommand : public AbstractCommand { private: - time_t startupIdleTime_; - int lowestDownloadSpeedLimit_; std::shared_ptr<PeerStat> peerStat_; - bool pieceHashValidationEnabled_; + std::unique_ptr<StreamFilter> streamFilter_; #ifdef ENABLE_MESSAGE_DIGEST - std::unique_ptr<MessageDigest> messageDigest_; - #endif // ENABLE_MESSAGE_DIGEST + time_t startupIdleTime_; + + int lowestDownloadSpeedLimit_; + + bool pieceHashValidationEnabled_; + + bool sinkFilterOnly_; + void validatePieceHash(const std::shared_ptr<Segment>& segment, const std::string& expectedPieceHash, const std::string& actualPieceHash); @@ -69,9 +73,6 @@ private: void completeSegment(cuid_t cuid, const std::shared_ptr<Segment>& segment); - std::unique_ptr<StreamFilter> streamFilter_; - - bool sinkFilterOnly_; protected: virtual bool executeInternal() CXX11_OVERRIDE; diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index cb945663..819a51cd 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -47,25 +47,26 @@ namespace aria2 { -DownloadContext::DownloadContext(): - pieceLength_(0), - checksumVerified_(false), - knowsTotalLength_(true), - ownerRequestGroup_(nullptr), - attrs_(MAX_CTX_ATTR), - downloadStopTime_(0), - acceptMetalink_(true) {} +DownloadContext::DownloadContext() + : ownerRequestGroup_(nullptr), + attrs_(MAX_CTX_ATTR), + downloadStopTime_(0), + pieceLength_(0), + checksumVerified_(false), + knowsTotalLength_(true), + acceptMetalink_(true) +{} DownloadContext::DownloadContext(int32_t pieceLength, int64_t totalLength, - const std::string& path): - pieceLength_(pieceLength), - checksumVerified_(false), - knowsTotalLength_(true), - ownerRequestGroup_(nullptr), - attrs_(MAX_CTX_ATTR), - downloadStopTime_(0), - acceptMetalink_(true) + const std::string& path) + : ownerRequestGroup_(nullptr), + attrs_(MAX_CTX_ATTR), + downloadStopTime_(0), + pieceLength_(pieceLength), + checksumVerified_(false), + knowsTotalLength_(true), + acceptMetalink_(true) { std::shared_ptr<FileEntry> fileEntry(new FileEntry(path, totalLength, 0)); fileEntries_.push_back(fileEntry); diff --git a/src/DownloadContext.h b/src/DownloadContext.h index fe1e665a..310bcccc 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -58,11 +58,19 @@ class FileEntry; class DownloadContext { private: + std::unique_ptr<Signature> signature_; + + RequestGroup* ownerRequestGroup_; + + std::vector<std::unique_ptr<ContextAttribute> > attrs_; + std::vector<std::shared_ptr<FileEntry> > fileEntries_; std::vector<std::string> pieceHashes_; - int32_t pieceLength_; + NetStat netStat_; + + Timer downloadStopTime_; std::string pieceHashType_; @@ -70,24 +78,18 @@ private: std::string hashType_; - bool checksumVerified_; - std::string basePath_; - bool knowsTotalLength_; - - RequestGroup* ownerRequestGroup_; - - std::vector<std::unique_ptr<ContextAttribute> > attrs_; + int32_t pieceLength_; - NetStat netStat_; + bool checksumVerified_; - Timer downloadStopTime_; + bool knowsTotalLength_; - std::unique_ptr<Signature> signature_; // This member variable is required to avoid to use parse Metalink // (including both Metalink XML and Metalink/HTTP) twice. bool acceptMetalink_; + public: DownloadContext(); diff --git a/src/DownloadResult.cc b/src/DownloadResult.cc index 49cba379..faa9b1c0 100644 --- a/src/DownloadResult.cc +++ b/src/DownloadResult.cc @@ -40,17 +40,16 @@ namespace aria2 { DownloadResult::DownloadResult() - : gid(nullptr), - inMemoryDownload(false), + : belongsTo(0), sessionDownloadLength(0), sessionTime(0), - result(error_code::UNDEFINED), - belongsTo(0), totalLength(0), completedLength(0), uploadLength(0), + numPieces(0), pieceLength(0), - numPieces(0) + result(error_code::UNDEFINED), + inMemoryDownload(false) {} DownloadResult::~DownloadResult() {} diff --git a/src/DownloadResult.h b/src/DownloadResult.h index 729e97d2..949c7c84 100644 --- a/src/DownloadResult.h +++ b/src/DownloadResult.h @@ -54,46 +54,46 @@ class MetadataInfo; struct DownloadResult { - std::shared_ptr<GroupId> gid; - - std::vector<std::shared_ptr<FileEntry> > fileEntries; - - bool inMemoryDownload; + // This field contains GID. See comment in + // RequestGroup.cc::belongsToGID_. + a2_gid_t belongsTo; uint64_t sessionDownloadLength; // milliseconds int64_t sessionTime; - error_code::Value result; + int64_t totalLength; - // This field contains GIDs. See comment in - // RequestGroup.cc::followedByGIDs_. - std::vector<a2_gid_t> followedBy; + int64_t completedLength; - // This field contains GID. See comment in - // RequestGroup.cc::belongsToGID_. - a2_gid_t belongsTo; + int64_t uploadLength; + + std::shared_ptr<GroupId> gid; std::shared_ptr<Option> option; std::shared_ptr<MetadataInfo> metadataInfo; - int64_t totalLength; - - int64_t completedLength; + std::vector<std::shared_ptr<FileEntry> > fileEntries; - int64_t uploadLength; + // This field contains GIDs. See comment in + // RequestGroup.cc::followedByGIDs_. + std::vector<a2_gid_t> followedBy; std::string bitfield; std::string infoHash; - int32_t pieceLength; + std::string dir; size_t numPieces; - std::string dir; + int32_t pieceLength; + + error_code::Value result; + + bool inMemoryDownload; DownloadResult(); ~DownloadResult(); diff --git a/src/FileEntry.cc b/src/FileEntry.cc index 6f572bc0..9e4b60b7 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -66,27 +66,24 @@ bool FileEntry::RequestFaster::operator() return lspd > rspd || (lspd == rspd && lhs.get() < rhs.get()); } -FileEntry::FileEntry -(const std::string& path, - int64_t length, - int64_t offset, - const std::vector<std::string>& uris) - : path_(path), - uris_(uris.begin(), uris.end()), - length_(length), +FileEntry::FileEntry(const std::string& path, int64_t length, int64_t offset, + const std::vector<std::string>& uris) + : length_(length), offset_(offset), - requested_(true), - uniqueProtocol_(false), + uris_(uris.begin(), uris.end()), + path_(path), + lastFasterReplace_(0), maxConnectionPerServer_(1), - lastFasterReplace_(0) + requested_(true), + uniqueProtocol_(false) {} FileEntry::FileEntry() : length_(0), offset_(0), + maxConnectionPerServer_(1), requested_(false), - uniqueProtocol_(false), - maxConnectionPerServer_(1) + uniqueProtocol_(false) {} FileEntry::~FileEntry() {} diff --git a/src/FileEntry.h b/src/FileEntry.h index cdab3174..d5dbd786 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -62,31 +62,35 @@ class FileEntry { public: typedef std::set<std::shared_ptr<Request>, RefLess<Request> > InFlightRequestSet; -private: - std::string path_; - std::deque<std::string> uris_; - std::deque<std::string> spentUris_; - int64_t length_; - int64_t offset_; - bool requested_; +private: class RequestFaster { public: bool operator()(const std::shared_ptr<Request>& lhs, const std::shared_ptr<Request>& rhs) const; }; - typedef std::set<std::shared_ptr<Request>, RequestFaster> RequestPool; - RequestPool requestPool_; - InFlightRequestSet inFlightRequests_; - std::string contentType_; + + int64_t length_; + int64_t offset_; + + std::deque<std::string> uris_; + std::deque<std::string> spentUris_; // URIResult is stored in the ascending order of the time when its result is // available. std::deque<URIResult> uriResults_; - bool uniqueProtocol_; - int maxConnectionPerServer_; + RequestPool requestPool_; + InFlightRequestSet inFlightRequests_; + + std::string path_; + std::string contentType_; std::string originalName_; + Timer lastFasterReplace_; + int maxConnectionPerServer_; + + bool requested_; + bool uniqueProtocol_; void storePool(const std::shared_ptr<Request>& request); public: diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index d6f6d16b..baf0bb93 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -58,15 +58,15 @@ namespace aria2 { const std::string HttpRequest::USER_AGENT("aria2"); HttpRequest::HttpRequest() - : contentEncodingEnabled_(true), - userAgent_(USER_AGENT), - acceptMetalink_(false), - cookieStorage_(nullptr), + : cookieStorage_(nullptr), authConfigFactory_(nullptr), option_(nullptr), + endOffsetOverride_(0), + userAgent_(USER_AGENT), + contentEncodingEnabled_(true), + acceptMetalink_(false), noCache_(true), - acceptGzip_(false), - endOffsetOverride_(0) + acceptGzip_(false) {} HttpRequest::~HttpRequest() {} diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 3baac4bb..34a52e3b 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -65,14 +65,9 @@ private: std::shared_ptr<Segment> segment_; - bool contentEncodingEnabled_; - - std::string userAgent_; - - std::vector<std::string> headers_; + std::shared_ptr<Request> proxyRequest_; - // If true, metalink content types are sent in Accept header field. - bool acceptMetalink_; + std::unique_ptr<AuthConfig> authConfig_; CookieStorage* cookieStorage_; @@ -80,14 +75,6 @@ private: const Option* option_; - std::unique_ptr<AuthConfig> authConfig_; - - std::shared_ptr<Request> proxyRequest_; - - bool noCache_; - - bool acceptGzip_; - // Historically, aria2 did not specify end byte marker unless http // pipelining is enabled. Sometimes end byte is known because the // segment/piece ahead of this request was already acquired. In this @@ -97,9 +84,23 @@ private: // bytes and it is also true if it is used via HTTP proxy. int64_t endOffsetOverride_; + std::vector<std::string> headers_; + + std::string userAgent_; + std::string ifModSinceHeader_; + bool contentEncodingEnabled_; + + // If true, metalink content types are sent in Accept header field. + bool acceptMetalink_; + + bool noCache_; + + bool acceptGzip_; + std::pair<std::string, std::string> getProxyAuthString() const; + public: HttpRequest(); ~HttpRequest(); diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index f8641101..dd35c49a 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -74,12 +74,12 @@ HttpSkipResponseCommand::HttpSkipResponseCommand const std::shared_ptr<SocketCore>& s) : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s, httpConnection->getSocketRecvBuffer()), - httpConnection_(httpConnection), - httpResponse_(std::move(httpResponse)), - streamFilter_(new NullSinkStreamFilter()), sinkFilterOnly_(true), totalLength_(httpResponse_->getEntityLength()), - receivedBytes_(0) + receivedBytes_(0), + httpConnection_(httpConnection), + httpResponse_(std::move(httpResponse)), + streamFilter_(new NullSinkStreamFilter()) { checkSocketRecvBuffer(); } diff --git a/src/HttpSkipResponseCommand.h b/src/HttpSkipResponseCommand.h index 6d13ef76..dff34f43 100644 --- a/src/HttpSkipResponseCommand.h +++ b/src/HttpSkipResponseCommand.h @@ -45,11 +45,7 @@ class StreamFilter; class HttpSkipResponseCommand : public AbstractCommand { private: - std::shared_ptr<HttpConnection> httpConnection_; - - std::unique_ptr<HttpResponse> httpResponse_; - - std::unique_ptr<StreamFilter> streamFilter_; + // hole from AbstractCommand (5 bytes on x86_64) bool sinkFilterOnly_; @@ -57,21 +53,27 @@ private: int64_t receivedBytes_; + std::shared_ptr<HttpConnection> httpConnection_; + + std::unique_ptr<HttpResponse> httpResponse_; + + std::unique_ptr<StreamFilter> streamFilter_; + bool processResponse(); void poolConnection() const; + protected: virtual bool executeInternal() CXX11_OVERRIDE; + public: - HttpSkipResponseCommand - (cuid_t cuid, - const std::shared_ptr<Request>& req, - const std::shared_ptr<FileEntry>& fileEntry, - RequestGroup* requestGroup, - const std::shared_ptr<HttpConnection>& httpConnection, - std::unique_ptr<HttpResponse> httpResponse, - DownloadEngine* e, - const std::shared_ptr<SocketCore>& s); + HttpSkipResponseCommand(cuid_t cuid, const std::shared_ptr<Request>& req, + const std::shared_ptr<FileEntry>& fileEntry, + RequestGroup* requestGroup, + const std::shared_ptr<HttpConnection>& httpConnection, + std::unique_ptr<HttpResponse> httpResponse, + DownloadEngine* e, + const std::shared_ptr<SocketCore>& s); virtual ~HttpSkipResponseCommand(); diff --git a/src/Piece.cc b/src/Piece.cc index faf70ec7..668e2131 100644 --- a/src/Piece.cc +++ b/src/Piece.cc @@ -52,22 +52,28 @@ namespace aria2 { -Piece::Piece():index_(0), length_(0), blockLength_(BLOCK_LENGTH), bitfield_(nullptr), - usedBySegment_(false), wrCache_(nullptr) +Piece::Piece() + : bitfield_(nullptr), + wrCache_(nullptr), + index_(0), + length_(0), + blockLength_(BLOCK_LENGTH), #ifdef ENABLE_MESSAGE_DIGEST - , nextBegin_(0) + nextBegin_(0), #endif // ENABLE_MESSAGE_DIGEST + usedBySegment_(false) {} Piece::Piece(size_t index, int32_t length, int32_t blockLength) - : index_(index), + : bitfield_(new BitfieldMan(blockLength, length)), + wrCache_(nullptr), + index_(index), length_(length), blockLength_(blockLength), - bitfield_(new BitfieldMan(blockLength_, length)), - usedBySegment_(false), wrCache_(nullptr) #ifdef ENABLE_MESSAGE_DIGEST - ,nextBegin_(0) + nextBegin_(0), #endif // ENABLE_MESSAGE_DIGEST + usedBySegment_(false) {} Piece::~Piece() diff --git a/src/Piece.h b/src/Piece.h index ea38b291..40c62693 100644 --- a/src/Piece.h +++ b/src/Piece.h @@ -59,32 +59,33 @@ class MessageDigest; class Piece { private: - size_t index_; - int32_t length_; - int32_t blockLength_; BitfieldMan* bitfield_; - std::vector<cuid_t> users_; - bool usedBySegment_; WrDiskCacheEntry* wrCache_; #ifdef ENABLE_MESSAGE_DIGEST - - int32_t nextBegin_; - + std::unique_ptr<MessageDigest> mdctx_; +#endif // ENABLE_MESSAGE_DIGEST + std::vector<cuid_t> users_; +#ifdef ENABLE_MESSAGE_DIGEST std::string hashType_; +#endif // ENABLE_MESSAGE_DIGEST - std::unique_ptr<MessageDigest> mdctx_; + size_t index_; + int32_t length_; + int32_t blockLength_; +#ifdef ENABLE_MESSAGE_DIGEST + int32_t nextBegin_; #endif // ENABLE_MESSAGE_DIGEST - Piece(const Piece& piece); + bool usedBySegment_; - Piece& operator=(const Piece& piece); -public: + Piece(const Piece& piece) = delete; + Piece& operator=(const Piece& piece) = delete; +public: static const int32_t BLOCK_LENGTH = 16*1024; Piece(); - Piece(size_t index, int32_t length, int32_t blockLength = BLOCK_LENGTH); ~Piece(); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 55ea2783..7550d9af 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -123,35 +123,35 @@ namespace aria2 { RequestGroup::RequestGroup(const std::shared_ptr<GroupId>& gid, const std::shared_ptr<Option>& option) - : gid_(gid), - state_(STATE_WAITING), + : belongsToGID_(0), + gid_(gid), option_(option), - numConcurrentCommand_(option->getAsInt(PREF_SPLIT)), - numStreamConnection_(0), - numStreamCommand_(0), - numCommand_(0), - saveControlFile_(true), progressInfoFile_(new NullProgressInfoFile()), - preLocalFileCheckEnabled_(true), - haltRequested_(false), - forceHaltRequested_(false), - haltReason_(RequestGroup::NONE), - pauseRequested_(false), uriSelector_(make_unique<InorderURISelector>()), - lastModifiedTime_(Time::null()), - fileNotFoundCount_(0), - timeout_(option->getAsInt(PREF_TIMEOUT)), + requestGroupMan_(nullptr), #ifdef ENABLE_BITTORRENT btRuntime_(nullptr), peerStorage_(nullptr), #endif // ENABLE_BITTORRENT - inMemoryDownload_(false), + lastModifiedTime_(Time::null()), + timeout_(option->getAsInt(PREF_TIMEOUT)), + state_(STATE_WAITING), + numConcurrentCommand_(option->getAsInt(PREF_SPLIT)), + numStreamConnection_(0), + numStreamCommand_(0), + numCommand_(0), + fileNotFoundCount_(0), maxDownloadSpeedLimit_(option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)), maxUploadSpeedLimit_(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)), + resumeFailureCount_(0), + haltReason_(RequestGroup::NONE), lastErrorCode_(error_code::UNDEFINED), - belongsToGID_(0), - requestGroupMan_(nullptr), - resumeFailureCount_(0) + saveControlFile_(true), + preLocalFileCheckEnabled_(true), + haltRequested_(false), + forceHaltRequested_(false), + pauseRequested_(false), + inMemoryDownload_(false) { fileAllocationEnabled_ = option_->get(PREF_FILE_ALLOCATION) != V_NONE; if(!option_->getAsBool(PREF_DRY_RUN)) { diff --git a/src/RequestGroup.h b/src/RequestGroup.h index dfc81cc4..25c163f0 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -87,96 +87,98 @@ public: // Download has begun STATE_ACTIVE }; + private: - std::shared_ptr<GroupId> gid_; + // If this download is a part of another download(for example, + // downloading torrent file described in Metalink file), this field + // has the GID of parent RequestGroup. 0 means this is a parent + // RequestGroup. + a2_gid_t belongsToGID_; - int state_; + std::shared_ptr<GroupId> gid_; std::shared_ptr<Option> option_; - int numConcurrentCommand_; - - /** - * This is the number of connections used in streaming protocol(http/ftp) - */ - int numStreamConnection_; - - int numStreamCommand_; - - int numCommand_; - std::shared_ptr<SegmentMan> segmentMan_; std::shared_ptr<DownloadContext> downloadContext_; std::shared_ptr<PieceStorage> pieceStorage_; - bool saveControlFile_; - std::shared_ptr<BtProgressInfoFile> progressInfoFile_; std::shared_ptr<DiskWriterFactory> diskWriterFactory_; std::shared_ptr<Dependency> dependency_; - bool fileAllocationEnabled_; + std::unique_ptr<URISelector> uriSelector_; - bool preLocalFileCheckEnabled_; + std::shared_ptr<MetadataInfo> metadataInfo_; - bool haltRequested_; + RequestGroupMan* requestGroupMan_; - bool forceHaltRequested_; +#ifdef ENABLE_BITTORRENT + BtRuntime* btRuntime_; - HaltReason haltReason_; + PeerStorage* peerStorage_; +#endif // ENABLE_BITTORRENT - bool pauseRequested_; + // If this download generates another downloads when completed(for + // example, downloads generated by PostDownloadHandler), this field + // has the GID of generated RequestGroups. empty list means there is + // no such RequestGroup. + std::vector<a2_gid_t> followedByGIDs_; std::vector<const PreDownloadHandler*> preDownloadHandlers_; std::vector<const PostDownloadHandler*> postDownloadHandlers_; - std::unique_ptr<URISelector> uriSelector_; - Time lastModifiedTime_; - int fileNotFoundCount_; - // Timeout used for HTTP/FTP downloads. time_t timeout_; -#ifdef ENABLE_BITTORRENT - BtRuntime* btRuntime_; + int state_; - PeerStorage* peerStorage_; -#endif // ENABLE_BITTORRENT + int numConcurrentCommand_; - // This flag just indicates that the downloaded file is not saved disk but - // just sits in memory. - bool inMemoryDownload_; + /** + * This is the number of connections used in streaming protocol(http/ftp) + */ + int numStreamConnection_; + + int numStreamCommand_; + + int numCommand_; + + int fileNotFoundCount_; int maxDownloadSpeedLimit_; int maxUploadSpeedLimit_; + int resumeFailureCount_; + + HaltReason haltReason_; + error_code::Value lastErrorCode_; - // If this download generates another downloads when completed(for - // example, downloads generated by PostDownloadHandler), this field - // has the GID of generated RequestGroups. empty list means there is - // no such RequestGroup. - std::vector<a2_gid_t> followedByGIDs_; + bool saveControlFile_; - // If this download is a part of another download(for example, - // downloading torrent file described in Metalink file), this field - // has the GID of parent RequestGroup. 0 means this is a parent - // RequestGroup. - a2_gid_t belongsToGID_; + bool fileAllocationEnabled_; - std::shared_ptr<MetadataInfo> metadataInfo_; + bool preLocalFileCheckEnabled_; - RequestGroupMan* requestGroupMan_; + bool haltRequested_; + + bool forceHaltRequested_; + + bool pauseRequested_; + + // This flag just indicates that the downloaded file is not saved disk but + // just sits in memory. + bool inMemoryDownload_; - int resumeFailureCount_; void validateFilename(const std::string& expectedFilename, const std::string& actualFilename) const; diff --git a/src/TimeBasedCommand.cc b/src/TimeBasedCommand.cc index f077baed..0be235bb 100644 --- a/src/TimeBasedCommand.cc +++ b/src/TimeBasedCommand.cc @@ -40,9 +40,14 @@ namespace aria2 { TimeBasedCommand::TimeBasedCommand(cuid_t cuid, DownloadEngine* e, time_t interval, - bool routineCommand): - Command(cuid), e_(e),exit_(false), interval_(interval), - routineCommand_(routineCommand), checkPoint_(global::wallclock()) {} + bool routineCommand) + : Command(cuid), + e_(e), + checkPoint_(global::wallclock()), + interval_(interval), + exit_(false), + routineCommand_(routineCommand) +{} TimeBasedCommand::~TimeBasedCommand() {} diff --git a/src/TimeBasedCommand.h b/src/TimeBasedCommand.h index 229c8ff8..7b26c93b 100644 --- a/src/TimeBasedCommand.h +++ b/src/TimeBasedCommand.h @@ -47,6 +47,10 @@ class TimeBasedCommand : public Command private: DownloadEngine* e_; + Timer checkPoint_; + + time_t interval_; // unit: sec + /** * setting exit_ to true if this command's job has finished and you want to * delete this command. @@ -56,11 +60,8 @@ private: */ bool exit_; - time_t interval_; // unit: sec - bool routineCommand_; - Timer checkPoint_; protected: DownloadEngine* getDownloadEngine() const { @@ -48,12 +48,12 @@ UriStruct::UriStruct() UriStruct::UriStruct(const UriStruct& c) : protocol(c.protocol), host(c.host), - port(c.port), dir(c.dir), file(c.file), query(c.query), username(c.username), password(c.password), + port(c.port), hasPassword(c.hasPassword), ipv6LiteralAddress(c.ipv6LiteralAddress) {} @@ -65,12 +65,12 @@ UriStruct& UriStruct::operator=(const UriStruct& c) if(this != &c) { protocol = c.protocol; host = c.host; - port = c.port; dir = c.dir; file = c.file; query = c.query; username = c.username; password = c.password; + port = c.port; hasPassword = c.hasPassword; ipv6LiteralAddress = c.ipv6LiteralAddress; } @@ -83,12 +83,12 @@ void UriStruct::swap(UriStruct& other) if(this != &other) { swap(protocol, other.protocol); swap(host, other.host); - swap(port, other.port); swap(dir, other.dir); swap(file, other.file); swap(query, other.query); swap(username, other.username); swap(password, other.password); + swap(port, other.port); swap(hasPassword, other.hasPassword); swap(ipv6LiteralAddress, other.ipv6LiteralAddress); } @@ -48,12 +48,12 @@ namespace uri { struct UriStruct { std::string protocol; std::string host; - uint16_t port; std::string dir; std::string file; std::string query; std::string username; std::string password; + uint16_t port; bool hasPassword; bool ipv6LiteralAddress; |
