diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-09-30 17:30:35 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-09-30 17:30:35 +0900 |
| commit | e34d0e7ffa602d611ec6ec14cf9aa381da41c24e (patch) | |
| tree | 592bb08917923313eba265001383f780ef0f930c /src | |
| parent | 492d6d1eeb7df7c848c07487dbdef0306a462332 (diff) | |
Dont' return SharedHandle from HttpHeader::getRange()
Diffstat (limited to 'src')
| -rw-r--r-- | src/HttpDownloadCommand.cc | 7 | ||||
| -rw-r--r-- | src/HttpHeader.cc | 15 | ||||
| -rw-r--r-- | src/HttpHeader.h | 2 | ||||
| -rw-r--r-- | src/HttpRequest.cc | 17 | ||||
| -rw-r--r-- | src/HttpRequest.h | 4 | ||||
| -rw-r--r-- | src/HttpResponse.cc | 12 | ||||
| -rw-r--r-- | src/Range.cc | 26 | ||||
| -rw-r--r-- | src/Range.h | 26 |
8 files changed, 45 insertions, 64 deletions
diff --git a/src/HttpDownloadCommand.cc b/src/HttpDownloadCommand.cc index 47c17f66..74153d4d 100644 --- a/src/HttpDownloadCommand.cc +++ b/src/HttpDownloadCommand.cc @@ -120,9 +120,8 @@ bool HttpDownloadCommand::prepareForNextSegment() { int64_t lastOffset =getFileEntry()->gtoloff (std::min(segment->getPosition()+segment->getLength(), getFileEntry()->getLastOffset())); - - if(lastOffset == - httpResponse_->getHttpHeader()->getRange()->getEndByte()+1) { + Range range = httpResponse_->getHttpHeader()->getRange(); + if(lastOffset == range.endByte + 1) { return prepareForRetry(0); } } @@ -132,7 +131,7 @@ bool HttpDownloadCommand::prepareForNextSegment() { int64_t HttpDownloadCommand::getRequestEndOffset() const { - int64_t endByte = httpResponse_->getHttpHeader()->getRange()->getEndByte(); + int64_t endByte = httpResponse_->getHttpHeader()->getRange().endByte; if(endByte > 0) { return endByte+1; } else { diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index a349a7a3..ae622b27 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -85,13 +85,13 @@ HttpHeader::equalRange(int hdKey) const return table_.equal_range(hdKey); } -SharedHandle<Range> HttpHeader::getRange() const +Range HttpHeader::getRange() const { const std::string& rangeStr = find(CONTENT_RANGE); if(rangeStr.empty()) { const std::string& clenStr = find(CONTENT_LENGTH); if(clenStr.empty()) { - return SharedHandle<Range>(new Range()); + return Range(); } else { int64_t contentLength; if(!util::parseLLIntNoThrow(contentLength, clenStr) || @@ -101,10 +101,9 @@ SharedHandle<Range> HttpHeader::getRange() const throw DOWNLOAD_FAILURE_EXCEPTION (fmt(EX_TOO_LARGE_FILE, contentLength)); } else if(contentLength == 0) { - return SharedHandle<Range>(new Range()); + return Range(); } else { - return SharedHandle<Range> - (new Range(0, contentLength-1, contentLength)); + return Range(0, contentLength - 1, contentLength); } } } @@ -130,11 +129,11 @@ SharedHandle<Range> HttpHeader::getRange() const // If byte-range-resp-spec or instance-length is "*", we returns // empty Range. The former is usually sent with 416 (Request range // not satisfiable) status. - return SharedHandle<Range>(new Range()); + return Range(); } std::string::const_iterator minus = std::find(byteRangeSpec, slash, '-'); if(minus == slash) { - return SharedHandle<Range>(new Range()); + return Range(); } int64_t startByte, endByte, entityLength; if(!util::parseLLIntNoThrow(startByte, std::string(byteRangeSpec, minus)) || @@ -153,7 +152,7 @@ SharedHandle<Range> HttpHeader::getRange() const if(entityLength > std::numeric_limits<off_t>::max()) { throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, entityLength)); } - return SharedHandle<Range>(new Range(startByte, endByte, entityLength)); + return Range(startByte, endByte, entityLength); } void HttpHeader::setVersion(const std::string& version) diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 4a1d3f9d..217e96b7 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -108,7 +108,7 @@ public: std::multimap<int, std::string>::const_iterator> equalRange(int hdKey) const; - SharedHandle<Range> getRange() const; + Range getRange() const; int getStatusCode() const; diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index fcf8ef0c..6cb6c454 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -101,31 +101,30 @@ int64_t HttpRequest::getEndByte() const } } -SharedHandle<Range> HttpRequest::getRange() const +Range HttpRequest::getRange() const { // content-length is always 0 if(!segment_) { - return SharedHandle<Range>(new Range()); + return Range(); } else { - return SharedHandle<Range>(new Range(getStartByte(), getEndByte(), - fileEntry_->getLength())); + return Range(getStartByte(), getEndByte(), fileEntry_->getLength()); } } -bool HttpRequest::isRangeSatisfied(const SharedHandle<Range>& range) const +bool HttpRequest::isRangeSatisfied(const Range& range) const { if(!segment_) { return true; } - if((getStartByte() == range->getStartByte()) && + if((getStartByte() == range.startByte) && ((getEndByte() == 0) || - (getEndByte() == range->getEndByte())) && + (getEndByte() == range.endByte)) && ((fileEntry_->getLength() == 0) || - (fileEntry_->getLength() == range->getEntityLength()))) { + (fileEntry_->getLength() == range.entityLength))) { return true; } else { return false; - } + } } namespace { diff --git a/src/HttpRequest.h b/src/HttpRequest.h index c467d601..76c954c9 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -128,13 +128,13 @@ public: std::string getURIHost() const; - SharedHandle<Range> getRange() const; + Range getRange() const; /** * Inspects whether the specified response range is satisfiable * with request range. */ - bool isRangeSatisfied(const SharedHandle<Range>& range) const; + bool isRangeSatisfied(const Range& range) const; const SharedHandle<Request>& getRequest() const { diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index b721d64b..cd7e821f 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -96,16 +96,16 @@ void HttpResponse::validateResponse() const } else if(statusCode == 200 || statusCode == 206) { if(!httpHeader_->defined(HttpHeader::TRANSFER_ENCODING)) { // compare the received range against the requested range - SharedHandle<Range> responseRange = httpHeader_->getRange(); + Range responseRange = httpHeader_->getRange(); if(!httpRequest_->isRangeSatisfied(responseRange)) { throw DL_ABORT_EX2 (fmt(EX_INVALID_RANGE_HEADER, httpRequest_->getStartByte(), httpRequest_->getEndByte(), httpRequest_->getEntityLength(), - responseRange->getStartByte(), - responseRange->getEndByte(), - responseRange->getEntityLength()), + responseRange.startByte, + responseRange.endByte, + responseRange.entityLength), error_code::CANNOT_RESUME); } } @@ -231,7 +231,7 @@ int64_t HttpResponse::getContentLength() const if(!httpHeader_) { return 0; } else { - return httpHeader_->getRange()->getContentLength(); + return httpHeader_->getRange().getContentLength(); } } @@ -240,7 +240,7 @@ int64_t HttpResponse::getEntityLength() const if(!httpHeader_) { return 0; } else { - return httpHeader_->getRange()->getEntityLength(); + return httpHeader_->getRange().entityLength; } } diff --git a/src/Range.cc b/src/Range.cc index 779b13f6..88dc149b 100644 --- a/src/Range.cc +++ b/src/Range.cc @@ -36,16 +36,16 @@ namespace aria2 { -Range::Range():startByte_(0), endByte_(0), entityLength_(0) {} +Range::Range():startByte(0), endByte(0), entityLength(0) {} Range::Range(int64_t startByte, int64_t endByte, int64_t entityLength) - : startByte_(startByte), endByte_(endByte), entityLength_(entityLength) + : startByte(startByte), endByte(endByte), entityLength(entityLength) {} Range::Range(const Range& c) - : startByte_(c.startByte_), - endByte_(c.endByte_), - entityLength_(c.entityLength_) + : startByte(c.startByte), + endByte(c.endByte), + entityLength(c.entityLength) {} Range::~Range() {} @@ -53,18 +53,18 @@ Range::~Range() {} Range& Range::operator=(const Range& c) { if(this != &c) { - startByte_ = c.startByte_; - endByte_ = c.endByte_; - entityLength_ = c.entityLength_; + startByte = c.startByte; + endByte = c.endByte; + entityLength = c.entityLength; } return *this; } bool Range::operator==(const Range& range) const { - return startByte_ == range.startByte_ && - endByte_ == range.endByte_ && - entityLength_ == range.entityLength_; + return startByte == range.startByte && + endByte == range.endByte && + entityLength == range.entityLength; } bool Range::operator!=(const Range& range) const @@ -74,8 +74,8 @@ bool Range::operator!=(const Range& range) const int64_t Range::getContentLength() const { - if(endByte_ >= startByte_) { - return endByte_-startByte_+1; + if(endByte >= startByte) { + return endByte-startByte+1; } else { return 0; } diff --git a/src/Range.h b/src/Range.h index c4d1ad4d..e7aef928 100644 --- a/src/Range.h +++ b/src/Range.h @@ -41,12 +41,11 @@ namespace aria2 { -class Range { -private: - int64_t startByte_; - int64_t endByte_; - int64_t entityLength_; -public: +struct Range { + int64_t startByte; + int64_t endByte; + int64_t entityLength; + Range(); Range(int64_t startByte, int64_t endByte, int64_t entityLength); @@ -61,21 +60,6 @@ public: bool operator!=(const Range& range) const; - int64_t getStartByte() const - { - return startByte_; - } - - int64_t getEndByte() const - { - return endByte_; - } - - int64_t getEntityLength() const - { - return entityLength_; - } - int64_t getContentLength() const; }; |
