diff --git a/.travis.yml b/.travis.yml index 8ce157a39..216b69636 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ before_script: script: - cd test - bjam -j2 warnings=off -l600 $CC - - bjam -j2 variant=test_debug warnings=off $CC + - bjam -j2 variant=test_debug warnings=off -l600 $CC - cd ../examples - bjam -j2 variant=test_debug warnings=off $CC - bjam -j2 variant=test_barebones warnings=off $CC diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index bbe7d81bb..f2e794b5a 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -46,9 +46,9 @@ namespace void outgoing_ports(lt::session& s, int _min, int _max) { allow_threading_guard guard; - settings_pack p; - p.set_int(settings_pack::outgoing_port, _min); - p.set_int(settings_pack::num_outgoing_ports, _max - _min); + settings_pack p; + p.set_int(settings_pack::outgoing_port, _min); + p.set_int(settings_pack::num_outgoing_ports, _max - _min); s.apply_settings(p); return; } @@ -126,7 +126,7 @@ namespace dict session_get_settings(lt::session const& ses) { - aux::session_settings sett; + settings_pack sett; { allow_threading_guard guard; sett = ses.get_settings(); diff --git a/include/libtorrent/aux_/disable_warnings_push.hpp b/include/libtorrent/aux_/disable_warnings_push.hpp index 7f4fbf0b4..b927ace61 100644 --- a/include/libtorrent/aux_/disable_warnings_push.hpp +++ b/include/libtorrent/aux_/disable_warnings_push.hpp @@ -67,6 +67,7 @@ POSSIBILITY OF SUCH DAMAGE. #pragma clang diagnostic ignored "-Wc++11-long-long" #pragma clang diagnostic ignored "-Wc++11-extensions" #pragma clang diagnostic ignored "-Wextra-semi" +#pragma clang diagnostic ignored "-Wunused-parameter" #endif #ifdef _MSC_VER diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 6347c055a..ea004600c 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -277,6 +277,7 @@ namespace libtorrent void apply_settings_pack(boost::shared_ptr pack); void apply_settings_pack_impl(settings_pack const& pack); session_settings const& settings() const { return m_settings; } + settings_pack get_settings() const; #ifndef TORRENT_DISABLE_DHT dht::dht_tracker* dht() { return m_dht.get(); } diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index d18be957a..c87c6fd5e 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -1011,7 +1011,7 @@ namespace libtorrent // asynchronous operation that will return immediately and actually apply // the settings to the main thread of libtorrent some time later. void apply_settings(settings_pack const& s); - aux::session_settings get_settings() const; + settings_pack get_settings() const; #ifndef TORRENT_NO_DEPRECATE // ``set_i2p_proxy`` sets the i2p_ proxy, and tries to open a persistant diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index cf359a073..b01671190 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/version.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/settings_pack.hpp" #include #include @@ -68,6 +69,7 @@ namespace libtorrent // construct the proxy_settings object from the settings // this constructor is implemented in session_impl.cpp + proxy_settings(settings_pack const& sett); proxy_settings(aux::session_settings const& sett); // the name or IP of the proxy server. ``port`` is the port number the diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 410b94577..f6680e7ee 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -78,7 +78,6 @@ namespace libtorrent // struct TORRENT_EXPORT settings_pack { - friend struct disk_io_thread; friend void apply_pack(settings_pack const* pack, aux::session_settings& sett, aux::session_impl* ses); void set_str(int name, std::string val); diff --git a/src/asio.cpp b/src/asio.cpp index 45418dbaa..67d3725ff 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -1,3 +1,5 @@ +#include "libtorrent/aux_/disable_warnings_push.hpp" + // builds all boost.asio source as a separate compilation unit #include #include @@ -14,8 +16,6 @@ #define BOOST_ASIO_DECL BOOST_SYMBOL_EXPORT #endif -#include "libtorrent/aux_/disable_warnings_push.hpp" - #if BOOST_VERSION >= 104500 #include diff --git a/src/session.cpp b/src/session.cpp index c0fcd7b52..328beba4b 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -932,7 +932,7 @@ namespace libtorrent pe_settings session::get_pe_settings() const { - aux::session_settings sett = get_settings(); + settings_pack sett = get_settings(); pe_settings r; r.prefer_rc4 = sett.get_bool(settings_pack::prefer_rc4); @@ -996,9 +996,9 @@ namespace libtorrent TORRENT_ASYNC_CALL1(apply_settings_pack, copy); } - aux::session_settings session::get_settings() const + settings_pack session::get_settings() const { - return TORRENT_SYNC_CALL_RET(aux::session_settings, settings); + return TORRENT_SYNC_CALL_RET(settings_pack, get_settings); } #ifndef TORRENT_NO_DEPRECATE @@ -1019,7 +1019,7 @@ namespace libtorrent proxy_settings session::proxy() const { - aux::session_settings sett = get_settings(); + settings_pack sett = get_settings(); return proxy_settings(sett); } @@ -1075,7 +1075,7 @@ namespace libtorrent proxy_settings session::i2p_proxy() const { proxy_settings ret; - aux::session_settings sett = get_settings(); + settings_pack sett = get_settings(); ret.hostname = sett.get_str(settings_pack::i2p_hostname); ret.port = sett.get_int(settings_pack::i2p_port); return ret; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 8f35ec301..3f0a642d4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -213,6 +213,18 @@ void network_thread_pool::process_job(socket_job const& j, bool post) } // TODO: 2 find a better place for this function +proxy_settings::proxy_settings(settings_pack const& sett) +{ + hostname = sett.get_str(settings_pack::proxy_hostname); + username = sett.get_str(settings_pack::proxy_username); + password = sett.get_str(settings_pack::proxy_password); + type = sett.get_int(settings_pack::proxy_type); + port = sett.get_int(settings_pack::proxy_port); + proxy_hostnames = sett.get_bool(settings_pack::proxy_hostnames); + proxy_peer_connections = sett.get_bool( + settings_pack::proxy_peer_connections); +} + proxy_settings::proxy_settings(aux::session_settings const& sett) { hostname = sett.get_str(settings_pack::proxy_hostname); @@ -1530,6 +1542,28 @@ namespace aux { apply_settings_pack_impl(*pack); } + settings_pack session_impl::get_settings() const + { + settings_pack ret; + // TODO: it would be nice to reserve() these vectors up front + for (int i = settings_pack::string_type_base; + i < settings_pack::max_string_setting_internal; ++i) + { + ret.set_str(i, m_settings.get_str(i)); + } + for (int i = settings_pack::int_type_base; + i < settings_pack::max_int_setting_internal; ++i) + { + ret.set_int(i, m_settings.get_int(i)); + } + for (int i = settings_pack::bool_type_base; + i < settings_pack::max_bool_setting_internal; ++i) + { + ret.set_bool(i, m_settings.get_bool(i)); + } + return ret; + } + void session_impl::apply_settings_pack_impl(settings_pack const& pack) { bool reopen_listen_port = diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 67a3f8fb0..1a8b1b457 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -59,6 +59,7 @@ namespace { } } +// TODO: 3 write a unit test for settings_pack namespace libtorrent { struct str_setting_entry_t @@ -680,6 +681,10 @@ namespace libtorrent { case string_type_base: { + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_strings.size() == settings_pack::num_string_settings) + return true; std::pair v(name, std::string()); std::vector >::const_iterator i = std::lower_bound(m_strings.begin(), m_strings.end(), v @@ -688,6 +693,10 @@ namespace libtorrent } case int_type_base: { + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_ints.size() == settings_pack::num_int_settings) + return true; std::pair v(name, 0); std::vector >::const_iterator i = std::lower_bound(m_ints.begin(), m_ints.end(), v @@ -696,6 +705,10 @@ namespace libtorrent } case bool_type_base: { + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_bools.size() == settings_pack::num_bool_settings) + return true; std::pair v(name, false); std::vector >::const_iterator i = std::lower_bound(m_bools.begin(), m_bools.end(), v @@ -712,6 +725,13 @@ namespace libtorrent TORRENT_ASSERT((name & type_mask) == string_type_base); if ((name & type_mask) != string_type_base) return std::string(); + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_strings.size() == settings_pack::num_string_settings) + { + TORRENT_ASSERT(m_strings[name].first == name); + return m_strings[name].second; + } std::pair v(name, std::string()); std::vector >::const_iterator i = std::lower_bound(m_strings.begin(), m_strings.end(), v @@ -725,6 +745,13 @@ namespace libtorrent TORRENT_ASSERT((name & type_mask) == int_type_base); if ((name & type_mask) != int_type_base) return 0; + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_ints.size() == settings_pack::num_int_settings) + { + TORRENT_ASSERT(m_ints[name].first == name); + return m_ints[name].second; + } std::pair v(name, 0); std::vector >::const_iterator i = std::lower_bound(m_ints.begin(), m_ints.end(), v @@ -738,6 +765,13 @@ namespace libtorrent TORRENT_ASSERT((name & type_mask) == bool_type_base); if ((name & type_mask) != bool_type_base) return false; + // this is an optimization. If the settings pack is complete, + // i.e. has every key, we don't need to search, it's just a lookup + if (m_bools.size() == settings_pack::num_bool_settings) + { + TORRENT_ASSERT(m_bools[name].first == name); + return m_bools[name].second; + } std::pair v(name, false); std::vector >::const_iterator i = std::lower_bound(m_bools.begin(), m_bools.end(), v