From 8e8f7989051fd21c818621bf8970eebbee560968 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 30 Nov 2011 20:07:18 +0000 Subject: [PATCH] get rid of read-recurse hack --- include/libtorrent/peer_connection.hpp | 4 --- src/peer_connection.cpp | 38 ++++++-------------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 7312a85d4..c0395ec21 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -1041,10 +1041,6 @@ namespace libtorrent // requesting too many pieces while being choked boost::uint8_t m_choke_rejects; - // counts the number of recursive calls to on_receive_data - // used to limit recursion - boost::uint8_t m_read_recurse:5; - // if this is true, the disconnection // timestamp is not updated when the connection // is closed. This means the time until we can diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 25b615191..1590e734a 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -138,7 +138,6 @@ namespace libtorrent , m_prefer_whole_pieces(0) , m_desired_queue_size(2) , m_choke_rejects(0) - , m_read_recurse(0) , m_fast_reconnect(false) , m_active(outgoing) , m_peer_interested(false) @@ -289,7 +288,6 @@ namespace libtorrent , m_prefer_whole_pieces(0) , m_desired_queue_size(2) , m_choke_rejects(0) - , m_read_recurse(0) , m_fast_reconnect(false) , m_active(outgoing) , m_peer_interested(false) @@ -2481,7 +2479,6 @@ namespace libtorrent int write_queue_size = fs.async_write(p, data, boost::bind(&peer_connection::on_disk_write_complete , self(), _1, _2, p, t)); m_outstanding_writing_bytes += p.length; - TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); m_download_queue.erase(b); if (write_queue_size / 16 / 1024 > m_ses.m_settings.cache_size / 2 @@ -4833,31 +4830,6 @@ namespace libtorrent return; } error_code ec; - - if (sync == read_sync && m_read_recurse < 10) - { - size_t bytes_transferred = try_read(read_sync, ec); - - if (ec != asio::error::would_block) - { -#if defined TORRENT_ASIO_DEBUGGING - add_outstanding_async("peer_connection::on_receive_data"); -#endif - ++m_read_recurse; - TORRENT_ASSERT((m_channel_state[download_channel] & peer_info::bw_network) == 0); - m_channel_state[download_channel] |= peer_info::bw_network; - on_receive_data(ec, bytes_transferred); - --m_read_recurse; - return; - } - } - -#ifdef TORRENT_VERBOSE_LOGGING - if (m_read_recurse >= 10) - { - peer_log("*** reached recursion limit"); - } -#endif try_read(read_async, ec); } @@ -5124,8 +5096,11 @@ namespace libtorrent #if defined TORRENT_ASIO_DEBUGGING complete_async("peer_connection::on_receive_data"); #endif + + // leave this bit set until we're done looping, reading from the socket. + // that way we don't trigger any async read calls until the end of this + // function. TORRENT_ASSERT(m_channel_state[download_channel] & peer_info::bw_network); - m_channel_state[download_channel] &= ~peer_info::bw_network; int bytes_in_loop = bytes_transferred; @@ -5222,6 +5197,11 @@ namespace libtorrent } m_statistics.trancieve_ip_packet(bytes_in_loop, m_remote.address().is_v6()); + + // allow reading from the socket again + TORRENT_ASSERT(m_channel_state[download_channel] & peer_info::bw_network); + m_channel_state[download_channel] &= ~peer_info::bw_network; + setup_receive(read_async); }