Reordered http queue slots to avoid race conditions.

This commit is contained in:
Jari Sundell
2026-07-07 09:34:19 +02:00
committed by rakshasa
parent 928f3e58a8
commit f1b22023a0
3 changed files with 27 additions and 28 deletions
+11 -9
View File
@@ -104,25 +104,28 @@ DownloadFactory::receive_load() {
throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL"); throw torrent::internal_error("DownloadFactory::load*() called on an object with m_stream != NULL");
if (is_network_uri(m_uri)) { if (is_network_uri(m_uri)) {
// Http handling here.
m_stream.reset(new std::stringstream); m_stream.reset(new std::stringstream);
m_manager->http_queue()->insert(m_uri, m_stream, auto done_fn = [this]() { receive_loaded(); };
[this]() { receive_loaded(); }, auto failed_fn = [this](const std::string& error) { receive_failed(error); };
[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; 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. // DEBUG: Use m_object.
m_stream.reset(new std::stringstream()); m_stream.reset(new std::stringstream());
*m_stream << "d10:magnet-uri" << m_uri.length() << ":" << m_uri << "e"; *m_stream << "d10:magnet-uri" << m_uri.length() << ":" << m_uri << "e";
m_variables["tied_to_file"] = (int64_t)false; m_variables["tied_to_file"] = (int64_t)false;
receive_loaded();
} else { receive_loaded();
return;
}
std::fstream stream(expand_path(m_uri).c_str(), std::ios::in | std::ios::binary); std::fstream stream(expand_path(m_uri).c_str(), std::ios::in | std::ios::binary);
if (!stream.is_open()) if (!stream.is_open())
@@ -137,7 +140,6 @@ DownloadFactory::receive_load() {
m_isFile = true; m_isFile = true;
receive_loaded(); receive_loaded();
}
} }
void void
+3 -6
View File
@@ -19,14 +19,11 @@ HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream,
for (auto& slot : m_signal_insert) for (auto& slot : m_signal_insert)
slot(*itr); 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_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. itr->add_failed_slot(torrent::this_thread::thread(), std::move(failed_fn));
// TODO: Quitting no longer works. itr->add_failed_slot(torrent::this_thread::thread(), [this, itr](auto) { erase(itr); });
torrent::net_thread::http_stack()->start_get(*itr); torrent::net_thread::http_stack()->start_get(*itr);
+1 -1
View File
@@ -10,8 +10,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <torrent/net/fd.h> #include <torrent/net/fd.h>
#include <torrent/system/system.h>
#include <torrent/system/thread.h> #include <torrent/system/thread.h>
#include <torrent/system/types.h>
#include "exec_file.h" #include "exec_file.h"
#include "parse.h" #include "parse.h"