From f0b15a241093c3a65b703f75e6abaa3f6062017d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 6 Feb 2011 09:34:47 +0000 Subject: [PATCH] more robust removal in packet_buffer --- src/packet_buffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/packet_buffer.cpp b/src/packet_buffer.cpp index ea30cdc4c..c9745f978 100644 --- a/src/packet_buffer.cpp +++ b/src/packet_buffer.cpp @@ -192,13 +192,17 @@ namespace libtorrent { if (idx == m_first && m_size != 0) { - while (!m_storage[++m_first & mask]); + ++m_first; + for (int i = 0; i < m_capacity; ++i, ++m_first) + if (m_storage[m_first & mask]) break; m_first &= 0xffff; } if (((idx + 1) & 0xffff) == m_last && m_size != 0) { - while (!m_storage[--m_last & mask]); + --m_last; + for (int i = 0; i < m_capacity; ++i, --m_last) + if (m_storage[m_last & mask]) break; ++m_last; m_last &= 0xffff; }