2007-05-20 13:57:56 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "RequestGroupMan.h"
|
2008-11-10 16:10:31 +00:00
|
|
|
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <ostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <numeric>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "BtProgressInfoFile.h"
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
#include "RecoverableException.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2007-05-20 13:57:56 +00:00
|
|
|
#include "DownloadEngine.h"
|
2007-07-20 17:06:21 +00:00
|
|
|
#include "message.h"
|
2007-11-07 12:36:33 +00:00
|
|
|
#include "a2functional.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
#include "DownloadResult.h"
|
2008-07-12 15:09:03 +00:00
|
|
|
#include "DownloadContext.h"
|
2008-08-04 17:06:47 +00:00
|
|
|
#include "ServerStatMan.h"
|
|
|
|
#include "ServerStat.h"
|
|
|
|
#include "PeerStat.h"
|
|
|
|
#include "SegmentMan.h"
|
|
|
|
#include "ServerStatURISelector.h"
|
|
|
|
#include "InOrderURISelector.h"
|
2009-01-06 13:13:42 +00:00
|
|
|
#include "AdaptiveURISelector.h"
|
2008-08-04 17:06:47 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include "prefs.h"
|
2008-08-23 15:42:06 +00:00
|
|
|
#include "File.h"
|
2008-11-10 16:10:31 +00:00
|
|
|
#include "Util.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups,
|
2008-08-04 17:06:47 +00:00
|
|
|
unsigned int maxSimultaneousDownloads,
|
|
|
|
const Option* option):
|
2007-10-11 16:58:24 +00:00
|
|
|
_requestGroups(requestGroups),
|
|
|
|
_logger(LogFactory::getInstance()),
|
|
|
|
_maxSimultaneousDownloads(maxSimultaneousDownloads),
|
2008-08-04 17:06:47 +00:00
|
|
|
_gidCounter(0),
|
|
|
|
_option(option),
|
|
|
|
_serverStatMan(new ServerStatMan()) {}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
bool RequestGroupMan::downloadFinished()
|
|
|
|
{
|
|
|
|
if(!_reservedGroups.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for(RequestGroups::iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
if((*itr)->getNumCommand() > 0 || !(*itr)->downloadFinished()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupMan::addRequestGroup(const RequestGroupHandle& group)
|
|
|
|
{
|
|
|
|
_requestGroups.push_back(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupMan::addReservedGroup(const RequestGroups& groups)
|
|
|
|
{
|
|
|
|
_reservedGroups.insert(_reservedGroups.end(), groups.begin(), groups.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupMan::addReservedGroup(const RequestGroupHandle& group)
|
|
|
|
{
|
|
|
|
_reservedGroups.push_back(group);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t RequestGroupMan::countRequestGroup() const
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
|
|
|
return _requestGroups.size();
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
RequestGroupHandle RequestGroupMan::getRequestGroup(size_t index) const
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
if(index < _requestGroups.size()) {
|
2007-10-11 16:58:24 +00:00
|
|
|
return _requestGroups[index];
|
|
|
|
} else {
|
2008-04-20 00:50:22 +00:00
|
|
|
return SharedHandle<RequestGroup>();
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-20 13:57:56 +00:00
|
|
|
|
2008-05-15 14:37:02 +00:00
|
|
|
const std::deque<SharedHandle<RequestGroup> >&
|
|
|
|
RequestGroupMan::getRequestGroups() const
|
|
|
|
{
|
|
|
|
return _requestGroups;
|
|
|
|
}
|
|
|
|
|
2008-05-24 12:00:51 +00:00
|
|
|
class ProcessStoppedRequestGroup {
|
|
|
|
private:
|
2008-11-03 06:49:02 +00:00
|
|
|
DownloadEngine* _e;
|
2008-05-24 12:00:51 +00:00
|
|
|
std::deque<SharedHandle<RequestGroup> >& _reservedGroups;
|
|
|
|
std::deque<SharedHandle<DownloadResult> >& _downloadResults;
|
|
|
|
Logger* _logger;
|
2008-07-12 15:09:03 +00:00
|
|
|
|
|
|
|
void saveSignature(const SharedHandle<RequestGroup>& group)
|
|
|
|
{
|
|
|
|
SharedHandle<Signature> sig =
|
|
|
|
group->getDownloadContext()->getSignature();
|
|
|
|
if(!sig.isNull() && !sig->getBody().empty()) {
|
|
|
|
// filename of signature file is the path to download file followed by
|
|
|
|
// ".sig".
|
|
|
|
std::string signatureFile = group->getFilePath()+".sig";
|
|
|
|
if(sig->save(signatureFile)) {
|
2008-07-13 12:15:56 +00:00
|
|
|
_logger->notice(MSG_SIGNATURE_SAVED, signatureFile.c_str());
|
2008-07-12 15:09:03 +00:00
|
|
|
} else {
|
2008-07-13 12:15:56 +00:00
|
|
|
_logger->notice(MSG_SIGNATURE_NOT_SAVED, signatureFile.c_str());
|
2008-07-12 15:09:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-24 12:00:51 +00:00
|
|
|
public:
|
|
|
|
ProcessStoppedRequestGroup
|
2008-11-03 06:49:02 +00:00
|
|
|
(DownloadEngine* e,
|
|
|
|
std::deque<SharedHandle<RequestGroup> >& reservedGroups,
|
2008-05-24 12:00:51 +00:00
|
|
|
std::deque<SharedHandle<DownloadResult> >& downloadResults):
|
2008-11-03 06:49:02 +00:00
|
|
|
_e(e),
|
2008-05-24 12:00:51 +00:00
|
|
|
_reservedGroups(reservedGroups),
|
|
|
|
_downloadResults(downloadResults),
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
void operator()(const SharedHandle<RequestGroup>& group)
|
|
|
|
{
|
|
|
|
if(group->getNumCommand() == 0) {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
try {
|
2008-09-07 14:38:26 +00:00
|
|
|
group->closeFile();
|
2008-05-24 12:00:51 +00:00
|
|
|
if(group->downloadFinished()) {
|
2008-09-07 14:38:26 +00:00
|
|
|
group->applyLastModifiedTimeToLocalFiles();
|
2008-05-24 12:00:51 +00:00
|
|
|
group->reportDownloadFinished();
|
|
|
|
if(group->allDownloadFinished()) {
|
|
|
|
group->getProgressInfoFile()->removeFile();
|
2008-07-12 15:09:03 +00:00
|
|
|
saveSignature(group);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
} else {
|
2008-05-24 12:00:51 +00:00
|
|
|
group->getProgressInfoFile()->save();
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
}
|
2008-05-11 13:59:27 +00:00
|
|
|
RequestGroups nextGroups;
|
2008-05-24 12:00:51 +00:00
|
|
|
group->postDownloadProcessing(nextGroups);
|
|
|
|
if(!nextGroups.empty()) {
|
2008-10-01 15:16:36 +00:00
|
|
|
_logger->debug
|
|
|
|
("Adding %lu RequestGroups as a result of PostDownloadHandler.",
|
|
|
|
static_cast<unsigned long>(nextGroups.size()));
|
2008-05-24 12:00:51 +00:00
|
|
|
_reservedGroups.insert(_reservedGroups.begin(),
|
|
|
|
nextGroups.begin(), nextGroups.end());
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
}
|
2007-10-29 14:06:59 +00:00
|
|
|
} else {
|
2008-05-24 12:00:51 +00:00
|
|
|
group->getProgressInfoFile()->save();
|
2007-10-29 14:06:59 +00:00
|
|
|
}
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(RecoverableException& ex) {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
_logger->error(EX_EXCEPTION_CAUGHT, ex);
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
2008-11-03 06:49:02 +00:00
|
|
|
group->releaseRuntimeResource(_e);
|
2008-05-24 12:00:51 +00:00
|
|
|
_downloadResults.push_back(group->createDownloadResult());
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-24 12:00:51 +00:00
|
|
|
};
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
class CollectServerStat {
|
|
|
|
private:
|
|
|
|
RequestGroupMan* _requestGroupMan;
|
|
|
|
public:
|
|
|
|
CollectServerStat(RequestGroupMan* requestGroupMan):
|
|
|
|
_requestGroupMan(requestGroupMan) {}
|
|
|
|
|
|
|
|
void operator()(const SharedHandle<RequestGroup>& group)
|
|
|
|
{
|
|
|
|
if(group->getNumCommand() == 0) {
|
|
|
|
// Collect statistics during download in PeerStats and update/register
|
|
|
|
// ServerStatMan
|
|
|
|
if(!group->getSegmentMan().isNull()) {
|
|
|
|
const std::deque<SharedHandle<PeerStat> >& peerStats =
|
|
|
|
group->getSegmentMan()->getPeerStats();
|
2009-01-06 13:13:42 +00:00
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
for(std::deque<SharedHandle<PeerStat> >::const_iterator i =
|
|
|
|
peerStats.begin(); i != peerStats.end(); ++i) {
|
|
|
|
if((*i)->getHostname().empty() || (*i)->getProtocol().empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-06 13:13:42 +00:00
|
|
|
int speed = (*i)->getAvgDownloadSpeed();
|
|
|
|
if (speed == 0) continue;
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
SharedHandle<ServerStat> ss =
|
2008-09-14 14:25:16 +00:00
|
|
|
_requestGroupMan->getOrCreateServerStat((*i)->getHostname(),
|
|
|
|
(*i)->getProtocol());
|
2009-01-06 13:13:42 +00:00
|
|
|
ss->increaseCounter();
|
|
|
|
ss->updateDownloadSpeed(speed);
|
|
|
|
if(peerStats.size() == 1) {
|
|
|
|
ss->updateSingleConnectionAvgSpeed(speed);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ss->updateMultiConnectionAvgSpeed(speed);
|
|
|
|
}
|
2008-08-04 17:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-24 12:00:51 +00:00
|
|
|
class FindStoppedRequestGroup {
|
|
|
|
public:
|
|
|
|
bool operator()(const SharedHandle<RequestGroup>& group) {
|
|
|
|
return group->getNumCommand() == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
void RequestGroupMan::updateServerStat()
|
|
|
|
{
|
|
|
|
std::for_each(_requestGroups.begin(), _requestGroups.end(),
|
|
|
|
CollectServerStat(this));
|
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void RequestGroupMan::removeStoppedGroup(DownloadEngine* e)
|
2008-05-24 12:00:51 +00:00
|
|
|
{
|
|
|
|
size_t numPrev = _requestGroups.size();
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
updateServerStat();
|
|
|
|
|
2008-05-24 12:00:51 +00:00
|
|
|
std::for_each(_requestGroups.begin(), _requestGroups.end(),
|
2008-11-03 06:49:02 +00:00
|
|
|
ProcessStoppedRequestGroup(e, _reservedGroups,
|
|
|
|
_downloadResults));
|
2008-05-24 12:00:51 +00:00
|
|
|
|
|
|
|
_requestGroups.erase(std::remove_if(_requestGroups.begin(),
|
|
|
|
_requestGroups.end(),
|
|
|
|
FindStoppedRequestGroup()),
|
|
|
|
_requestGroups.end());
|
|
|
|
|
|
|
|
size_t numRemoved = numPrev-_requestGroups.size();
|
|
|
|
if(numRemoved > 0) {
|
2008-10-01 15:16:36 +00:00
|
|
|
_logger->debug("%lu RequestGroup(s) deleted.",
|
|
|
|
static_cast<unsigned long>(numRemoved));
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
void RequestGroupMan::configureRequestGroup
|
|
|
|
(const SharedHandle<RequestGroup>& requestGroup) const
|
|
|
|
{
|
|
|
|
const std::string& uriSelectorValue = _option->get(PREF_URI_SELECTOR);
|
|
|
|
if(uriSelectorValue == V_FEEDBACK) {
|
|
|
|
requestGroup->setURISelector
|
|
|
|
(SharedHandle<URISelector>(new ServerStatURISelector(_serverStatMan)));
|
|
|
|
} else if(uriSelectorValue == V_INORDER) {
|
|
|
|
requestGroup->setURISelector
|
|
|
|
(SharedHandle<URISelector>(new InOrderURISelector()));
|
2009-01-06 13:13:42 +00:00
|
|
|
} else if(uriSelectorValue == V_ADAPTIVE) {
|
|
|
|
requestGroup->setURISelector
|
|
|
|
(SharedHandle<URISelector>(new AdaptiveURISelector(_serverStatMan,
|
|
|
|
requestGroup)));
|
2008-08-04 17:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 14:05:39 +00:00
|
|
|
static void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup,
|
|
|
|
std::deque<Command*>& commands,
|
|
|
|
DownloadEngine* e,
|
|
|
|
bool useHead)
|
|
|
|
{
|
|
|
|
requestGroup->createInitialCommand(commands, e,
|
|
|
|
useHead ?
|
|
|
|
Request::METHOD_HEAD :
|
|
|
|
Request::METHOD_GET);
|
|
|
|
}
|
|
|
|
|
2007-05-20 13:57:56 +00:00
|
|
|
void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
RequestGroups temp;
|
2008-11-03 06:49:02 +00:00
|
|
|
removeStoppedGroup(e);
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int count = 0;
|
|
|
|
for(int num = _maxSimultaneousDownloads-_requestGroups.size();
|
2007-05-20 13:57:56 +00:00
|
|
|
num > 0 && _reservedGroups.size() > 0; --num) {
|
|
|
|
RequestGroupHandle groupToAdd = _reservedGroups.front();
|
|
|
|
_reservedGroups.pop_front();
|
2007-10-11 16:58:24 +00:00
|
|
|
try {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
if(!groupToAdd->isDependencyResolved()) {
|
2008-05-24 12:00:51 +00:00
|
|
|
temp.push_back(groupToAdd);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-04 17:06:47 +00:00
|
|
|
configureRequestGroup(groupToAdd);
|
2008-05-11 09:36:39 +00:00
|
|
|
Commands commands;
|
2008-12-29 14:05:39 +00:00
|
|
|
createInitialCommand(groupToAdd, commands, e,
|
|
|
|
_option->getAsBool(PREF_USE_HEAD));
|
2007-12-04 14:52:46 +00:00
|
|
|
_requestGroups.push_back(groupToAdd);
|
2007-10-11 16:58:24 +00:00
|
|
|
++count;
|
|
|
|
e->addCommand(commands);
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(RecoverableException& ex) {
|
2007-10-11 16:58:24 +00:00
|
|
|
_logger->error(EX_EXCEPTION_CAUGHT, ex);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
_downloadResults.push_back(groupToAdd->createDownloadResult());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
2008-05-24 12:00:51 +00:00
|
|
|
_reservedGroups.insert(_reservedGroups.begin(), temp.begin(), temp.end());
|
2007-05-20 13:57:56 +00:00
|
|
|
if(count > 0) {
|
2008-04-20 05:42:15 +00:00
|
|
|
e->setNoWait(true);
|
2007-05-20 13:57:56 +00:00
|
|
|
_logger->debug("%d RequestGroup(s) added.", count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 09:36:39 +00:00
|
|
|
void RequestGroupMan::getInitialCommands(std::deque<Command*>& commands,
|
|
|
|
DownloadEngine* e)
|
2007-05-22 16:55:56 +00:00
|
|
|
{
|
2007-10-11 16:58:24 +00:00
|
|
|
for(RequestGroups::iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end();) {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
try {
|
|
|
|
if((*itr)->isDependencyResolved()) {
|
2008-08-04 17:06:47 +00:00
|
|
|
configureRequestGroup(*itr);
|
2008-12-29 14:05:39 +00:00
|
|
|
createInitialCommand(*itr, commands, e,
|
|
|
|
_option->getAsBool(PREF_USE_HEAD));
|
2007-10-11 16:58:24 +00:00
|
|
|
++itr;
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
} else {
|
|
|
|
_reservedGroups.push_front((*itr));
|
2007-11-12 11:28:16 +00:00
|
|
|
itr = _requestGroups.erase(itr);
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(RecoverableException& e) {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
|
|
|
_downloadResults.push_back((*itr)->createDownloadResult());
|
2007-10-11 16:58:24 +00:00
|
|
|
itr = _requestGroups.erase(itr);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
}
|
2007-05-22 16:55:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void RequestGroupMan::save()
|
|
|
|
{
|
|
|
|
for(RequestGroups::iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
2007-10-29 14:06:59 +00:00
|
|
|
if((*itr)->allDownloadFinished()) {
|
|
|
|
(*itr)->getProgressInfoFile()->removeFile();
|
|
|
|
} else {
|
2007-10-11 16:58:24 +00:00
|
|
|
try {
|
|
|
|
(*itr)->getProgressInfoFile()->save();
|
2008-04-27 02:22:14 +00:00
|
|
|
} catch(RecoverableException& e) {
|
2007-10-11 16:58:24 +00:00
|
|
|
_logger->error(EX_EXCEPTION_CAUGHT, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupMan::closeFile()
|
|
|
|
{
|
|
|
|
for(RequestGroups::iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
(*itr)->closeFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-20 16:46:56 +00:00
|
|
|
RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
|
|
|
|
{
|
|
|
|
DownloadStat stat;
|
|
|
|
size_t finished = 0;
|
|
|
|
size_t error = 0;
|
|
|
|
size_t inprogress = 0;
|
|
|
|
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin();
|
|
|
|
itr != _downloadResults.end(); ++itr) {
|
|
|
|
if((*itr)->result == DownloadResult::FINISHED) {
|
|
|
|
++finished;
|
|
|
|
} else {
|
|
|
|
++error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
DownloadResultHandle result = (*itr)->createDownloadResult();
|
|
|
|
if(result->result == DownloadResult::FINISHED) {
|
|
|
|
++finished;
|
|
|
|
} else {
|
|
|
|
++inprogress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stat.setCompleted(finished);
|
|
|
|
stat.setError(error);
|
|
|
|
stat.setInProgress(inprogress);
|
|
|
|
stat.setWaiting(_reservedGroups.size());
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void RequestGroupMan::showDownloadResults(std::ostream& o) const
|
2007-05-20 13:57:56 +00:00
|
|
|
{
|
2008-05-14 15:03:09 +00:00
|
|
|
static const std::string MARK_OK("OK");
|
|
|
|
static const std::string MARK_ERR("ERR");
|
|
|
|
static const std::string MARK_INPR("INPR");
|
|
|
|
|
2007-05-20 13:57:56 +00:00
|
|
|
// Download Results:
|
|
|
|
// idx|stat|path/length
|
|
|
|
// ===+====+=======================================================================
|
|
|
|
o << "\n"
|
|
|
|
<<_("Download Results:") << "\n"
|
2008-11-10 16:10:31 +00:00
|
|
|
<< "gid|stat|avg speed |path/URI" << "\n"
|
|
|
|
<< "===+====+===========+==========================================================" << "\n";
|
2008-10-21 16:26:43 +00:00
|
|
|
|
|
|
|
int ok = 0;
|
|
|
|
int err = 0;
|
|
|
|
int inpr = 0;
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin();
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
itr != _downloadResults.end(); ++itr) {
|
2008-10-21 16:26:43 +00:00
|
|
|
std::string status;
|
|
|
|
if((*itr)->result == DownloadResult::FINISHED) {
|
|
|
|
status = MARK_OK;
|
|
|
|
++ok;
|
|
|
|
} else {
|
|
|
|
status = MARK_ERR;
|
|
|
|
++err;
|
|
|
|
}
|
|
|
|
o << formatDownloadResult(status, *itr) << "\n";
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
DownloadResultHandle result = (*itr)->createDownloadResult();
|
2008-10-21 16:26:43 +00:00
|
|
|
std::string status;
|
|
|
|
if(result->result == DownloadResult::FINISHED) {
|
|
|
|
status = MARK_OK;
|
|
|
|
++ok;
|
|
|
|
} else {
|
2008-11-10 16:10:31 +00:00
|
|
|
// Since this RequestGroup is not processed by ProcessStoppedRequestGroup,
|
|
|
|
// its download stop time is not reseted.
|
|
|
|
// Reset download stop time and assign sessionTime here.
|
|
|
|
(*itr)->getDownloadContext()->resetDownloadStopTime();
|
|
|
|
result->sessionTime =
|
|
|
|
(*itr)->getDownloadContext()->calculateSessionTime();
|
2008-10-21 16:26:43 +00:00
|
|
|
status = MARK_INPR;
|
|
|
|
++inpr;
|
|
|
|
}
|
|
|
|
o << formatDownloadResult(status, result) << "\n";
|
|
|
|
}
|
|
|
|
if(ok > 0 || err > 0 || inpr > 0) {
|
|
|
|
o << "\n"
|
|
|
|
<< _("Status Legend:") << "\n";
|
|
|
|
|
|
|
|
if(ok > 0) {
|
|
|
|
o << " (OK):download completed.";
|
|
|
|
}
|
|
|
|
if(err > 0) {
|
|
|
|
o << "(ERR):error occurred.";
|
|
|
|
}
|
|
|
|
if(inpr > 0) {
|
|
|
|
o << "(INPR):download in-progress.";
|
|
|
|
}
|
|
|
|
o << "\n";
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::stringstream o;
|
|
|
|
o << std::setw(3) << downloadResult->gid << "|"
|
2008-11-10 16:10:31 +00:00
|
|
|
<< std::setw(4) << status << "|"
|
|
|
|
<< std::setw(11);
|
|
|
|
if(downloadResult->sessionTime > 0) {
|
|
|
|
o << Util::abbrevSize
|
|
|
|
(downloadResult->sessionDownloadLength*1000/downloadResult->sessionTime)+
|
|
|
|
"B/s";
|
|
|
|
} else {
|
|
|
|
o << "n/a";
|
|
|
|
}
|
|
|
|
o << "|";
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
if(downloadResult->result == DownloadResult::FINISHED) {
|
|
|
|
o << downloadResult->filePath;
|
2007-10-11 16:58:24 +00:00
|
|
|
} else {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
if(downloadResult->numUri == 0) {
|
|
|
|
if(downloadResult->filePath.empty()) {
|
2007-05-20 13:57:56 +00:00
|
|
|
o << "n/a";
|
|
|
|
} else {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
o << downloadResult->filePath;
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
o << downloadResult->uri;
|
|
|
|
if(downloadResult->numUri > 1) {
|
|
|
|
o << " (" << downloadResult->numUri-1 << "more)";
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-11 16:58:24 +00:00
|
|
|
return o.str();
|
2007-05-20 13:57:56 +00:00
|
|
|
}
|
2007-06-03 14:24:37 +00:00
|
|
|
|
|
|
|
bool RequestGroupMan::isSameFileBeingDownloaded(RequestGroup* requestGroup) const
|
|
|
|
{
|
2007-11-25 11:48:44 +00:00
|
|
|
// TODO it may be good to use dedicated method rather than use isPreLocalFileCheckEnabled
|
|
|
|
if(!requestGroup->isPreLocalFileCheckEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-03 14:24:37 +00:00
|
|
|
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
if((*itr).get() != requestGroup &&
|
|
|
|
(*itr)->getFilePath() == requestGroup->getFilePath()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
void RequestGroupMan::halt()
|
|
|
|
{
|
|
|
|
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
(*itr)->setHaltRequested(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-07 13:33:59 +00:00
|
|
|
void RequestGroupMan::forceHalt()
|
|
|
|
{
|
|
|
|
for(RequestGroups::const_iterator itr = _requestGroups.begin();
|
|
|
|
itr != _requestGroups.end(); ++itr) {
|
|
|
|
(*itr)->setForceHaltRequested(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
TransferStat RequestGroupMan::calculateStat()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
return std::accumulate(_requestGroups.begin(), _requestGroups.end(), TransferStat(),
|
|
|
|
adopt2nd(std::plus<TransferStat>(), mem_fun_sh(&RequestGroup::calculateStat)));
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-04-23 10:28:56 +00:00
|
|
|
const std::deque<SharedHandle<DownloadResult> >&
|
|
|
|
RequestGroupMan::getDownloadResults() const
|
|
|
|
{
|
|
|
|
return _downloadResults;
|
|
|
|
}
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
SharedHandle<ServerStat>
|
|
|
|
RequestGroupMan::findServerStat(const std::string& hostname,
|
|
|
|
const std::string& protocol) const
|
|
|
|
{
|
|
|
|
return _serverStatMan->find(hostname, protocol);
|
|
|
|
}
|
|
|
|
|
2008-09-14 14:25:16 +00:00
|
|
|
SharedHandle<ServerStat>
|
|
|
|
RequestGroupMan::getOrCreateServerStat(const std::string& hostname,
|
|
|
|
const std::string& protocol)
|
|
|
|
{
|
|
|
|
SharedHandle<ServerStat> ss = findServerStat(hostname, protocol);
|
|
|
|
if(ss.isNull()) {
|
|
|
|
ss.reset(new ServerStat(hostname, protocol));
|
|
|
|
addServerStat(ss);
|
|
|
|
}
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
bool RequestGroupMan::addServerStat(const SharedHandle<ServerStat>& serverStat)
|
|
|
|
{
|
|
|
|
return _serverStatMan->add(serverStat);
|
|
|
|
}
|
|
|
|
|
2008-08-10 15:22:55 +00:00
|
|
|
bool RequestGroupMan::loadServerStat(const std::string& filename)
|
|
|
|
{
|
|
|
|
std::ifstream in(filename.c_str());
|
|
|
|
if(!in) {
|
2008-08-23 15:59:15 +00:00
|
|
|
_logger->error(MSG_OPENING_READABLE_SERVER_STAT_FILE_FAILED, filename.c_str());
|
2008-08-10 15:22:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(_serverStatMan->load(in)) {
|
2008-08-23 15:59:15 +00:00
|
|
|
_logger->notice(MSG_SERVER_STAT_LOADED, filename.c_str());
|
2008-08-10 15:22:55 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2008-08-23 15:59:15 +00:00
|
|
|
_logger->error(MSG_READING_SERVER_STAT_FILE_FAILED, filename.c_str());
|
2008-08-10 15:22:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RequestGroupMan::saveServerStat(const std::string& filename) const
|
|
|
|
{
|
2008-08-23 15:42:06 +00:00
|
|
|
std::string tempfile = filename+"__temp";
|
|
|
|
std::ofstream out(tempfile.c_str());
|
2008-08-10 15:22:55 +00:00
|
|
|
if(!out) {
|
2008-08-23 15:59:15 +00:00
|
|
|
_logger->error(MSG_OPENING_WRITABLE_SERVER_STAT_FILE_FAILED,
|
2008-08-23 15:42:06 +00:00
|
|
|
tempfile.c_str());
|
2008-08-10 15:22:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-22 20:28:50 +00:00
|
|
|
if (_serverStatMan->save(out)) {
|
|
|
|
out.close();
|
|
|
|
if (File(tempfile).renameTo(filename)) {
|
|
|
|
_logger->notice(MSG_SERVER_STAT_SAVED, filename.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-10 15:22:55 +00:00
|
|
|
}
|
2008-11-22 20:28:50 +00:00
|
|
|
_logger->error(MSG_WRITING_SERVER_STAT_FILE_FAILED, filename.c_str());
|
|
|
|
return false;
|
2008-08-10 15:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RequestGroupMan::removeStaleServerStat(time_t timeout)
|
|
|
|
{
|
|
|
|
_serverStatMan->removeStaleServerStat(timeout);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|