diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index dc4069cc..cb082bdc 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -104,40 +104,42 @@ DownloadFactory::receive_load() { throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL"); if (is_network_uri(m_uri)) { - // Http handling here. m_stream.reset(new std::stringstream); - m_manager->http_queue()->insert(m_uri, m_stream, - [this]() { receive_loaded(); }, - [this](const std::string& error) { receive_failed(error); } - ); + auto done_fn = [this]() { receive_loaded(); }; + auto failed_fn = [this](const std::string& error) { receive_failed(error); }; + + m_manager->http_queue()->insert(m_uri, m_stream, done_fn, failed_fn); m_variables["tied_to_file"] = (int64_t)false; + return; + } - } else if (is_magnet_uri(m_uri)) { + if (is_magnet_uri(m_uri)) { // DEBUG: Use m_object. 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; - receive_loaded(); - - } else { - std::fstream stream(expand_path(m_uri).c_str(), std::ios::in | std::ios::binary); - - if (!stream.is_open()) - return receive_failed("Could not open file"); - - m_object = new torrent::Object; - stream >> *m_object; - - if (!stream.good()) - return receive_failed("Reading torrent file failed"); - - m_isFile = true; receive_loaded(); + return; } + + std::fstream stream(expand_path(m_uri).c_str(), std::ios::in | std::ios::binary); + + if (!stream.is_open()) + return receive_failed("Could not open file"); + + m_object = new torrent::Object; + stream >> *m_object; + + if (!stream.good()) + return receive_failed("Reading torrent file failed"); + + m_isFile = true; + + receive_loaded(); } void diff --git a/src/core/http_queue.cc b/src/core/http_queue.cc index bdc3ed6c..855a895e 100644 --- a/src/core/http_queue.cc +++ b/src/core/http_queue.cc @@ -19,14 +19,11 @@ HttpQueue::insert(const std::string& url, std::shared_ptr stream, for (auto& slot : m_signal_insert) slot(*itr); - itr->add_done_slot(torrent::this_thread::thread(), [this, itr]() { erase(itr); }); - itr->add_failed_slot(torrent::this_thread::thread(), [this, itr](auto) { erase(itr); }); - itr->add_done_slot(torrent::this_thread::thread(), std::move(done_fn)); - itr->add_failed_slot(torrent::this_thread::thread(), std::move(failed_fn)); + itr->add_done_slot(torrent::this_thread::thread(), [this, itr]() { erase(itr); }); - // TODO: Downloading http torrents doesn't seem to work. - // TODO: Quitting no longer works. + itr->add_failed_slot(torrent::this_thread::thread(), std::move(failed_fn)); + itr->add_failed_slot(torrent::this_thread::thread(), [this, itr](auto) { erase(itr); }); torrent::net_thread::http_stack()->start_get(*itr); diff --git a/src/rpc/exec_file.cc b/src/rpc/exec_file.cc index 51f77d37..d1467526 100644 --- a/src/rpc/exec_file.cc +++ b/src/rpc/exec_file.cc @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include "exec_file.h" #include "parse.h"