From 05831942a72d8e45b4aa120f28753add431613a9 Mon Sep 17 00:00:00 2001 From: xirvik Date: Wed, 29 Jul 2026 22:01:49 +0000 Subject: [PATCH] commands: don't register min_alloc/max_alloc for the generic socket category SocketManager throws internal_error for category_generic, aborting rtorrent over RPC. --- src/command_local.cc | 8 +++-- test/Makefile.am | 2 ++ test/src/test_command_local.cc | 54 ++++++++++++++++++++++++++++++++++ test/src/test_command_local.h | 15 ++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 test/src/test_command_local.cc create mode 100644 test/src/test_command_local.h diff --git a/src/command_local.cc b/src/command_local.cc index 277b5a8c..269a6e9b 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -250,12 +250,12 @@ initialize_command_local() { CMD_ANY (category_name + ".size", [category](auto, auto) { return torrent::runtime::socket_manager()->category_managed_size(category); }); CMD_ANY (category_name + ".max_size", [category](auto, auto) { return torrent::runtime::socket_manager()->category_max_size(category); }); - CMD_ANY (category_name + ".min_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_min_allocation(category); }); - CMD_ANY (category_name + ".max_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_max_allocation(category); }); if (i == 0) continue; + CMD_ANY (category_name + ".min_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_min_allocation(category); }); + CMD_ANY (category_name + ".max_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_max_allocation(category); }); CMD_ANY_VALUE_V(category_name + ".min_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_min_allocation(category, value); }); CMD_ANY_VALUE_V(category_name + ".max_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_max_allocation(category, value); }); } @@ -354,6 +354,10 @@ initialize_command_local() { rpc::rpc.mark_safe(category_name + ".size"); rpc::rpc.mark_safe(category_name + ".max_size"); + + if (i == 0) + continue; + rpc::rpc.mark_safe(category_name + ".min_alloc"); rpc::rpc.mark_safe(category_name + ".max_alloc"); } diff --git a/test/Makefile.am b/test/Makefile.am index aae18225..d6eb396e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -49,6 +49,8 @@ rtorrent_Test_Rpc_SOURCES = $(rtorrent_Test_Common) \ rtorrent_Test_Src_SOURCES = $(rtorrent_Test_Common) \ src/test_command_dynamic.cc \ src/test_command_dynamic.h \ + src/test_command_local.cc \ + src/test_command_local.h \ src/test_watch_ready_queue.cc \ src/test_watch_ready_queue.h diff --git a/test/src/test_command_local.cc b/test/src/test_command_local.cc new file mode 100644 index 00000000..46b15e21 --- /dev/null +++ b/test/src/test_command_local.cc @@ -0,0 +1,54 @@ +#include "config.h" + +#include "test/src/test_command_local.h" + +#include +#include +#include + +#include "control.h" +#include "globals.h" +#include "rpc/parse_commands.h" + +CPPUNIT_TEST_SUITE_REGISTRATION(TestCommandLocal); + +void initialize_command_local(); + +void +TestCommandLocal::setUp() { + torrent::initialize_main_thread(); + torrent::initialize(); + + if (control == nullptr) + control = new Control; + + if (!rpc::commands.has("system.sockets.size")) + initialize_command_local(); +} + +void +TestCommandLocal::tearDown() { + torrent::cleanup(); +} + +void +TestCommandLocal::test_socket_category_commands() { + for (uint32_t i = 0; i < torrent::runtime::SocketManager::category_count; ++i) { + auto category = static_cast(i); + auto name = "system.sockets." + torrent::option_to_str_or_throw(torrent::OPTION_SOCKET_CATEGORY, i); + + for (const auto suffix : {".size", ".max_size", ".min_alloc", ".max_alloc"}) + if (rpc::commands.has(name + suffix)) + CPPUNIT_ASSERT_NO_THROW(rpc::commands.call(name + suffix)); + + const bool has_allocation = category != torrent::runtime::category_generic; + + CPPUNIT_ASSERT(rpc::commands.has(name + ".size")); + CPPUNIT_ASSERT(rpc::commands.has(name + ".max_size")); + + CPPUNIT_ASSERT_EQUAL(has_allocation, rpc::commands.has(name + ".min_alloc")); + CPPUNIT_ASSERT_EQUAL(has_allocation, rpc::commands.has(name + ".max_alloc")); + CPPUNIT_ASSERT_EQUAL(has_allocation, rpc::commands.has(name + ".min_alloc.set")); + CPPUNIT_ASSERT_EQUAL(has_allocation, rpc::commands.has(name + ".max_alloc.set")); + } +} diff --git a/test/src/test_command_local.h b/test/src/test_command_local.h new file mode 100644 index 00000000..652febfc --- /dev/null +++ b/test/src/test_command_local.h @@ -0,0 +1,15 @@ +#include "test/helpers/test_fixture.h" + +class TestCommandLocal : public test_fixture { + CPPUNIT_TEST_SUITE(TestCommandLocal); + + CPPUNIT_TEST(test_socket_category_commands); + + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void test_socket_category_commands(); +};