transition from intrusive_ptr to shared_ptr. don't export initialize_default_settings

This commit is contained in:
Arvid Norberg 2015-01-06 08:08:49 +00:00
parent 4b731b8ad7
commit 0f37e3403c
29 changed files with 124 additions and 157 deletions

View File

@ -60,6 +60,7 @@ set(sources
session
session_call
session_impl
session_settings
session_stats
settings_pack
socket_io

View File

@ -617,6 +617,7 @@ SOURCES =
session_stats
performance_counters
resolver
session_settings
# -- extensions --
metadata_transfer

View File

@ -63,7 +63,6 @@ nobase_include_HEADERS = \
i2p_stream.hpp \
identify_client.hpp \
instantiate_connection.hpp \
intrusive_ptr_base.hpp \
invariant_check.hpp \
io.hpp \
io_service.hpp \

View File

@ -1010,9 +1010,9 @@ namespace libtorrent
// this is deducted from the connect speed
int m_boost_connections;
boost::intrusive_ptr<natpmp> m_natpmp;
boost::intrusive_ptr<upnp> m_upnp;
boost::intrusive_ptr<lsd> m_lsd;
boost::shared_ptr<natpmp> m_natpmp;
boost::shared_ptr<upnp> m_upnp;
boost::shared_ptr<lsd> m_lsd;
// mask is a bitmask of which protocols to remap on:
// 1: NAT-PMP

View File

@ -40,6 +40,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
namespace libtorrent
{
TORRENT_EXTRA_EXPORT void initialize_default_settings(aux::session_settings& s);
}
namespace libtorrent { namespace aux
{
@ -65,12 +70,12 @@ namespace libtorrent { namespace aux
void set_bool(int name, bool value) { SET(bool); }
bool get_bool(int name) const { GET(bool, false); }
session_settings() { initialize_default_settings(*this); }
session_settings();
private:
std::string m_strings[settings_pack::num_string_settings];
int m_ints[settings_pack::num_int_settings];
// TODO: 2 make this a bitfield
// TODO: make this a bitfield
bool m_bools[settings_pack::num_bool_settings];
};

View File

@ -205,11 +205,6 @@ namespace libtorrent
// the pointers to the block data. If this is a ghost
// cache entry, there won't be any data here
// TODO: 3 could this be a scoped_array instead? does cached_piece_entry
// really need to be copyable? cached_piece_entry does need to be
// copyable since it's part of a container, but it's possible it could be
// a raw pointer or boost::unique_ptr perhaps
boost::shared_array<cached_block_entry> blocks;
// the last time a block was written to this piece

View File

@ -66,11 +66,11 @@ namespace libtorrent
class TORRENT_EXTRA_EXPORT broadcast_socket
{
public:
broadcast_socket(udp::endpoint const& multicast_endpoint
, receive_handler_t const& handler);
broadcast_socket(udp::endpoint const& multicast_endpoint);
~broadcast_socket() { close(); }
void open(io_service& ios, error_code& ec, bool loopback = true);
void open(receive_handler_t const& handler, io_service& ios
, error_code& ec, bool loopback = true);
enum flags_t { broadcast = 1 };
void send(char const* buffer, int size, error_code& ec, int flags = 0);

View File

@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include <boost/noncopyable.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
@ -51,7 +51,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/intrusive_ptr_base.hpp"
#ifdef TORRENT_WINDOWS
// windows part
@ -216,15 +215,15 @@ namespace libtorrent
char stack[2048];
private:
boost::intrusive_ptr<file> m_file;
boost::shared_ptr<file> m_file;
};
void TORRENT_EXTRA_EXPORT print_open_files(char const* event, char const* name);
#else
typedef boost::intrusive_ptr<file> file_handle;
typedef boost::shared_ptr<file> file_handle;
#endif
struct TORRENT_EXTRA_EXPORT file: boost::noncopyable, intrusive_ptr_base<file>
struct TORRENT_EXTRA_EXPORT file: boost::noncopyable
{
// the open mode for files. Used for the file constructor or
// file::open().

View File

@ -36,12 +36,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/intrusive_ptr_base.hpp"
#include "libtorrent/deadline_timer.hpp"
#include <boost/function/function2.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#if defined TORRENT_LOGGING
#include <stdio.h>
@ -52,19 +52,21 @@ namespace libtorrent
typedef boost::function<void(tcp::endpoint, sha1_hash)> peer_callback_t;
class lsd : public intrusive_ptr_base<lsd>
class lsd : public boost::enable_shared_from_this<lsd>
{
public:
lsd(io_service& ios, peer_callback_t const& cb);
~lsd();
// void rebind(address const& listen_interface);
void start();
void announce(sha1_hash const& ih, int listen_port, bool broadcast = false);
void close();
private:
boost::shared_ptr<lsd> self() { return shared_from_this(); }
void announce_impl(sha1_hash const& ih, int listen_port
, bool broadcast, int retry_count);
void resend_announce(error_code const& e, sha1_hash const& ih

View File

@ -38,11 +38,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/address.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/intrusive_ptr_base.hpp"
#include "libtorrent/deadline_timer.hpp"
#include <boost/function/function1.hpp>
#include <boost/function/function4.hpp>
#include <boost/enable_shared_from_this.hpp>
namespace libtorrent
{
@ -53,14 +53,13 @@ namespace libtorrent
typedef boost::function<void(int, address, int, error_code const&)> portmap_callback_t;
typedef boost::function<void(char const*)> log_callback_t;
class natpmp : public intrusive_ptr_base<natpmp>
class natpmp : public boost::enable_shared_from_this<natpmp>
{
public:
natpmp(io_service& ios, address const& listen_interface
, portmap_callback_t const& cb
natpmp(io_service& ios, portmap_callback_t const& cb
, log_callback_t const& lcb);
void rebind(address const& listen_interface);
void start();
// maps the ports, if a port is set to 0
// it will not be mapped
@ -73,6 +72,8 @@ public:
private:
boost::shared_ptr<natpmp> self() { return shared_from_this(); }
void update_mapping(int i, mutex::scoped_lock& l);
void send_map_request(int i, mutex::scoped_lock& l);
void send_get_ip_address_request(mutex::scoped_lock& l);

View File

@ -33,13 +33,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_PEER_CLASS_HPP_INCLUDED
#define TORRENT_PEER_CLASS_HPP_INCLUDED
#include "libtorrent/intrusive_ptr_base.hpp"
#include "libtorrent/bandwidth_limit.hpp"
#include "libtorrent/assert.hpp"
#include <vector>
#include <string>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/cstdint.hpp>
namespace libtorrent
@ -83,7 +82,7 @@ namespace libtorrent
int download_priority;
};
struct TORRENT_EXTRA_EXPORT peer_class : intrusive_ptr_base<peer_class>
struct TORRENT_EXTRA_EXPORT peer_class : boost::enable_shared_from_this<peer_class>
{
friend struct peer_class_pool;
@ -136,7 +135,7 @@ namespace libtorrent
// state for peer classes (a peer can belong to multiple classes)
// this can control
std::vector<boost::intrusive_ptr<peer_class> > m_peer_classes;
std::vector<boost::shared_ptr<peer_class> > m_peer_classes;
// indices in m_peer_classes that are no longer used
std::vector<peer_class_t> m_free_list;

View File

@ -48,7 +48,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/array.hpp>
#include <boost/optional.hpp>

View File

@ -55,7 +55,6 @@ namespace libtorrent
TORRENT_EXTRA_EXPORT settings_pack* load_pack_from_dict(lazy_entry const* settings);
TORRENT_EXTRA_EXPORT void save_settings_to_dict(aux::session_settings const& s, entry::dictionary_type& sett);
TORRENT_EXPORT void initialize_default_settings(aux::session_settings& s);
TORRENT_EXTRA_EXPORT void apply_pack(settings_pack const* pack, aux::session_settings& sett, aux::session_impl* ses = 0);
TORRENT_EXPORT int setting_by_name(std::string const& name);

View File

@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/unordered_set.hpp>
#include <boost/atomic.hpp>

View File

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/error_code.hpp"
#include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/http_connection.hpp"
#include "libtorrent/intrusive_ptr_base.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/deadline_timer.hpp"
#include "libtorrent/enum_net.hpp"
@ -47,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/function/function4.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <set>
namespace libtorrent
@ -106,15 +106,17 @@ typedef boost::function<void(int, address, int, error_code const&)> portmap_call
typedef boost::function<void(char const*)> log_callback_t;
// TODO: support using the windows API for UPnP operations as well
class TORRENT_EXTRA_EXPORT upnp : public intrusive_ptr_base<upnp>
class TORRENT_EXTRA_EXPORT upnp : public boost::enable_shared_from_this<upnp>
{
public:
upnp(io_service& ios
, address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb, log_callback_t const& lcb
, bool ignore_nonrouters, void* state = 0);
, bool ignore_nonrouters);
~upnp();
void start(void* state = 0);
void* drain_state();
enum protocol_type { none = 0, udp = 1, tcp = 2 };
@ -157,6 +159,8 @@ public:
private:
boost::shared_ptr<upnp> self() { return shared_from_this(); }
void map_timer(error_code const& ec);
void try_map_upnp(mutex::scoped_lock& l, bool timer = false);
void discover_device_impl(mutex::scoped_lock& l);

View File

@ -104,6 +104,7 @@ libtorrent_rasterbar_la_SOURCES = \
session.cpp \
session_call.cpp \
session_impl.cpp \
session_settings.cpp \
settings_pack.cpp \
sha1.cpp \
smart_ban.cpp \

View File

@ -226,10 +226,8 @@ namespace libtorrent
}
broadcast_socket::broadcast_socket(
udp::endpoint const& multicast_endpoint
, receive_handler_t const& handler)
udp::endpoint const& multicast_endpoint)
: m_multicast_endpoint(multicast_endpoint)
, m_on_receive(handler)
, m_outstanding_operations(0)
, m_abort(false)
{
@ -238,8 +236,11 @@ namespace libtorrent
using namespace asio::ip::multicast;
}
void broadcast_socket::open(io_service& ios, error_code& ec, bool loopback)
void broadcast_socket::open(receive_handler_t const& handler
, io_service& ios, error_code& ec, bool loopback)
{
m_on_receive = handler;
std::vector<ip_interface> interfaces = enum_net_interfaces(ios, ec);
#if TORRENT_USE_IPV6
@ -279,11 +280,11 @@ namespace libtorrent
#endif
open_multicast_socket(ios, i->interface_address, loopback, ec);
#ifdef TORRENT_DEBUG
// fprintf(stderr, "broadcast socket [ if: %s group: %s mask: %s ] %s\n"
// , i->interface_address.to_string().c_str()
// , m_multicast_endpoint.address().to_string().c_str()
// , i->netmask.to_string().c_str()
// , ec.message().c_str());
fprintf(stderr, "broadcast socket [ if: %s group: %s mask: %s ] %s\n"
, i->interface_address.to_string().c_str()
, m_multicast_endpoint.address().to_string().c_str()
, i->netmask.to_string().c_str()
, ec.message().c_str());
#endif
open_unicast_socket(ios, i->interface_address
, i->netmask.is_v4() ? i->netmask.to_v4() : address_v4());

View File

@ -163,7 +163,7 @@ namespace libtorrent
// be outstanding operations on it, we can't close the
// file, we can only delete our reference to it.
// if this is the only reference to the file, it will be closed
e.file_ptr.reset(new (std::nothrow)file);
e.file_ptr = boost::make_shared<file>();
std::string full_path = fs.file_path(file_index, p);
if (!e.file_ptr->open(full_path, m, ec))
@ -183,7 +183,7 @@ namespace libtorrent
}
lru_file_entry e;
e.file_ptr.reset(new (std::nothrow)file);
e.file_ptr = boost::make_shared<file>();
if (!e.file_ptr)
{
ec = error_code(ENOMEM, get_posix_category());
@ -307,7 +307,7 @@ namespace libtorrent
for (file_set::const_iterator i = m_files.begin();
i != m_files.end(); ++i)
{
if (i->second.key == st && i->second.file_ptr->refcount() > 1)
if (i->second.key == st && !i->second.file_ptr.unique())
return false;
}
return true;

View File

@ -67,11 +67,9 @@ static error_code ec;
lsd::lsd(io_service& ios, peer_callback_t const& cb)
: m_callback(cb)
, m_socket(udp::endpoint(address_v4::from_string("239.192.152.143", ec), 6771)
, boost::bind(&lsd::on_announce, self(), _1, _2, _3))
, m_socket(udp::endpoint(address_v4::from_string("239.192.152.143", ec), 6771))
#if TORRENT_USE_IPV6
, m_socket6(udp::endpoint(address_v6::from_string("ff15::efc0:988f", ec), 6771)
, boost::bind(&lsd::on_announce, self(), _1, _2, _3))
, m_socket6(udp::endpoint(address_v6::from_string("ff15::efc0:988f", ec), 6771))
#endif
, m_broadcast_timer(ios)
, m_cookie(random())
@ -79,9 +77,16 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb)
#if TORRENT_USE_IPV6
, m_disabled6(false)
#endif
#if defined TORRENT_LOGGING
, m_log(NULL)
#endif
{
}
void lsd::start()
{
#if defined TORRENT_LOGGING
// TODO: instead if writing to a file, post alerts. Or call a log callback
// TODO: 3 instead if writing to a file, post alerts. Or call a log callback
m_log = fopen("lsd.log", "w+");
if (m_log == NULL)
{
@ -91,7 +96,8 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb)
#endif
error_code ec;
m_socket.open(ios, ec);
m_socket.open(boost::bind(&lsd::on_announce, self(), _1, _2, _3)
, m_broadcast_timer.get_io_service(), ec);
#if defined TORRENT_LOGGING
if (ec)
@ -102,7 +108,8 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb)
#endif
#if TORRENT_USE_IPV6
m_socket6.open(ios, ec);
m_socket6.open(boost::bind(&lsd::on_announce, self(), _1, _2, _3)
, m_broadcast_timer.get_io_service(), ec);
#if defined TORRENT_LOGGING
if (ec)
{

View File

@ -63,7 +63,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
natpmp::natpmp(io_service& ios, address const& listen_interface
natpmp::natpmp(io_service& ios
, portmap_callback_t const& cb, log_callback_t const& lcb)
: m_callback(cb)
, m_log_callback(lcb)
@ -80,10 +80,9 @@ natpmp::natpmp(io_service& ios, address const& listen_interface
// for this array not to be reallocated, by passing
// around pointers to its elements. so reserve size for now
m_mappings.reserve(10);
rebind(listen_interface);
}
void natpmp::rebind(address const& listen_interface)
void natpmp::start()
{
mutex::scoped_lock l(m_mutex);

View File

@ -88,11 +88,11 @@ namespace libtorrent
else
{
ret = m_peer_classes.size();
m_peer_classes.push_back(boost::intrusive_ptr<peer_class>());
m_peer_classes.push_back(boost::shared_ptr<peer_class>());
}
TORRENT_ASSERT(m_peer_classes[ret].get() == 0);
m_peer_classes[ret] = new peer_class(label);
m_peer_classes[ret] = boost::make_shared<peer_class>(label);
return ret;
}

View File

@ -3163,7 +3163,7 @@ namespace libtorrent
i->locked = true;
}
// TODO: 3 it would be nice if this could be folded into lock_piece()
// TODO: 2 it would be nice if this could be folded into lock_piece()
// the main distinction is that this also maintains the m_num_passed
// counter and the passed_hash_check member
void piece_picker::write_failed(piece_block block)

View File

@ -1989,7 +1989,7 @@ retry:
void session_impl::remap_tcp_ports(boost::uint32_t mask, int tcp_port, int ssl_port)
{
if ((mask & 1) && m_natpmp.get())
if ((mask & 1) && m_natpmp)
{
if (m_tcp_mapping[0] != -1) m_natpmp->delete_mapping(m_tcp_mapping[0]);
m_tcp_mapping[0] = m_natpmp->add_mapping(natpmp::tcp, tcp_port, tcp_port);
@ -1999,7 +1999,7 @@ retry:
, ssl_port, ssl_port);
#endif
}
if ((mask & 2) && m_upnp.get())
if ((mask & 2) && m_upnp)
{
if (m_tcp_mapping[1] != -1) m_upnp->delete_mapping(m_tcp_mapping[1]);
m_tcp_mapping[1] = m_upnp->add_mapping(upnp::tcp, tcp_port, tcp_port);
@ -2841,7 +2841,8 @@ retry:
if (now - m_last_second_tick < seconds(1)) return;
#ifndef TORRENT_DISABLE_DHT
if (m_dht_interval_update_torrents < 40
if (m_dht
&& m_dht_interval_update_torrents < 40
&& m_dht_interval_update_torrents != int(m_torrents.size()))
update_dht_announce_interval();
#endif
@ -5135,7 +5136,7 @@ retry:
void session_impl::announce_lsd(sha1_hash const& ih, int port, bool broadcast)
{
// use internal listen port for local peers
if (m_lsd.get())
if (m_lsd)
m_lsd->announce(ih, port, broadcast);
}
@ -5514,7 +5515,7 @@ retry:
void session_impl::maybe_update_udp_mapping(int nat, int local_port, int external_port)
{
int local, external, protocol;
if (nat == 0 && m_natpmp.get())
if (nat == 0 && m_natpmp)
{
if (m_udp_mapping[nat] != -1)
{
@ -5530,7 +5531,7 @@ retry:
, local_port, external_port);
return;
}
else if (nat == 1 && m_upnp.get())
else if (nat == 1 && m_upnp)
{
if (m_udp_mapping[nat] != -1)
{
@ -6206,7 +6207,7 @@ retry:
if (m_lsd) return;
m_lsd = new lsd(m_io_service
m_lsd = boost::make_shared<lsd>(m_io_service
, boost::bind(&session_impl::on_lsd_peer, this, _1, _2));
}
@ -6218,15 +6219,12 @@ retry:
// the natpmp constructor may fail and call the callbacks
// into the session_impl.
natpmp* n = new (std::nothrow) natpmp(m_io_service
, m_listen_interface.address()
m_natpmp = boost::make_shared<natpmp>(m_io_service
, boost::bind(&session_impl::on_port_mapping
, this, _1, _2, _3, _4, 0)
, boost::bind(&session_impl::on_port_map_log
, this, _1, 0));
if (n == 0) return 0;
m_natpmp = n;
m_natpmp->start();
int ssl_port = ssl_listen_port();
@ -6246,7 +6244,7 @@ retry:
, ssl_port, ssl_port);
}
#endif
return n;
return m_natpmp.get();
}
upnp* session_impl::start_upnp()
@ -6256,7 +6254,7 @@ retry:
if (m_upnp) return m_upnp.get();
// the upnp constructor may fail and call the callbacks
upnp* u = new (std::nothrow) upnp(m_io_service
m_upnp = boost::make_shared<upnp>(m_io_service
, m_listen_interface.address()
, m_settings.get_str(settings_pack::user_agent)
, boost::bind(&session_impl::on_port_mapping
@ -6264,10 +6262,7 @@ retry:
, boost::bind(&session_impl::on_port_map_log
, this, _1, 1)
, m_settings.get_bool(settings_pack::upnp_ignore_nonrouters));
if (u == 0) return 0;
m_upnp = u;
m_upnp->start();
int ssl_port = ssl_listen_port();
@ -6288,7 +6283,7 @@ retry:
, ssl_port, ssl_port);
}
#endif
return u;
return m_upnp.get();
}
int session_impl::add_port_mapping(int t, int external_port
@ -6310,14 +6305,14 @@ retry:
void session_impl::stop_lsd()
{
if (m_lsd.get())
if (m_lsd)
m_lsd->close();
m_lsd = 0;
m_lsd.reset();
}
void session_impl::stop_natpmp()
{
if (m_natpmp.get())
if (m_natpmp)
{
m_natpmp->close();
m_udp_mapping[0] = -1;
@ -6327,12 +6322,12 @@ retry:
m_ssl_udp_mapping[0] = -1;
#endif
}
m_natpmp = 0;
m_natpmp.reset();
}
void session_impl::stop_upnp()
{
if (m_upnp.get())
if (m_upnp)
{
m_upnp->close();
m_udp_mapping[1] = -1;
@ -6342,7 +6337,7 @@ retry:
m_ssl_udp_mapping[1] = -1;
#endif
}
m_upnp = 0;
m_upnp.reset();
}
external_ip const& session_impl::external_address() const

View File

@ -1,6 +1,6 @@
/*
Copyright (c) 2007-2014, Arvid Norberg
Copyright (c) 2015, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -30,57 +30,13 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_INTRUSIVE_PTR_BASE
#define TORRENT_INTRUSIVE_PTR_BASE
#include "libtorrent/aux_/session_settings.hpp"
#include <boost/checked_delete.hpp>
#include <boost/intrusive_ptr.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include <boost/atomic.hpp>
namespace libtorrent
namespace libtorrent { namespace aux
{
// TODO: 2 remove this class and transition over to using shared_ptr and
// make_shared instead
template<class T>
struct intrusive_ptr_base
session_settings::session_settings()
{
intrusive_ptr_base(intrusive_ptr_base<T> const&)
: m_refs(0) {}
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)
{
TORRENT_ASSERT(s != 0);
TORRENT_ASSERT(s->m_refs >= 0);
++s->m_refs;
}
friend void intrusive_ptr_release(intrusive_ptr_base<T> const* s)
{
TORRENT_ASSERT(s != 0);
TORRENT_ASSERT(s->m_refs > 0);
if (--s->m_refs == 0)
boost::checked_delete(static_cast<T const*>(s));
}
boost::intrusive_ptr<T> self()
{ return boost::intrusive_ptr<T>((T*)this); }
boost::intrusive_ptr<const T> self() const
{ return boost::intrusive_ptr<const T>((T const*)this); }
int refcount() const { return m_refs; }
intrusive_ptr_base(): m_refs(0) {}
private:
// reference counter for intrusive_ptr
mutable boost::atomic<int> m_refs;
};
}
#endif
initialize_default_settings(*this);
}
} }

View File

@ -7710,7 +7710,7 @@ namespace libtorrent
// if it's lower rank than the incoming connection
peer_connection* peer = find_lowest_ranking_peer();
// TODO: 3 if peer is a really good peer, maybe we shouldn't disconnect it
// TODO: 2 if peer is a really good peer, maybe we shouldn't disconnect it
if (peer && peer->peer_rank() < p->peer_rank())
{
peer->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);

View File

@ -72,15 +72,14 @@ static error_code ec;
upnp::upnp(io_service& ios
, address const& listen_interface, std::string const& user_agent
, portmap_callback_t const& cb, log_callback_t const& lcb
, bool ignore_nonrouters, void* state)
, bool ignore_nonrouters)
: m_user_agent(user_agent)
, m_callback(cb)
, m_log_callback(lcb)
, m_retry_count(0)
, m_io_service(ios)
, m_resolver(ios)
, m_socket(udp::endpoint(address_v4::from_string("239.255.255.250", ec), 1900)
, boost::bind(&upnp::on_reply, self(), _1, _2, _3))
, m_socket(udp::endpoint(address_v4::from_string("239.255.255.250", ec), 1900))
, m_broadcast_timer(ios)
, m_refresh_timer(ios)
, m_map_timer(ios)
@ -90,9 +89,13 @@ upnp::upnp(io_service& ios
, m_last_if_update(min_time())
{
TORRENT_ASSERT(cb);
}
void upnp::start(void* state)
{
error_code ec;
m_socket.open(ios, ec);
m_socket.open(boost::bind(&upnp::on_reply, self(), _1, _2, _3)
, m_refresh_timer.get_io_service(), ec);
if (state)
{
@ -275,7 +278,7 @@ void upnp::resend_request(error_code const& ec)
#endif
if (ec) return;
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);
@ -330,7 +333,7 @@ void upnp::resend_request(error_code const& ec)
void upnp::on_reply(udp::endpoint const& from, char* buffer
, std::size_t bytes_transferred)
{
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);
@ -742,7 +745,7 @@ void upnp::update_map(rootdevice& d, int i, mutex::scoped_lock& l)
if (d.upnp_connection) return;
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mapping_t& m = d.mapping[i];
@ -920,7 +923,7 @@ void upnp::on_upnp_xml(error_code const& e
, libtorrent::http_parser const& p, rootdevice& d
, http_connection& c)
{
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);
@ -1227,7 +1230,7 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e
, libtorrent::http_parser const& p, rootdevice& d
, http_connection& c)
{
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);
@ -1307,7 +1310,7 @@ void upnp::on_upnp_map_response(error_code const& e
, libtorrent::http_parser const& p, rootdevice& d, int mapping
, http_connection& c)
{
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);
@ -1475,7 +1478,7 @@ void upnp::on_upnp_unmap_response(error_code const& e
, libtorrent::http_parser const& p, rootdevice& d, int mapping
, http_connection& c)
{
boost::intrusive_ptr<upnp> me(self());
boost::shared_ptr<upnp> me(self());
mutex::scoped_lock l(m_mutex);

View File

@ -433,7 +433,7 @@ bool get_item_cb(dht::item& i)
return false;
}
// TODO: 3 test obfuscated_get_peers
// TODO: 2 test obfuscated_get_peers
int test_main()
{
dht_settings sett;

View File

@ -285,7 +285,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
// us catch all events that failed (and would put the torrent
// back into upload mode) before we restart it.
// TODO: 3 factor out the disk-full test into its own unit test
// TODO: 2 factor out the disk-full test into its own unit test
if (test_disk_full && st2.upload_mode && ++upload_mode_timer > 10)
{
test_disk_full = false;

View File

@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <fstream>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr.hpp>
#include <iostream>
using namespace libtorrent;
@ -144,15 +144,17 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
xml.write(soap_add_response, sizeof(soap_add_response)-1);
xml.close();
sock = new broadcast_socket(udp::endpoint(address_v4::from_string("239.255.255.250"), 1900)
, &incoming_msearch);
sock = new broadcast_socket(udp::endpoint(address_v4::from_string("239.255.255.250")
, 1900));
sock->open(ios, ec);
sock->open(&incoming_msearch, ios, ec);
std::string user_agent = "test agent";
boost::intrusive_ptr<upnp> upnp_handler = new upnp(ios, address_v4::from_string("127.0.0.1")
boost::shared_ptr<upnp> upnp_handler = boost::make_shared<upnp>(ios
, address_v4::from_string("127.0.0.1")
, user_agent, &callback, &log_callback, false);
upnp_handler->start();
upnp_handler->discover_device();
for (int i = 0; i < 20; ++i)