mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 06:39:23 +00:00
* Make the torrent::Object immediately after loading a file to lower memory footprint.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1133 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -70,9 +70,27 @@ is_network_uri(const std::string& uri) {
|
|||||||
std::strncmp(uri.c_str(), "ftp://", 6) == 0;
|
std::strncmp(uri.c_str(), "ftp://", 6) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
download_factory_add_stream(torrent::Object* root, const char* key, const char* filename) {
|
||||||
|
std::fstream stream(filename, std::ios::in | std::ios::binary);
|
||||||
|
|
||||||
|
if (!stream.is_open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
torrent::Object obj;
|
||||||
|
stream >> obj;
|
||||||
|
|
||||||
|
if (!stream.good())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
root->insert_key_move(key, obj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
DownloadFactory::DownloadFactory(Manager* m) :
|
DownloadFactory::DownloadFactory(Manager* m) :
|
||||||
m_manager(m),
|
m_manager(m),
|
||||||
m_stream(NULL),
|
m_stream(NULL),
|
||||||
|
m_object(NULL),
|
||||||
m_commited(false),
|
m_commited(false),
|
||||||
m_loaded(false),
|
m_loaded(false),
|
||||||
|
|
||||||
@@ -95,6 +113,7 @@ DownloadFactory::~DownloadFactory() {
|
|||||||
priority_queue_erase(&taskScheduler, &m_taskCommit);
|
priority_queue_erase(&taskScheduler, &m_taskCommit);
|
||||||
|
|
||||||
delete m_stream;
|
delete m_stream;
|
||||||
|
delete m_object;
|
||||||
m_stream = NULL;
|
m_stream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,10 +159,13 @@ DownloadFactory::receive_load() {
|
|||||||
if (!stream.is_open())
|
if (!stream.is_open())
|
||||||
return receive_failed("Could not open file");
|
return receive_failed("Could not open file");
|
||||||
|
|
||||||
m_stream = new std::stringstream;
|
m_object = new torrent::Object;
|
||||||
m_isFile = true;
|
stream >> *m_object;
|
||||||
|
|
||||||
*m_stream << stream.rdbuf();
|
if (!stream.good())
|
||||||
|
return receive_failed("Reading torrent file failed");
|
||||||
|
|
||||||
|
m_isFile = true;
|
||||||
|
|
||||||
receive_loaded();
|
receive_loaded();
|
||||||
}
|
}
|
||||||
@@ -165,29 +187,16 @@ DownloadFactory::receive_commit() {
|
|||||||
receive_success();
|
receive_success();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
download_factory_add_stream(torrent::Object* root, const char* key, const char* filename) {
|
|
||||||
std::fstream stream(filename, std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (!stream.is_open())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
torrent::Object obj;
|
|
||||||
stream >> obj;
|
|
||||||
|
|
||||||
if (!stream.good())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
root->insert_key_move(key, obj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadFactory::receive_success() {
|
DownloadFactory::receive_success() {
|
||||||
if (m_stream == NULL)
|
if (m_stream == NULL)
|
||||||
throw torrent::internal_error("DownloadFactory::receive_success() called on an object with m_stream == NULL.");
|
throw torrent::internal_error("DownloadFactory::receive_success() called on an object with m_stream == NULL.");
|
||||||
|
|
||||||
Download* download = m_manager->download_list()->create(m_stream, m_printLog);
|
Download* download = m_stream != NULL ?
|
||||||
|
m_manager->download_list()->create(m_stream, m_printLog) :
|
||||||
|
m_manager->download_list()->create(m_object, m_printLog);
|
||||||
|
|
||||||
|
m_object = NULL;
|
||||||
|
|
||||||
if (download == NULL) {
|
if (download == NULL) {
|
||||||
// core::Manager should already have added the error message to
|
// core::Manager should already have added the error message to
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ private:
|
|||||||
|
|
||||||
Manager* m_manager;
|
Manager* m_manager;
|
||||||
std::iostream* m_stream;
|
std::iostream* m_stream;
|
||||||
|
torrent::Object* m_object;
|
||||||
|
|
||||||
bool m_commited;
|
bool m_commited;
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
|||||||
@@ -112,6 +112,27 @@ DownloadList::find_hex_ptr(const char* hash) {
|
|||||||
return itr != end() ? *itr : NULL;
|
return itr != end() ? *itr : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Download*
|
||||||
|
DownloadList::create(torrent::Object* obj, bool printLog) {
|
||||||
|
torrent::Download download;
|
||||||
|
|
||||||
|
try {
|
||||||
|
download = torrent::download_add(obj);
|
||||||
|
|
||||||
|
} catch (torrent::local_error& e) {
|
||||||
|
delete obj;
|
||||||
|
|
||||||
|
if (printLog)
|
||||||
|
control->core()->push_log(e.what());
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There's no non-critical exceptions that should be throwable by
|
||||||
|
// the ctor, so don't catch.
|
||||||
|
return new Download(download);
|
||||||
|
}
|
||||||
|
|
||||||
Download*
|
Download*
|
||||||
DownloadList::create(std::istream* str, bool printLog) {
|
DownloadList::create(std::istream* str, bool printLog) {
|
||||||
torrent::Object* object = new torrent::Object;
|
torrent::Object* object = new torrent::Object;
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ public:
|
|||||||
|
|
||||||
// Might move this to DownloadFactory.
|
// Might move this to DownloadFactory.
|
||||||
Download* create(std::istream* str, bool printLog);
|
Download* create(std::istream* str, bool printLog);
|
||||||
|
Download* create(torrent::Object* obj, bool printLog);
|
||||||
|
|
||||||
iterator insert(Download* d);
|
iterator insert(Download* d);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user