From 5cb12318c516ba07eddd38659863d3f0c27479cb Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 7 Mar 2017 20:17:35 -0500 Subject: [PATCH] fix bug where settings_pack::file_pool_size setting was not being honored --- ChangeLog | 1 + include/libtorrent/settings_pack.hpp | 4 +-- simulation/test_file_pool.cpp | 53 ++++++++++++++++++++++++++++ src/disk_io_thread.cpp | 7 ++-- src/session_impl.cpp | 18 ---------- 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f9a48279..45552b0d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix bug where settings_pack::file_pool_size setting was not being honored * add feature to periodically close files (to make windows clear disk cache) * fix bug in torrent_handle::file_status * fix issue with peers not updated on metadata from magnet links diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 6938a200d..76b4baae0 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -786,9 +786,7 @@ namespace libtorrent // for viruses. deferring the closing of the files will be the // difference between a usable system and a completely hogged down // system. Most operating systems also has a limit on the total number - // of file descriptors a process may have open. It is usually a good - // idea to find this limit and set the number of connections and the - // number of files limits so their sum is slightly below it. + // of file descriptors a process may have open. file_pool_size, // ``max_failcount`` is the maximum times we try to connect to a peer diff --git a/simulation/test_file_pool.cpp b/simulation/test_file_pool.cpp index 16d8eb051..8dff42d59 100644 --- a/simulation/test_file_pool.cpp +++ b/simulation/test_file_pool.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session.hpp" #include "libtorrent/session_stats.hpp" #include "libtorrent/file.hpp" +#include "libtorrent/torrent_info.hpp" using namespace libtorrent; @@ -84,3 +85,55 @@ TORRENT_TEST(close_file_interval) TEST_CHECK(ran_to_completion); } +TORRENT_TEST(file_pool_size) +{ + bool ran_to_completion = false; + int max_files = 0; + + setup_swarm(2, swarm_test::download + // add session + , [](lt::settings_pack& pack) + { + pack.set_int(lt::settings_pack::file_pool_size, 5); + } + // add torrent + , [](lt::add_torrent_params& atp) { + // we need a torrent with lots of files in it, to hit the + // file_size_limit we set. + file_storage fs; + for (int i = 0; i < 0x10 * 9; ++i) + { + char filename[50]; + snprintf(filename, sizeof(filename), "root/file-%d", i); + fs.add_file(filename, 0x400); + } + atp.ti = boost::make_shared(*atp.ti); + atp.ti->remap_files(fs); + } + // on alert + , [&](lt::alert const* a, lt::session&) + {} + // terminate + , [&](int ticks, lt::session& ses) -> bool + { + if (ticks > 80) + { + TEST_ERROR("timeout"); + return true; + } + + std::vector status; + ses.get_torrents().at(0).file_status(status); + printf("open files: %d\n", int(status.size())); + max_files = std::max(max_files, int(status.size())); + if (!is_seed(ses)) return false; + printf("completed in %d ticks\n", ticks); + ran_to_completion = true; + return true; + }); + + TEST_CHECK(max_files <= 5); + TEST_CHECK(max_files >= 4); + TEST_CHECK(ran_to_completion); +} + diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 2d4d284fa..f5812984c 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -57,10 +57,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/debug.hpp" -#if TORRENT_USE_RLIMIT -#include -#endif - #define DEBUG_DISK_THREAD 0 #if __cplusplus >= 201103L || defined __clang__ @@ -172,7 +168,7 @@ namespace libtorrent // futexes, shared objects etc. // 80% of the available file descriptors should go to connections // 20% goes towards regular files - const int max_files = (std::min)((std::max)(5 + const int max_files = std::min((std::max)(5 , (max_open_files() - 20) * 2 / 10) , m_file_pool.size_limit()); m_file_pool.resize(max_files); @@ -282,6 +278,7 @@ namespace libtorrent apply_pack(pack, m_settings); error_code ec; m_disk_cache.set_settings(m_settings, ec); + m_file_pool.resize(m_settings.get_int(settings_pack::file_pool_size)); #ifndef TORRENT_NO_DEPRECATE if (ec && alerts.should_post()) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 10d632263..a088dc7ca 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -57,24 +57,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if TORRENT_USE_RLIMIT - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlong-long" -#endif // __GNUC__ - -#include - -// capture this here where warnings are disabled (the macro generates warnings) -const rlim_t rlim_infinity = RLIM_INFINITY; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif // __GNUC__ - -#endif // TORRENT_USE_RLIMIT - #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/openssl.hpp"