From 0a76faa4278cad3a5fc2bcbc9f8ea60af2c40181 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Wed, 17 Feb 2010 17:18:54 +0000 Subject: [PATCH] * Copy a torrent to std::stringstream instead of keeping a fstream open. This ensures rtorrent doesn't run out of file descriptors during launch. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1132 e378c898-3ddf-0310-93e7-cc216c733640 --- src/core/download_factory.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index e0f29735..16aee928 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -135,12 +135,15 @@ DownloadFactory::receive_load() { m_variables["tied_to_file"] = (int64_t)false; } else { - std::fstream* stream = new std::fstream(rak::path_expand(m_uri).c_str(), std::ios::in | std::ios::binary); - m_stream = stream; + std::fstream stream(rak::path_expand(m_uri).c_str(), std::ios::in | std::ios::binary); + + if (!stream.is_open()) + return receive_failed("Could not open file"); + + m_stream = new std::stringstream; m_isFile = true; - if (!stream->is_open()) - return receive_failed("Could not open file"); + *m_stream << stream.rdbuf(); receive_loaded(); }