diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 65d1fda7b..a53936c29 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1752,7 +1752,7 @@ int main(int argc, char* argv[]) cache_size = (cache_size == 0) ? -1 : 0; settings_pack p; p.set_int(settings_pack::cache_size, cache_size); - ses.apply_settings(p); + ses.apply_settings(std::move(p)); } if (c == 'h') { diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index cc93b95f2..786dc572f 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -158,7 +158,7 @@ namespace libtorrent // nat-pmp) and default plugins (ut_metadata, ut_pex and smart_ban). The // default is to start those features. If you do not want them to start, // pass 0 as the flags parameter. - session(settings_pack const& pack = settings_pack() + session(settings_pack pack = settings_pack() , int flags = start_default_features | add_default_plugins) : session_handle(nullptr) { @@ -187,7 +187,7 @@ namespace libtorrent // call session::abort() and save the session_proxy first, then // destruct the session object, then sync with the io_service, then // destruct the session_proxy object. - session(settings_pack const& pack + session(settings_pack pack , io_service& ios , int flags = start_default_features | add_default_plugins) : session_handle(nullptr) @@ -215,7 +215,7 @@ namespace libtorrent pack.set_bool(settings_pack::enable_dht, false); } - start(flags, pack, nullptr); + start(flags, std::move(pack), nullptr); } TORRENT_DEPRECATED @@ -247,7 +247,7 @@ namespace libtorrent pack.set_bool(settings_pack::enable_lsd, false); pack.set_bool(settings_pack::enable_dht, false); } - start(flags, pack, nullptr); + start(flags, std::move(pack), nullptr); } #endif // TORRENT_NO_DEPRECATE @@ -281,7 +281,7 @@ namespace libtorrent private: - void start(int flags, settings_pack const& pack, io_service* ios); + void start(int flags, settings_pack pack, io_service* ios); // data shared between the main thread // and the working thread diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 92d5f4eb7..20576d38f 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -791,7 +791,7 @@ namespace libtorrent // Applies the settings specified by the settings_pack ``s``. This is an // 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); + void apply_settings(settings_pack s); settings_pack get_settings() const; #ifndef TORRENT_NO_DEPRECATE diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 2ab58804b..1ad29f5a1 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -85,6 +85,12 @@ namespace libtorrent { friend TORRENT_EXTRA_EXPORT void apply_pack(settings_pack const* pack, aux::session_settings& sett, aux::session_impl* ses); + settings_pack() = default; + settings_pack(settings_pack const&) = default; + settings_pack(settings_pack&&) = default; + settings_pack& operator=(settings_pack const&) = default; + settings_pack& operator=(settings_pack&&) = default; + void set_str(int name, std::string val); void set_int(int name, int val); void set_bool(int name, bool val); diff --git a/src/session.cpp b/src/session.cpp index cd3734b3d..6fb9edfae 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -322,7 +322,7 @@ namespace libtorrent // configurations this will give a link error void TORRENT_EXPORT TORRENT_CFG() {} - void session::start(int flags, settings_pack const& pack, io_service* ios) + void session::start(int flags, settings_pack pack, io_service* ios) { bool const internal_executor = ios == nullptr; @@ -347,7 +347,7 @@ namespace libtorrent TORRENT_UNUSED(flags); #endif - m_impl->start_session(pack); + m_impl->start_session(std::move(pack)); if (internal_executor) { diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 380e4b66e..5a786ed9e 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -436,14 +436,14 @@ namespace libtorrent { settings_pack p; p.set_bool(settings_pack::enable_dht, true); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::stop_dht() { settings_pack p; p.set_bool(settings_pack::enable_dht, false); - apply_settings(p); + apply_settings(std::move(p)); } #endif // TORRENT_NO_DEPRECATE @@ -700,7 +700,7 @@ namespace libtorrent { settings_pack p; p.set_str(settings_pack::peer_fingerprint, id.to_string()); - apply_settings(p); + apply_settings(std::move(p)); } #endif @@ -762,9 +762,9 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE void session_handle::use_interfaces(char const* interfaces) { - settings_pack pack; - pack.set_str(settings_pack::outgoing_interfaces, interfaces); - apply_settings(pack); + settings_pack p; + p.set_str(settings_pack::outgoing_interfaces, interfaces); + apply_settings(std::move(p)); } void session_handle::listen_on( @@ -783,7 +783,7 @@ namespace libtorrent p.set_str(settings_pack::listen_interfaces, interfaces_str); p.set_int(settings_pack::max_retry_port_bind, port_range.second - port_range.first); p.set_bool(settings_pack::listen_system_port_fallback, (flags & session::listen_no_system_port) == 0); - apply_settings(p); + apply_settings(std::move(p)); } #endif @@ -811,13 +811,13 @@ namespace libtorrent void session_handle::set_pe_settings(pe_settings const& r) { - settings_pack pack; - pack.set_bool(settings_pack::prefer_rc4, r.prefer_rc4); - pack.set_int(settings_pack::out_enc_policy, r.out_enc_policy); - pack.set_int(settings_pack::in_enc_policy, r.in_enc_policy); - pack.set_int(settings_pack::allowed_enc_level, r.allowed_enc_level); + settings_pack p; + p.set_bool(settings_pack::prefer_rc4, r.prefer_rc4); + p.set_int(settings_pack::out_enc_policy, r.out_enc_policy); + p.set_int(settings_pack::in_enc_policy, r.in_enc_policy); + p.set_int(settings_pack::allowed_enc_level, r.allowed_enc_level); - apply_settings(pack); + apply_settings(std::move(p)); } pe_settings session_handle::get_pe_settings() const @@ -833,7 +833,7 @@ namespace libtorrent } #endif - void session_handle::apply_settings(settings_pack const& s) + void session_handle::apply_settings(settings_pack s) { TORRENT_ASSERT_PRECOND(!s.has_val(settings_pack::out_enc_policy) || s.get_int(settings_pack::out_enc_policy) @@ -845,7 +845,7 @@ namespace libtorrent || s.get_int(settings_pack::allowed_enc_level) <= settings_pack::pe_both); - boost::shared_ptr copy = boost::make_shared(s); + boost::shared_ptr copy = boost::make_shared(std::move(s)); async_call(&session_impl::apply_settings_pack, copy); } @@ -875,16 +875,16 @@ namespace libtorrent void session_handle::set_proxy(proxy_settings const& s) { - settings_pack pack; - pack.set_str(settings_pack::proxy_hostname, s.hostname); - pack.set_str(settings_pack::proxy_username, s.username); - pack.set_str(settings_pack::proxy_password, s.password); - pack.set_int(settings_pack::proxy_type, s.type); - pack.set_int(settings_pack::proxy_port, s.port); - pack.set_bool(settings_pack::proxy_hostnames,s.proxy_hostnames); - pack.set_bool(settings_pack::proxy_peer_connections, s.proxy_peer_connections); + settings_pack p; + p.set_str(settings_pack::proxy_hostname, s.hostname); + p.set_str(settings_pack::proxy_username, s.username); + p.set_str(settings_pack::proxy_password, s.password); + p.set_int(settings_pack::proxy_type, s.type); + p.set_int(settings_pack::proxy_port, s.port); + p.set_bool(settings_pack::proxy_hostnames,s.proxy_hostnames); + p.set_bool(settings_pack::proxy_peer_connections, s.proxy_peer_connections); - apply_settings(pack); + apply_settings(std::move(p)); } proxy_settings session_handle::proxy() const @@ -1044,7 +1044,7 @@ namespace libtorrent settings_pack p; p.set_int(settings_pack::alert_mask, m); - apply_settings(p); + apply_settings(std::move(p)); } size_t session_handle::set_alert_queue_size_limit(size_t queue_size_limit_) @@ -1056,7 +1056,7 @@ namespace libtorrent { settings_pack p; p.set_int(settings_pack::alert_mask, m); - apply_settings(p); + apply_settings(std::move(p)); } std::uint32_t session_handle::get_alert_mask() const @@ -1068,42 +1068,42 @@ namespace libtorrent { settings_pack p; p.set_bool(settings_pack::enable_lsd, true); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::stop_lsd() { settings_pack p; p.set_bool(settings_pack::enable_lsd, false); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::start_upnp() { settings_pack p; p.set_bool(settings_pack::enable_upnp, true); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::stop_upnp() { settings_pack p; p.set_bool(settings_pack::enable_upnp, false); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::start_natpmp() { settings_pack p; p.set_bool(settings_pack::enable_natpmp, true); - apply_settings(p); + apply_settings(std::move(p)); } void session_handle::stop_natpmp() { settings_pack p; p.set_bool(settings_pack::enable_natpmp, false); - apply_settings(p); + apply_settings(std::move(p)); } #endif // TORRENT_NO_DEPRECATE