Merge pull request #675 from ssiloti/unique_ptr
Use unique_ptr where possible
This commit is contained in:
commit
a3de04dffc
|
@ -166,7 +166,8 @@ namespace libtorrent
|
||||||
// the actual sockets (TCP listen socket and UDP socket)
|
// the actual sockets (TCP listen socket and UDP socket)
|
||||||
// An entry does not necessarily have a UDP or TCP socket. One of these
|
// An entry does not necessarily have a UDP or TCP socket. One of these
|
||||||
// pointers may be null!
|
// pointers may be null!
|
||||||
// TODO: 3 make these unique_ptr<>
|
// These must be shared_ptr to avoid a dangling reference if an
|
||||||
|
// incoming packet is in the event queue when the socket is erased
|
||||||
boost::shared_ptr<tcp::acceptor> sock;
|
boost::shared_ptr<tcp::acceptor> sock;
|
||||||
boost::shared_ptr<udp_socket> udp_sock;
|
boost::shared_ptr<udp_socket> udp_sock;
|
||||||
};
|
};
|
||||||
|
@ -759,7 +760,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// a thread pool used for async_write_some calls,
|
// a thread pool used for async_write_some calls,
|
||||||
// to distribute its cost to multiple threads
|
// to distribute its cost to multiple threads
|
||||||
std::vector<boost::shared_ptr<network_thread_pool> > m_net_thread_pool;
|
std::vector<std::unique_ptr<network_thread_pool>> m_net_thread_pool;
|
||||||
|
|
||||||
// the bandwidth manager is responsible for
|
// the bandwidth manager is responsible for
|
||||||
// handing out bandwidth to connections that
|
// handing out bandwidth to connections that
|
||||||
|
|
|
@ -77,8 +77,8 @@ namespace libtorrent { namespace aux
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT((name & settings_pack::type_mask) == type);
|
TORRENT_ASSERT((name & settings_pack::type_mask) == type);
|
||||||
if ((name & settings_pack::type_mask) != type) return;
|
if ((name & settings_pack::type_mask) != type) return;
|
||||||
int const index = name & settings_pack::index_mask;
|
size_t const index = name & settings_pack::index_mask;
|
||||||
TORRENT_ASSERT(index >= 0 && index < N);
|
TORRENT_ASSERT(index < N);
|
||||||
arr[index] = val;
|
arr[index] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ namespace libtorrent { namespace aux
|
||||||
static T empty;
|
static T empty;
|
||||||
TORRENT_ASSERT((name & settings_pack::type_mask) == type);
|
TORRENT_ASSERT((name & settings_pack::type_mask) == type);
|
||||||
if ((name & settings_pack::type_mask) != type) return empty;
|
if ((name & settings_pack::type_mask) != type) return empty;
|
||||||
int const index = name & settings_pack::index_mask;
|
size_t const index = name & settings_pack::index_mask;
|
||||||
TORRENT_ASSERT(index >= 0 && index < N);
|
TORRENT_ASSERT(index < N);
|
||||||
return arr[index];
|
return arr[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,7 +401,8 @@ namespace libtorrent
|
||||||
mutable std::mutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
|
|
||||||
// maps transactionid to the udp_tracker_connection
|
// maps transactionid to the udp_tracker_connection
|
||||||
// TODO: this should be unique_ptr in the future
|
// These must use shared_ptr to avoid a dangling reference
|
||||||
|
// if a connection is erased while a timeout event is in the queue
|
||||||
typedef boost::unordered_map<boost::uint32_t
|
typedef boost::unordered_map<boost::uint32_t
|
||||||
, boost::shared_ptr<udp_tracker_connection> > udp_conns_t;
|
, boost::shared_ptr<udp_tracker_connection> > udp_conns_t;
|
||||||
udp_conns_t m_udp_conns;
|
udp_conns_t m_udp_conns;
|
||||||
|
|
|
@ -51,7 +51,6 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
udp_socket(io_service& ios);
|
udp_socket(io_service& ios);
|
||||||
~udp_socket();
|
|
||||||
|
|
||||||
enum flags_t {
|
enum flags_t {
|
||||||
peer_connection = 1
|
peer_connection = 1
|
||||||
|
@ -135,10 +134,8 @@ namespace libtorrent
|
||||||
|
|
||||||
udp::socket m_socket;
|
udp::socket m_socket;
|
||||||
|
|
||||||
// TODO: 2 this should probably be a scoped_ptr<> or unique_ptr
|
using receive_buffer = std::array<char, 1500>;
|
||||||
// with a hard coded size
|
std::unique_ptr<receive_buffer> m_buf;
|
||||||
int const m_buf_size;
|
|
||||||
char* m_buf;
|
|
||||||
|
|
||||||
boost::uint16_t m_bind_port;
|
boost::uint16_t m_bind_port;
|
||||||
|
|
||||||
|
|
|
@ -6083,7 +6083,7 @@ namespace aux {
|
||||||
int num_pools = num_threads > 0 ? num_threads : 1;
|
int num_pools = num_threads > 0 ? num_threads : 1;
|
||||||
while (num_pools > m_net_thread_pool.size())
|
while (num_pools > m_net_thread_pool.size())
|
||||||
{
|
{
|
||||||
m_net_thread_pool.push_back(boost::make_shared<network_thread_pool>());
|
m_net_thread_pool.emplace_back(new network_thread_pool());
|
||||||
m_net_thread_pool.back()->set_num_threads(num_threads > 0 ? 1 : 0);
|
m_net_thread_pool.back()->set_num_threads(num_threads > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,19 +162,11 @@ struct set_dont_frag
|
||||||
|
|
||||||
udp_socket::udp_socket(io_service& ios)
|
udp_socket::udp_socket(io_service& ios)
|
||||||
: m_socket(ios)
|
: m_socket(ios)
|
||||||
, m_buf_size(1500)
|
, m_buf(new receive_buffer())
|
||||||
, m_buf(NULL)
|
|
||||||
, m_bind_port(0)
|
, m_bind_port(0)
|
||||||
, m_force_proxy(false)
|
, m_force_proxy(false)
|
||||||
, m_abort(true)
|
, m_abort(true)
|
||||||
{
|
{}
|
||||||
m_buf = static_cast<char*>(malloc(m_buf_size));
|
|
||||||
}
|
|
||||||
|
|
||||||
udp_socket::~udp_socket()
|
|
||||||
{
|
|
||||||
free(m_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
||||||
{
|
{
|
||||||
|
@ -184,7 +176,7 @@ int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
||||||
|
|
||||||
while (ret < num)
|
while (ret < num)
|
||||||
{
|
{
|
||||||
int const len = m_socket.receive_from(boost::asio::buffer(m_buf, m_buf_size)
|
int const len = m_socket.receive_from(boost::asio::buffer(*m_buf)
|
||||||
, p.from, 0, ec);
|
, p.from, 0, ec);
|
||||||
|
|
||||||
if (ec == error::would_block
|
if (ec == error::would_block
|
||||||
|
@ -214,7 +206,7 @@ int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p.data = array_view<char>(m_buf, len);
|
p.data = array_view<char>(m_buf->data(), len);
|
||||||
|
|
||||||
// support packets coming from the SOCKS5 proxy
|
// support packets coming from the SOCKS5 proxy
|
||||||
if (m_socks5_connection && m_socks5_connection->active())
|
if (m_socks5_connection && m_socks5_connection->active())
|
||||||
|
|
Loading…
Reference in New Issue