From 6c880159c927f87ae4013e32023eb89a5336b5a4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 4 Apr 2020 13:38:31 +0200 Subject: [PATCH] fix bug in auto disk cache size logic --- ChangeLog | 1 + include/libtorrent/settings_pack.hpp | 1 + src/disk_buffer_pool.cpp | 2 +- src/platform_util.cpp | 2 +- src/settings_pack.cpp | 6 ++++++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78614a2d7..a50375f43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix bug in auto disk cache size logic * fix issue with outgoing_interfaces setting, where bind() would be called twice * add build option to disable share-mode * support validation of HTTPS trackers diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index e8e48f7d9..8341673f6 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -78,6 +78,7 @@ namespace aux { , aux::session_settings_single_thread& sett , std::vector* callbacks = nullptr); TORRENT_EXTRA_EXPORT void run_all_updates(aux::session_impl& ses); + TORRENT_EXTRA_EXPORT int default_int_value(int const name); // converts a setting integer (from the enums string_types, int_types or // bool_types) to a string, and vice versa. diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 7c238d7c5..3d1b8248a 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -292,7 +292,7 @@ namespace libtorrent { if (cache_size < 0) { std::int64_t phys_ram = total_physical_ram(); - if (phys_ram == 0) m_max_use = 1024; + if (phys_ram == 0) m_max_use = default_int_value(settings_pack::cache_size); else { // this is the logic to calculate the automatic disk cache size diff --git a/src/platform_util.cpp b/src/platform_util.cpp index 9ce1ac1cb..8b5298d13 100644 --- a/src/platform_util.cpp +++ b/src/platform_util.cpp @@ -112,7 +112,7 @@ namespace libtorrent { MEMORYSTATUSEX ms; ms.dwLength = sizeof(MEMORYSTATUSEX); if (GlobalMemoryStatusEx(&ms)) - ret = int(ms.ullTotalPhys); + ret = ms.ullTotalPhys; else ret = 0; #elif defined TORRENT_LINUX diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 3488d75db..15d9c8e42 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -531,6 +531,12 @@ constexpr int CLOSE_FILE_INTERVAL = 0; return ret; } + int default_int_value(int const name) + { + TORRENT_ASSERT((name & settings_pack::type_mask) == settings_pack::int_type_base); + return int_settings[name - settings_pack::int_type_base].default_value; + } + void apply_pack(settings_pack const* pack, aux::session_settings& sett , aux::session_impl* ses) {