merged uTP fix from RC_0_16

This commit is contained in:
Arvid Norberg 2012-11-25 07:03:37 +00:00
parent 5077c06c4a
commit 205d70da3c
3 changed files with 21 additions and 2 deletions

View File

@ -107,7 +107,7 @@ namespace libtorrent
std::size_t m_size;
// This defines the first index that is part of the m_storage.
// The last index is (m_first + (m_capacity - 1)) & 0xffff.
// last is one passed the last used slot
index_type m_first;
index_type m_last;
};

View File

@ -106,7 +106,7 @@ namespace libtorrent {
// We have wrapped.
if (idx >= ((m_first + m_capacity) & 0xffff) && m_capacity < 0xffff)
{
reserve(m_capacity + (idx - ((m_first + m_capacity) & 0xffff)));
reserve(m_capacity + (idx + 1 - ((m_first + m_capacity) & 0xffff)));
}
}
if (compare_less_wrap(m_last, (idx + 1) & 0xffff, 0xffff))

View File

@ -705,6 +705,25 @@ int test_main()
TEST_CHECK(pb.at(2) == (void*)2);
}
{
// test wrapping the indices
packet_buffer pb;
TEST_EQUAL(pb.size(), 0);
pb.insert(0xfff3, (void*)1);
TEST_CHECK(pb.at(0xfff3) == (void*)1);
int new_index = (0xfff3 + pb.capacity()) & 0xffff;
pb.insert(new_index, (void*)2);
TEST_CHECK(pb.at(new_index) == (void*)2);
void* old = pb.remove(0xfff3);
TEST_CHECK(old == (void*)1);
TEST_CHECK(pb.at(0xfff3) == (void*)0);
TEST_CHECK(pb.at(new_index) == (void*)2);
}
TEST_CHECK(error_code(errors::http_error).message() == "HTTP error");
TEST_CHECK(error_code(errors::missing_file_sizes).message() == "missing or invalid 'file sizes' entry");
TEST_CHECK(error_code(errors::unsupported_protocol_version).message() == "unsupported protocol version");