From 1c377b18076ef2c7022d1a9e842d8dca17c07a46 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 2 Nov 2009 01:01:07 +0000 Subject: [PATCH] streaming fixes --- examples/client_test.cpp | 14 ++++++++++++++ src/peer_connection.cpp | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 8e3ffab1e..f8649f614 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1109,6 +1109,20 @@ int main(int argc, char* argv[]) if (h.is_valid()) h.set_sequential_download(!h.is_sequential_download()); } + if (c == 'o') + { + torrent_handle h = get_active_torrent(handles); + if (h.is_valid()) + { + int num_pieces = h.get_torrent_info().num_pieces(); + if (num_pieces > 300) num_pieces = 300; + for (int i = 0; i < num_pieces; ++i) + { + h.set_piece_deadline(i, seconds(i+5), torrent_handle::alert_when_available); + } + } + } + if (c == 'v') { torrent_handle h = get_active_torrent(handles); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4be086bb8..a127a5588 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1091,6 +1091,7 @@ namespace libtorrent } } m_request_queue.clear(); + m_queued_time_critical = 0; } } @@ -2561,9 +2562,8 @@ namespace libtorrent bool peer_connection::can_request_time_critical() const { if (has_peer_choked() || !is_interesting()) return false; - if (m_desired_queue_size * 2 < - - (int)m_download_queue.size() - - (int)m_request_queue.size()) return false; + if ((int)m_download_queue.size() + (int)m_request_queue.size() + > m_desired_queue_size * 2) return false; if (on_parole()) return false; return true; } @@ -3077,6 +3077,7 @@ namespace libtorrent m_request_queue.pop_back(); } } + m_queued_time_critical = 0; t->remove_peer(this); m_torrent.reset(); @@ -3734,6 +3735,8 @@ namespace libtorrent = m_request_queue.begin() + (prev_request_queue - 1); r = *i; m_request_queue.erase(i); + if (prev_request_queue <= m_queued_time_critical) + --m_queued_time_critical; } else {