diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index b2fcc43a..dc4069cc 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -107,10 +107,10 @@ DownloadFactory::receive_load() { // Http handling here. m_stream.reset(new std::stringstream); - HttpQueue::iterator itr = m_manager->http_queue()->insert(m_uri, m_stream); - - itr->add_done_slot(torrent::this_thread::thread(), [this]() { receive_loaded(); }); - itr->add_failed_slot(torrent::this_thread::thread(), [this](const std::string& error) { receive_failed(error); }); + m_manager->http_queue()->insert(m_uri, m_stream, + [this]() { receive_loaded(); }, + [this](const std::string& error) { receive_failed(error); } + ); m_variables["tied_to_file"] = (int64_t)false; diff --git a/src/core/http_queue.cc b/src/core/http_queue.cc index 42a7516f..bdc3ed6c 100644 --- a/src/core/http_queue.cc +++ b/src/core/http_queue.cc @@ -9,7 +9,8 @@ namespace core { HttpQueue::iterator -HttpQueue::insert(const std::string& url, std::shared_ptr stream) { +HttpQueue::insert(const std::string& url, std::shared_ptr stream, + std::function done_fn, std::function failed_fn) { auto itr = base_type::insert(end(), torrent::net::HttpGet(url, stream)); itr->set_max_file_size(15 << 20); @@ -18,9 +19,12 @@ 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_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)); + // TODO: Downloading http torrents doesn't seem to work. // TODO: Quitting no longer works. diff --git a/src/core/http_queue.h b/src/core/http_queue.h index 5f107063..49f17e03 100644 --- a/src/core/http_queue.h +++ b/src/core/http_queue.h @@ -39,7 +39,8 @@ public: // // Consider adding a flag to indicate whetever HttpQueue should // delete the stream. - iterator insert(const std::string& url, std::shared_ptr stream); + iterator insert(const std::string& url, std::shared_ptr stream, + std::function done_fn, std::function failed_fn); void erase(iterator itr); void clear();