forked from premiere/premiere-libtorrent
use a unique_ptr for the udp_socket receive buffer
This commit is contained in:
parent
bca41a681f
commit
0682e6146c
|
@ -51,7 +51,6 @@ namespace libtorrent
|
|||
{
|
||||
public:
|
||||
udp_socket(io_service& ios);
|
||||
~udp_socket();
|
||||
|
||||
enum flags_t {
|
||||
peer_connection = 1
|
||||
|
@ -135,10 +134,8 @@ namespace libtorrent
|
|||
|
||||
udp::socket m_socket;
|
||||
|
||||
// TODO: 2 this should probably be a scoped_ptr<> or unique_ptr
|
||||
// with a hard coded size
|
||||
int const m_buf_size;
|
||||
char* m_buf;
|
||||
using receive_buffer = std::array<char, 1500>;
|
||||
std::unique_ptr<receive_buffer> m_buf;
|
||||
|
||||
boost::uint16_t m_bind_port;
|
||||
|
||||
|
|
|
@ -162,19 +162,11 @@ struct set_dont_frag
|
|||
|
||||
udp_socket::udp_socket(io_service& ios)
|
||||
: m_socket(ios)
|
||||
, m_buf_size(1500)
|
||||
, m_buf(NULL)
|
||||
, m_buf(new receive_buffer())
|
||||
, m_bind_port(0)
|
||||
, m_force_proxy(false)
|
||||
, 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)
|
||||
{
|
||||
|
@ -184,7 +176,7 @@ int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
|||
|
||||
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);
|
||||
|
||||
if (ec == error::would_block
|
||||
|
@ -214,7 +206,7 @@ int udp_socket::read(array_view<packet> pkts, error_code& ec)
|
|||
}
|
||||
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
|
||||
if (m_socks5_connection && m_socks5_connection->active())
|
||||
|
|
Loading…
Reference in New Issue