don't return an internal session_settings type from the session, return a settings_pack instead
This commit is contained in:
parent
a3d397e194
commit
aa6598b2e6
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -277,6 +277,7 @@ namespace libtorrent
|
|||
void apply_settings_pack(boost::shared_ptr<settings_pack> 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(); }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "libtorrent/version.hpp"
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/settings_pack.hpp"
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <string>
|
||||
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
// builds all boost.asio source as a separate compilation unit
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/preprocessor/facilities/is_empty.hpp>
|
||||
|
@ -14,8 +16,6 @@
|
|||
#define BOOST_ASIO_DECL BOOST_SYMBOL_EXPORT
|
||||
#endif
|
||||
|
||||
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
||||
|
||||
#if BOOST_VERSION >= 104500
|
||||
|
||||
#include <boost/asio/impl/src.hpp>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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<boost::uint16_t, std::string> v(name, std::string());
|
||||
std::vector<std::pair<boost::uint16_t, std::string> >::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<boost::uint16_t, int> v(name, 0);
|
||||
std::vector<std::pair<boost::uint16_t, int> >::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<boost::uint16_t, bool> v(name, false);
|
||||
std::vector<std::pair<boost::uint16_t, bool> >::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<boost::uint16_t, std::string> v(name, std::string());
|
||||
std::vector<std::pair<boost::uint16_t, std::string> >::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<boost::uint16_t, int> v(name, 0);
|
||||
std::vector<std::pair<boost::uint16_t, int> >::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<boost::uint16_t, bool> v(name, false);
|
||||
std::vector<std::pair<boost::uint16_t, bool> >::const_iterator i
|
||||
= std::lower_bound(m_bools.begin(), m_bools.end(), v
|
||||
|
|
Loading…
Reference in New Issue