mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-05 17:52:29 +00:00
Use shared_ptr for CurlGet stream and improved thread-safety.
This commit is contained in:
@@ -75,9 +75,7 @@ DownloadFactory::~DownloadFactory() {
|
||||
torrent::this_thread::scheduler()->erase(&m_task_load);
|
||||
torrent::this_thread::scheduler()->erase(&m_task_commit);
|
||||
|
||||
delete m_stream;
|
||||
delete m_object;
|
||||
m_stream = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -92,7 +90,7 @@ DownloadFactory::load_raw_data(const std::string& input) {
|
||||
if (m_stream)
|
||||
throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL");
|
||||
|
||||
m_stream = new std::stringstream(input);
|
||||
m_stream.reset(new std::stringstream(input));
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
@@ -108,7 +106,7 @@ DownloadFactory::receive_load() {
|
||||
|
||||
if (is_network_uri(m_uri)) {
|
||||
// Http handling here.
|
||||
m_stream = new std::stringstream;
|
||||
m_stream.reset(new std::stringstream);
|
||||
|
||||
HttpQueue::iterator itr = m_manager->http_queue()->insert(m_uri, m_stream);
|
||||
|
||||
@@ -119,7 +117,7 @@ DownloadFactory::receive_load() {
|
||||
|
||||
} else if (is_magnet_uri(m_uri)) {
|
||||
// DEBUG: Use m_object.
|
||||
m_stream = new std::stringstream();
|
||||
m_stream.reset(new std::stringstream());
|
||||
*m_stream << "d10:magnet-uri" << m_uri.length() << ":" << m_uri << "e";
|
||||
|
||||
m_variables["tied_to_file"] = (int64_t)false;
|
||||
@@ -171,8 +169,8 @@ DownloadFactory::receive_success() {
|
||||
else
|
||||
tracker_key = random() % (std::numeric_limits<uint32_t>::max() - 1) + 1;
|
||||
|
||||
Download* download = m_stream != NULL ?
|
||||
m_manager->download_list()->create(m_stream, tracker_key, m_printLog) :
|
||||
Download* download = m_stream != nullptr ?
|
||||
m_manager->download_list()->create(m_stream.get(), tracker_key, m_printLog) :
|
||||
m_manager->download_list()->create(m_object, tracker_key, m_printLog);
|
||||
|
||||
m_object = NULL;
|
||||
|
||||
@@ -62,9 +62,9 @@ private:
|
||||
|
||||
void initialize_rtorrent(Download* download, torrent::Object* rtorrent);
|
||||
|
||||
Manager* m_manager;
|
||||
std::iostream* m_stream{};
|
||||
torrent::Object* m_object{};
|
||||
Manager* m_manager;
|
||||
std::shared_ptr<std::iostream> m_stream;
|
||||
torrent::Object* m_object{};
|
||||
|
||||
bool m_commited{};
|
||||
bool m_loaded{};
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace core {
|
||||
|
||||
HttpQueue::iterator
|
||||
HttpQueue::insert(const std::string& url, std::iostream* stream) {
|
||||
HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream) {
|
||||
auto itr = base_type::insert(end(), torrent::net::HttpGet(url, stream));
|
||||
|
||||
itr->add_done_slot([this, itr]() { erase(itr); });
|
||||
@@ -16,6 +16,7 @@ HttpQueue::insert(const std::string& url, std::iostream* stream) {
|
||||
|
||||
torrent::net_thread::http_stack()->start_get(*itr);
|
||||
|
||||
// TODO: Move above?
|
||||
for (auto& slot : m_signal_insert)
|
||||
slot(*itr);
|
||||
|
||||
@@ -27,6 +28,7 @@ HttpQueue::erase(iterator signal_itr) {
|
||||
for (const auto& slot : m_signal_erase)
|
||||
slot(*signal_itr);
|
||||
|
||||
signal_itr->close();
|
||||
base_type::erase(signal_itr);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <torrent/net/http_get.h>
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
//
|
||||
// Consider adding a flag to indicate whetever HttpQueue should
|
||||
// delete the stream.
|
||||
iterator insert(const std::string& url, std::iostream* stream);
|
||||
iterator insert(const std::string& url, std::shared_ptr<std::ostream> stream);
|
||||
void erase(iterator itr);
|
||||
|
||||
void clear();
|
||||
|
||||
Reference in New Issue
Block a user