From 543cbc6d1c468b2c5475769a90c530dad624c565 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 29 Jan 2018 17:03:14 +0800 Subject: [PATCH] Add "Coalesce reads & writes" checkbox in advanced options The setting is defaulted to ON for Windows. Closes #8295. --- src/base/bittorrent/session.cpp | 22 ++++++++++++++++++++++ src/base/bittorrent/session.h | 3 +++ src/gui/advancedsettings.cpp | 8 ++++++++ src/gui/advancedsettings.h | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 707761ff2..f0ce251a2 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -280,6 +280,11 @@ Session::Session(QObject *parent) , m_diskCacheTTL(BITTORRENT_SESSION_KEY("DiskCacheTTL"), 60) , m_useOSCache(BITTORRENT_SESSION_KEY("UseOSCache"), true) , m_guidedReadCacheEnabled(BITTORRENT_SESSION_KEY("GuidedReadCache"), true) +#ifdef Q_OS_WIN + , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), true) +#else + , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), false) +#endif , m_isSuggestMode(BITTORRENT_SESSION_KEY("SuggestMode"), false) , m_sendBufferWatermark(BITTORRENT_SESSION_KEY("SendBufferWatermark"), 500) , m_sendBufferLowWatermark(BITTORRENT_SESSION_KEY("SendBufferLowWatermark"), 10) @@ -1303,6 +1308,10 @@ void Session::configure(libtorrent::settings_pack &settingsPack) settingsPack.set_int(libt::settings_pack::disk_io_read_mode, mode); settingsPack.set_int(libt::settings_pack::disk_io_write_mode, mode); settingsPack.set_bool(libt::settings_pack::guided_read_cache, isGuidedReadCacheEnabled()); + + settingsPack.set_bool(libt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled()); + settingsPack.set_bool(libt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled()); + settingsPack.set_int(libt::settings_pack::suggest_mode, isSuggestModeEnabled() ? libt::settings_pack::suggest_read_cache : libt::settings_pack::no_piece_suggestions); @@ -3049,6 +3058,19 @@ void Session::setGuidedReadCacheEnabled(bool enabled) configureDeferred(); } +bool Session::isCoalesceReadWriteEnabled() const +{ + return m_coalesceReadWriteEnabled; +} + +void Session::setCoalesceReadWriteEnabled(bool enabled) +{ + if (enabled == m_coalesceReadWriteEnabled) return; + + m_coalesceReadWriteEnabled = enabled; + configureDeferred(); +} + bool Session::isSuggestModeEnabled() const { return m_isSuggestMode; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 0e219fb1d..09082dd1f 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -382,6 +382,8 @@ namespace BitTorrent void setUseOSCache(bool use); bool isGuidedReadCacheEnabled() const; void setGuidedReadCacheEnabled(bool enabled); + bool isCoalesceReadWriteEnabled() const; + void setCoalesceReadWriteEnabled(bool enabled); bool isSuggestModeEnabled() const; void setSuggestMode(bool mode); int sendBufferWatermark() const; @@ -646,6 +648,7 @@ namespace BitTorrent CachedSettingValue m_diskCacheTTL; CachedSettingValue m_useOSCache; CachedSettingValue m_guidedReadCacheEnabled; + CachedSettingValue m_coalesceReadWriteEnabled; CachedSettingValue m_isSuggestMode; CachedSettingValue m_sendBufferWatermark; CachedSettingValue m_sendBufferLowWatermark; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index d209a4988..eabef3ed5 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -82,6 +82,7 @@ enum AdvSettingsRows DISK_CACHE_TTL, OS_CACHE, GUIDED_READ_CACHE, + COALESCE_RW, SUGGEST_MODE, SEND_BUF_WATERMARK, SEND_BUF_LOW_WATERMARK, @@ -142,6 +143,8 @@ void AdvancedSettings::saveAdvancedSettings() session->setUseOSCache(cb_os_cache.isChecked()); // Guided read cache session->setGuidedReadCacheEnabled(cbGuidedReadCache.isChecked()); + // Coalesce reads & writes + session->setCoalesceReadWriteEnabled(cbCoalesceRW.isChecked()); // Suggest mode session->setSuggestMode(cbSuggestMode.isChecked()); // Send buffer watermark @@ -313,6 +316,11 @@ void AdvancedSettings::loadAdvancedSettings() // Guided read cache cbGuidedReadCache.setChecked(session->isGuidedReadCacheEnabled()); addRow(GUIDED_READ_CACHE, tr("Guided read cache"), &cbGuidedReadCache); + // Coalesce reads & writes + cbCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled()); +#if LIBTORRENT_VERSION_NUM >= 10107 + addRow(COALESCE_RW, tr("Coalesce reads & writes"), &cbCoalesceRW); +#endif // Suggest mode cbSuggestMode.setChecked(session->isSuggestModeEnabled()); addRow(SUGGEST_MODE, tr("Send upload piece suggestions"), &cbSuggestMode); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 78e976577..8c1893c00 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -80,7 +80,7 @@ private: QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding, cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status, cb_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cb_announce_all_tiers, - cbGuidedReadCache, cbMultiConnectionsPerIp, cbSuggestMode; + cbGuidedReadCache, cbMultiConnectionsPerIp, cbSuggestMode, cbCoalesceRW; QComboBox combo_iface, combo_iface_address, comboUtpMixedMode, comboChokingAlgorithm, comboSeedChokingAlgorithm; QLineEdit txtAnnounceIP;