diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-06-29 16:43:41 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-06-29 16:43:41 +0000 |
| commit | cece2bc896b941d0c9b9d441460b5d32989268bd (patch) | |
| tree | ff5348711867e2cb2cd753d7e2549a20a201675f /src/FileEntry.cc | |
| parent | c4d79d7160569bef82c4a67b267d78289b91e449 (diff) | |
2009-06-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed ServerHost. Same functionality is implemented using
FileEntry's in-flight Request objects.
* src/AbstractCommand.cc
* src/BtDependency.cc
* src/CreateRequestCommand.cc
* src/FileEntry.cc
* src/FileEntry.h
* src/FtpNegotiationCommand.cc
* src/HttpResponseCommand.cc
* src/Makefile.am
* src/Metalink2RequestGroup.cc
* src/RequestGroup.cc
* src/RequestGroup.h
* src/ServerHost.cc: Removed
* src/ServerHost.h: Removed
* test/BtDependencyTest.cc
* test/FileEntryTest.cc
* test/RequestGroupTest.cc
Diffstat (limited to 'src/FileEntry.cc')
| -rw-r--r-- | src/FileEntry.cc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/FileEntry.cc b/src/FileEntry.cc index e2e67da5..28427faf 100644 --- a/src/FileEntry.cc +++ b/src/FileEntry.cc @@ -49,10 +49,12 @@ FileEntry::FileEntry(const std::string& path, const std::deque<std::string>& uris): path(path), _uris(uris), length(length), offset(offset), extracted(false), requested(true), + _singleHostMultiConnection(true), _logger(LogFactory::getInstance()) {} FileEntry::FileEntry(): length(0), offset(0), extracted(false), requested(false), + _singleHostMultiConnection(true), _logger(LogFactory::getInstance()) {} FileEntry::~FileEntry() {} @@ -101,11 +103,26 @@ std::string FileEntry::selectUri(const SharedHandle<URISelector>& uriSelector) return uriSelector->select(this); } +template<typename InputIterator> +static bool inFlightHost(InputIterator first, InputIterator last, + const std::string& hostname) +{ + // TODO1.5 redirection should be considered here. We need to parse + // original URI to get hostname. + for(; first != last; ++first) { + if((*first)->getHost() == hostname) { + return true; + } + } + return false; +} + SharedHandle<Request> FileEntry::getRequest(const SharedHandle<URISelector>& selector) { SharedHandle<Request> req; if(_requestPool.empty()) { + std::deque<std::string> pending; while(1) { std::string uri = selector->select(this); if(uri.empty()) { @@ -113,19 +130,28 @@ FileEntry::getRequest(const SharedHandle<URISelector>& selector) } req.reset(new Request()); if(req->setUrl(uri)) { + if(!_singleHostMultiConnection) { + if(inFlightHost(_inFlightRequests.begin(), _inFlightRequests.end(), + req->getHost())) { + pending.push_back(uri); + req.reset(); + continue; + } + } _spentUris.push_back(uri); _inFlightRequests.push_back(req); - return req; + break; } else { req.reset(); } } + _uris.insert(_uris.begin(), pending.begin(), pending.end()); } else { req = _requestPool.front(); _requestPool.pop_front(); _inFlightRequests.push_back(req); - return req; } + return req; } SharedHandle<Request> |
