another udp_socket buffer allocation fix

This commit is contained in:
Arvid Norberg 2011-02-08 17:17:07 +00:00
parent c8edb67509
commit cfd36ca53e
1 changed files with 4 additions and 4 deletions

View File

@ -201,7 +201,7 @@ void udp_socket::maybe_realloc_buffers(int which)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
bool no_mem = false; bool no_mem = false;
if (m_reallocate_buffer4 && (which & 1)) if (m_reallocate_buffer4 && (which & 1) && m_v4_outstanding == 0)
{ {
TORRENT_ASSERT(m_v4_outstanding == 0); TORRENT_ASSERT(m_v4_outstanding == 0);
void* tmp = realloc(m_v4_buf, m_v4_buf_size); void* tmp = realloc(m_v4_buf, m_v4_buf_size);
@ -210,7 +210,7 @@ void udp_socket::maybe_realloc_buffers(int which)
m_reallocate_buffer4 = false; m_reallocate_buffer4 = false;
} }
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (m_reallocate_buffer6 && (which & 2)) if (m_reallocate_buffer6 && (which & 2) && m_v6_outstanding == 0)
{ {
TORRENT_ASSERT(m_v6_outstanding == 0); TORRENT_ASSERT(m_v6_outstanding == 0);
void* tmp = realloc(m_v6_buf, m_v6_buf_size); void* tmp = realloc(m_v6_buf, m_v6_buf_size);
@ -587,8 +587,6 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec); if (m_ipv6_sock.is_open()) m_ipv6_sock.close(ec);
#endif #endif
maybe_realloc_buffers();
if (ep.address().is_v4()) if (ep.address().is_v4())
{ {
m_ipv4_sock.open(udp::v4(), ec); m_ipv4_sock.open(udp::v4(), ec);
@ -597,6 +595,7 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
if (ec) return; if (ec) return;
if (m_v4_outstanding == 0) if (m_v4_outstanding == 0)
{ {
maybe_realloc_buffers(1);
#if defined TORRENT_ASIO_DEBUGGING #if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read"); add_outstanding_async("udp_socket::on_read");
#endif #endif
@ -615,6 +614,7 @@ void udp_socket::bind(udp::endpoint const& ep, error_code& ec)
if (ec) return; if (ec) return;
if (m_v6_outstanding == 0) if (m_v6_outstanding == 0)
{ {
maybe_realloc_buffers(2);
#if defined TORRENT_ASIO_DEBUGGING #if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("udp_socket::on_read"); add_outstanding_async("udp_socket::on_read");
#endif #endif