Various pool_event_* and thread API cleanups.

This commit is contained in:
Jari Sundell
2025-05-31 18:22:14 +02:00
committed by GitHub
parent e8c1f3ed2c
commit f0809ec29d
8 changed files with 62 additions and 46 deletions
+1 -1
View File
@@ -307,7 +307,7 @@ apply_d_add_peer(core::Download* download, const std::string& arg) {
if (port < 1 || port > 65535)
throw torrent::input_error("Invalid port number.");
assert(std::this_thread::get_id() == torrent::main_thread()->thread_id());
assert(std::this_thread::get_id() == torrent::main_thread::thread()->thread_id());
// Currently discarding SOCK_STREAM.
torrent::this_thread::resolver()->resolve_preferred(NULL, host, AF_UNSPEC, AF_INET, [download, port](torrent::c_sa_shared_ptr sa, int err) {
+1 -1
View File
@@ -279,7 +279,7 @@ initialize_command_local() {
CMD2_ANY ("pieces.stats.total_size", std::bind(&apply_pieces_stats_total_size));
CMD2_ANY ("pieces.hash.queue_size", std::bind(&torrent::hash_queue_size));
CMD2_ANY ("pieces.hash.queue_size", std::bind(&torrent::main_thread::hash_queue_size));
CMD2_VAR_BOOL ("pieces.hash.on_completion", true);
CMD2_VAR_STRING ("directory.default", "./");
+1 -1
View File
@@ -45,7 +45,7 @@ apply_dht_add_node(const std::string& arg) {
if (port < 1 || port > 65535)
throw torrent::input_error("Invalid port number.");
assert(std::this_thread::get_id() == torrent::main_thread()->thread_id());
assert(std::this_thread::get_id() == torrent::main_thread::thread()->thread_id());
// Currently discarding SOCK_STREAM.
torrent::this_thread::resolver()->resolve_specific(nullptr, host, PF_INET, [port](torrent::c_sa_shared_ptr sa, int err) {
+2 -2
View File
@@ -16,10 +16,10 @@ WindowLog::WindowLog(torrent::log_buffer* l) :
m_task_update.slot() = std::bind(&WindowLog::receive_update, this);
unsigned int signal_index = torrent::main_thread()->signal_bitfield()->add_signal(std::bind(&WindowLog::receive_update, this));
unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&WindowLog::receive_update, this));
m_log->lock_and_set_update_slot([signal_index]() {
torrent::main_thread()->send_event_signal(signal_index, false);
torrent::main_thread::thread()->send_event_signal(signal_index, false);
});
}
+1 -1
View File
@@ -446,7 +446,7 @@ main(int argc, char** argv) {
rpc::commands.call_catch("event.system.startup_done", rpc::make_target(), "startup_done", "System startup_done event action failed: ");
torrent::main_thread()->event_loop();
torrent::utils::Thread::self()->event_loop();
control->core()->download_list()->session_save();
control->cleanup();
+5 -5
View File
@@ -41,8 +41,8 @@ SCgiTask::close() {
if (!get_fd().is_valid())
return;
torrent::main_thread()->cancel_callback_and_wait(this);
torrent::thread_self()->cancel_callback(this);
torrent::main_thread::thread()->cancel_callback_and_wait(this);
torrent::utils::Thread::self()->cancel_callback(this);
torrent::this_thread::poll()->remove_and_close(this);
@@ -261,7 +261,7 @@ void
SCgiTask::receive_call(const char* buffer, uint32_t length) {
// TODO: Rewrite RpcManager.process to pass the result buffer instead of having to copy it.
auto scgi_thread = torrent::thread_self();
auto scgi_thread = torrent::utils::Thread::self();
auto result_callback = [this, scgi_thread](const char* b, uint32_t l) {
receive_write(b, l);
@@ -279,7 +279,7 @@ SCgiTask::receive_call(const char* buffer, uint32_t length) {
switch (content_type()) {
case rpc::SCgiTask::ContentType::JSON:
torrent::main_thread()->callback_interrupt_pollling(this, [buffer, length, result_callback]() {
torrent::main_thread::thread()->callback_interrupt_pollling(this, [buffer, length, result_callback]() {
rpc.process(RpcManager::RPCType::JSON, buffer, length,
[result_callback](const char* b, uint32_t l) {
result_callback(b, l);
@@ -289,7 +289,7 @@ SCgiTask::receive_call(const char* buffer, uint32_t length) {
break;
case rpc::SCgiTask::ContentType::XML:
torrent::main_thread()->callback_interrupt_pollling(this, [buffer, length, result_callback]() {
torrent::main_thread::thread()->callback_interrupt_pollling(this, [buffer, length, result_callback]() {
rpc.process(RpcManager::RPCType::XML, buffer, length,
[result_callback](const char* b, uint32_t l) {
result_callback(b, l);
+2 -2
View File
@@ -18,10 +18,10 @@ ElementLogComplete::ElementLogComplete(torrent::log_buffer* l) :
m_window(NULL),
m_log(l) {
unsigned int signal_index = torrent::main_thread()->signal_bitfield()->add_signal(std::bind(&ElementLogComplete::received_update, this));
unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&ElementLogComplete::received_update, this));
m_log->lock_and_set_update_slot([signal_index]() {
torrent::main_thread()->send_event_signal(signal_index, false);
torrent::main_thread::thread()->send_event_signal(signal_index, false);
});
}
+49 -33
View File
@@ -6,11 +6,11 @@
#include <iostream>
#include <unistd.h>
#include <torrent/event.h>
#include <torrent/net/socket_address.h>
#include <torrent/net/fd.h>
#include <torrent/utils/log.h>
#include <torrent/utils/random.h>
#include "torrent/event.h"
#include "torrent/net/socket_address.h"
#include "torrent/net/fd.h"
#include "torrent/utils/log.h"
#include "torrent/utils/random.h"
#define MOCK_CLEANUP_MAP(MOCK_FUNC) \
CPPUNIT_ASSERT_MESSAGE("expected mock function calls not completed for '" #MOCK_FUNC "'", mock_cleanup_map(&MOCK_FUNC) || ignore_assert);
@@ -28,15 +28,17 @@ mock_clear(bool ignore_assert) {
MOCK_CLEANUP_MAP(torrent::fd__setsockopt_int);
MOCK_CLEANUP_MAP(torrent::fd__socket);
MOCK_CLEANUP_MAP(torrent::poll_event_open);
MOCK_CLEANUP_MAP(torrent::poll_event_close);
MOCK_CLEANUP_MAP(torrent::poll_event_closed);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_read);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_write);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_error);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_read);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_write);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_open);
MOCK_CLEANUP_MAP(torrent::this_thread::event_open_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_close_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_closed_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_read);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_write);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_read);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_write);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_and_close);
MOCK_CLEANUP_MAP(torrent::random_uniform_uint16);
MOCK_CLEANUP_MAP(torrent::random_uniform_uint32);
@@ -117,52 +119,66 @@ int fd__socket(int domain, int type, int protocol) {
}
//
// Mock functions for 'torrent/event.h':
// Mock functions for 'torrent/common.h':
//
void poll_event_open(Event* event) {
namespace this_thread {
void event_open(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_open, event);
return mock_call<void>(__func__, &torrent::this_thread::event_open, event);
}
void poll_event_close(Event* event) {
void event_open_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_close, event);
return mock_call<void>(__func__, &torrent::this_thread::event_open_and_count, event);
}
void poll_event_closed(Event* event) {
void event_close_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_closed, event);
return mock_call<void>(__func__, &torrent::this_thread::event_close_and_count, event);
}
void poll_event_insert_read(Event* event) {
void event_closed_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_read, event);
return mock_call<void>(__func__, &torrent::this_thread::event_closed_and_count, event);
}
void poll_event_insert_write(Event* event) {
void event_insert_read(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_write, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_read, event);
}
void poll_event_insert_error(Event* event) {
void event_insert_write(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_error, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_write, event);
}
void poll_event_remove_read(Event* event) {
void event_insert_error(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_read, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_error, event);
}
void poll_event_remove_write(Event* event) {
void event_remove_read(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_write, event);
return mock_call<void>(__func__, &torrent::this_thread::event_remove_read, event);
}
void poll_event_remove_error(Event* event) {
void event_remove_write(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_error, event);
return mock_call<void>(__func__, &torrent::this_thread::event_remove_write, event);
}
void event_remove_error(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::this_thread::event_remove_error, event);
}
void event_remove_and_close(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::this_thread::event_remove_and_close, event);
}
}
//