mirror of https://github.com/aria2/aria2
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten AdaptiveURISelector::mayRetryWithIncreasedTimeout() using RequestGroup::extractURIResult(). * src/AdaptiveURISelector.cc * src/RequestGroup.cc * src/RequestGroup.h * test/RequestGroupTest.ccpull/1/head
parent
b8d177dd5d
commit
9bb57720cf
|
@ -1,3 +1,12 @@
|
|||
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Rewritten AdaptiveURISelector::mayRetryWithIncreasedTimeout()
|
||||
using RequestGroup::extractURIResult().
|
||||
* src/AdaptiveURISelector.cc
|
||||
* src/RequestGroup.cc
|
||||
* src/RequestGroup.h
|
||||
* test/RequestGroupTest.cc
|
||||
|
||||
2009-02-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added tests for array_ptr.
|
||||
|
|
|
@ -99,18 +99,17 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout
|
|||
_requestGroup->setTimeout(_requestGroup->getTimeout()*2);
|
||||
|
||||
// looking for retries
|
||||
const std::deque<URIResult>& uriResults = _requestGroup->getURIResults();
|
||||
for (std::deque<URIResult>::const_iterator i = uriResults.begin();
|
||||
i != uriResults.end(); ++i) {
|
||||
if ((*i).getResult() == DownloadResult::TIME_OUT) {
|
||||
_logger->debug("AdaptiveURISelector: will retry server with increased"
|
||||
" timeout (%d s): %s",
|
||||
_requestGroup->getTimeout(), (*i).getURI().c_str());
|
||||
uris.push_back((*i).getURI());
|
||||
}
|
||||
std::deque<URIResult> timeouts;
|
||||
_requestGroup->extractURIResult(timeouts, DownloadResult::TIME_OUT);
|
||||
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
|
||||
std::mem_fun_ref(&URIResult::getURI));
|
||||
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end();
|
||||
++i) {
|
||||
_logger->debug("AdaptiveURISelector: will retry server with increased"
|
||||
" timeout (%d s): %s",
|
||||
_requestGroup->getTimeout(), (*i).c_str());
|
||||
}
|
||||
std::sort(uris.begin(), uris.end());
|
||||
uris.erase(std::unique(uris.begin(), uris.end()), uris.end());
|
||||
}
|
||||
|
||||
std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
|
||||
|
|
|
@ -1135,6 +1135,28 @@ const std::deque<URIResult>& RequestGroup::getURIResults() const
|
|||
return _uriResults;
|
||||
}
|
||||
|
||||
class FindURIResultByResult {
|
||||
private:
|
||||
DownloadResult::RESULT _r;
|
||||
public:
|
||||
FindURIResultByResult(DownloadResult::RESULT r):_r(r) {}
|
||||
|
||||
bool operator()(const URIResult& uriResult) const
|
||||
{
|
||||
return uriResult.getResult() == _r;
|
||||
}
|
||||
};
|
||||
|
||||
void RequestGroup::extractURIResult
|
||||
(std::deque<URIResult>& res, DownloadResult::RESULT r)
|
||||
{
|
||||
std::deque<URIResult>::iterator i =
|
||||
std::stable_partition(_uriResults.begin(), _uriResults.end(),
|
||||
FindURIResultByResult(r));
|
||||
std::copy(_uriResults.begin(), i, std::back_inserter(res));
|
||||
_uriResults.erase(_uriResults.begin(), i);
|
||||
}
|
||||
|
||||
void RequestGroup::setTimeout(time_t timeout)
|
||||
{
|
||||
_timeout = timeout;
|
||||
|
|
|
@ -333,6 +333,10 @@ public:
|
|||
|
||||
const std::deque<URIResult>& getURIResults() const;
|
||||
|
||||
// Extracts URIResult whose _result is r and stores them into res.
|
||||
// The extracted URIResults are removed from _uriResults.
|
||||
void extractURIResult(std::deque<URIResult>& res, DownloadResult::RESULT r);
|
||||
|
||||
void dependsOn(const SharedHandle<Dependency>& dep);
|
||||
|
||||
bool isDependencyResolved();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "RequestGroup.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "ServerHost.h"
|
||||
|
@ -17,6 +18,7 @@ class RequestGroupTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
|
||||
CPPUNIT_TEST(testGetFilePath);
|
||||
CPPUNIT_TEST(testCreateDownloadResult);
|
||||
CPPUNIT_TEST(testExtractURIResult);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
|
@ -27,6 +29,7 @@ public:
|
|||
void testRemoveURIWhoseHostnameIs();
|
||||
void testGetFilePath();
|
||||
void testCreateDownloadResult();
|
||||
void testExtractURIResult();
|
||||
};
|
||||
|
||||
|
||||
|
@ -139,4 +142,33 @@ void RequestGroupTest::testCreateDownloadResult()
|
|||
}
|
||||
}
|
||||
|
||||
void RequestGroupTest::testExtractURIResult()
|
||||
{
|
||||
Option op;
|
||||
RequestGroup group(&op, std::deque<std::string>());
|
||||
group.addURIResult("http://timeout/file", DownloadResult::TIME_OUT);
|
||||
group.addURIResult("http://finished/file", DownloadResult::FINISHED);
|
||||
group.addURIResult("http://timeout/file2", DownloadResult::TIME_OUT);
|
||||
group.addURIResult("http://unknownerror/file", DownloadResult::UNKNOWN_ERROR);
|
||||
|
||||
std::deque<URIResult> res;
|
||||
group.extractURIResult(res, DownloadResult::TIME_OUT);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file"), res[0].getURI());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file2"), res[1].getURI());
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://finished/file"),
|
||||
group.getURIResults()[0].getURI());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://unknownerror/file"),
|
||||
group.getURIResults()[1].getURI());
|
||||
|
||||
res.clear();
|
||||
|
||||
group.extractURIResult(res, DownloadResult::TIME_OUT);
|
||||
CPPUNIT_ASSERT(res.empty());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
|
||||
}
|
||||
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue