mirror of https://github.com/aria2/aria2
Reuse in-flight and pooled URIs when a download is paused.
parent
4532881eb6
commit
e2e711fba8
|
@ -185,6 +185,7 @@ void DownloadContext::releaseRuntimeResource()
|
|||
{
|
||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||
fileEntries_.begin(), eoi = fileEntries_.end(); i != eoi; ++i) {
|
||||
(*i)->putBackRequest();
|
||||
(*i)->releaseRuntimeResource();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -452,6 +452,25 @@ void FileEntry::releaseRuntimeResource()
|
|||
inFlightRequests_.clear();
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename InputIterator>
|
||||
void putBackUri
|
||||
(std::deque<std::string>& uris,
|
||||
InputIterator first,
|
||||
InputIterator last)
|
||||
{
|
||||
for(; first != last; ++first) {
|
||||
uris.push_front((*first)->getUri());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void FileEntry::putBackRequest()
|
||||
{
|
||||
putBackUri(uris_, requestPool_.begin(), requestPool_.end());
|
||||
putBackUri(uris_, inFlightRequests_.begin(), inFlightRequests_.end());
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename InputIterator, typename T>
|
||||
InputIterator findRequestByUri
|
||||
|
|
|
@ -231,6 +231,9 @@ public:
|
|||
|
||||
void releaseRuntimeResource();
|
||||
|
||||
// Push URIs in pooled or in-flight requests to the front of uris_.
|
||||
void putBackRequest();
|
||||
|
||||
void setOriginalName(const std::string& originalName);
|
||||
|
||||
const std::string& getOriginalName() const
|
||||
|
|
|
@ -20,6 +20,7 @@ class FileEntryTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testAddUris);
|
||||
CPPUNIT_TEST(testInsertUri);
|
||||
CPPUNIT_TEST(testRemoveUri);
|
||||
CPPUNIT_TEST(testPutBackRequest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
@ -34,6 +35,7 @@ public:
|
|||
void testAddUris();
|
||||
void testInsertUri();
|
||||
void testRemoveUri();
|
||||
void testPutBackRequest();
|
||||
};
|
||||
|
||||
|
||||
|
@ -292,4 +294,23 @@ void FileEntryTest::testRemoveUri()
|
|||
CPPUNIT_ASSERT(!file.removeUri("http://example.net"));
|
||||
}
|
||||
|
||||
void FileEntryTest::testPutBackRequest()
|
||||
{
|
||||
SharedHandle<FileEntry> fileEntry = createFileEntry();
|
||||
SharedHandle<InorderURISelector> selector(new InorderURISelector());
|
||||
std::vector<std::pair<size_t, std::string> > usedHosts;
|
||||
SharedHandle<Request> req1 =
|
||||
fileEntry->getRequest(selector, false, usedHosts);
|
||||
SharedHandle<Request> req2 =
|
||||
fileEntry->getRequest(selector, false, usedHosts);
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntry->getRemainingUris().size());
|
||||
fileEntry->poolRequest(req2);
|
||||
fileEntry->putBackRequest();
|
||||
const std::deque<std::string>& uris = fileEntry->getRemainingUris();
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2.zip"), uris[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"), uris[1]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ftp://localhost/aria2.zip"), uris[2]);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue