fix some build warnings

This commit is contained in:
arvidn 2015-08-17 09:01:43 -04:00
parent 2e5a85056b
commit eecdd3121d
10 changed files with 120 additions and 90 deletions

View File

@ -66,13 +66,13 @@ namespace libtorrent
// whenever the element at the cursor is removed, the
// cursor is bumped to the next occupied element
class TORRENT_EXTRA_EXPORT packet_buffer
class TORRENT_EXTRA_EXPORT packet_buffer_impl
{
public:
typedef boost::uint32_t index_type;
packet_buffer();
~packet_buffer();
packet_buffer_impl();
~packet_buffer_impl();
void* insert(index_type idx, void* value);
@ -111,6 +111,31 @@ namespace libtorrent
index_type m_first;
index_type m_last;
};
template <typename T>
class packet_buffer : packet_buffer_impl
{
public:
using packet_buffer_impl::index_type;
using packet_buffer_impl::size;
using packet_buffer_impl::capacity;
using packet_buffer_impl::reserve;
using packet_buffer_impl::cursor;
using packet_buffer_impl::span;
T* insert(index_type i, T* p)
{
return static_cast<T*>(packet_buffer_impl::insert(i, p));
}
T* at(index_type idx) const
{ return static_cast<T*>(packet_buffer_impl::at(idx)); }
T* remove(index_type idx)
{ return static_cast<T*>(packet_buffer_impl::remove(idx)); }
};
}
#endif // TORRENT_PACKET_BUFFER_HPP_INCLUDED

View File

@ -70,6 +70,8 @@ namespace libtorrent
void set_utp_stream_logging(bool enable);
#endif
bool compare_less_wrap(boost::uint32_t lhs, boost::uint32_t rhs, boost::uint32_t mask);
struct utp_socket_manager;
// internal: some MTU and protocol header sizes constants

View File

@ -26,7 +26,7 @@ alias libtorrent-sims :
[ run test_swarm.cpp ]
[ run test_super_seeding.cpp ]
[ run test_utp.cpp ]
# [ run test_dht.cpp ]
[ run test_dht.cpp ]
[ run test_pe_crypto.cpp ]
[ run test_metadata_extension.cpp ]
[ run test_trackers_extension.cpp ]

View File

@ -1833,8 +1833,8 @@ namespace libtorrent {
dht_direct_response_alert::dht_direct_response_alert(
aux::stack_allocator& alloc, void* userdata_
, udp::endpoint const& addr, bdecode_node const& response)
: userdata(userdata_), addr(addr), m_alloc(alloc)
, udp::endpoint const& addr_, bdecode_node const& response)
: userdata(userdata_), addr(addr_), m_alloc(alloc)
, m_response_idx(alloc.copy_buffer(response.data_section().first, response.data_section().second))
, m_response_size(response.data_section().second)
{}

View File

@ -41,7 +41,7 @@ namespace libtorrent {
bool compare_less_wrap(boost::uint32_t lhs, boost::uint32_t rhs
, boost::uint32_t mask);
packet_buffer::packet_buffer()
packet_buffer_impl::packet_buffer_impl()
: m_storage(0)
, m_capacity(0)
, m_size(0)
@ -50,7 +50,7 @@ namespace libtorrent {
{}
#if TORRENT_USE_INVARIANT_CHECKS
void packet_buffer::check_invariant() const
void packet_buffer_impl::check_invariant() const
{
int count = 0;
for (int i = 0; i < int(m_capacity); ++i)
@ -61,12 +61,12 @@ namespace libtorrent {
}
#endif
packet_buffer::~packet_buffer()
packet_buffer_impl::~packet_buffer_impl()
{
free(m_storage);
}
void* packet_buffer::insert(index_type idx, void* value)
void* packet_buffer_impl::insert(index_type idx, void* value)
{
INVARIANT_CHECK;
@ -133,7 +133,7 @@ namespace libtorrent {
return old_value;
}
void* packet_buffer::at(index_type idx) const
void* packet_buffer_impl::at(index_type idx) const
{
INVARIANT_CHECK;
if (idx >= m_first + m_capacity)
@ -148,7 +148,7 @@ namespace libtorrent {
return m_storage[idx & mask];
}
void packet_buffer::reserve(std::size_t size)
void packet_buffer_impl::reserve(std::size_t size)
{
INVARIANT_CHECK;
TORRENT_ASSERT_VAL(size <= 0xffff, size);
@ -174,7 +174,7 @@ namespace libtorrent {
m_capacity = new_size;
}
void* packet_buffer::remove(index_type idx)
void* packet_buffer_impl::remove(index_type idx)
{
INVARIANT_CHECK;
// TODO: use compare_less_wrap for this comparison as well

View File

@ -1820,7 +1820,7 @@ retry:
{
// this means we should open two listen sockets
// one for IPv4 and one for IPv6
int retries = m_settings.get_int(settings_pack::max_retry_port_bind);
const int retries = m_settings.get_int(settings_pack::max_retry_port_bind);
listen_socket_t s = setup_listener("0.0.0.0", true
, m_listen_interface.port()
@ -1840,8 +1840,7 @@ retry:
#ifdef TORRENT_USE_OPENSSL
if (m_settings.get_int(settings_pack::ssl_listen))
{
int retries = m_settings.get_int(settings_pack::max_retry_port_bind);
listen_socket_t s = setup_listener("0.0.0.0", true
s = setup_listener("0.0.0.0", true
, m_settings.get_int(settings_pack::ssl_listen)
, flags | open_ssl_socket, ec);
@ -1857,7 +1856,7 @@ retry:
// only try to open the IPv6 port if IPv6 is installed
if (supports_ipv6())
{
listen_socket_t s = setup_listener("::1", false, m_listen_interface.port()
s = setup_listener("::1", false, m_listen_interface.port()
, flags, ec);
if (!ec && s.sock)
@ -1870,7 +1869,7 @@ retry:
if (m_settings.get_int(settings_pack::ssl_listen))
{
s.ssl = true;
listen_socket_t s = setup_listener("::1", false
s = setup_listener("::1", false
, m_settings.get_int(settings_pack::ssl_listen)
, flags | open_ssl_socket, ec);
@ -2504,7 +2503,6 @@ retry:
// peer is correctly bound to on of them
if (!m_settings.get_str(settings_pack::outgoing_interfaces).empty())
{
error_code ec;
tcp::endpoint local = s->local_endpoint(ec);
if (ec)
{
@ -2927,10 +2925,10 @@ retry:
#endif
// remove undead peers that only have this list as their reference keeping them alive
std::vector<boost::shared_ptr<peer_connection> >::iterator i = std::remove_if(
m_undead_peers.begin(), m_undead_peers.end()
std::vector<boost::shared_ptr<peer_connection> >::iterator remove_it
= std::remove_if(m_undead_peers.begin(), m_undead_peers.end()
, boost::bind(&boost::shared_ptr<peer_connection>::unique, _1));
m_undead_peers.erase(i, m_undead_peers.end());
m_undead_peers.erase(remove_it, m_undead_peers.end());
int tick_interval_ms = int(total_milliseconds(now - m_last_second_tick));
m_last_second_tick = now;
@ -4551,14 +4549,14 @@ retry:
&& !params.resume_data.empty())
{
int pos;
error_code ec;
error_code err;
bdecode_node tmp;
bdecode_node info;
#ifndef TORRENT_DISABLE_LOGGING
session_log("adding magnet link with resume data");
#endif
if (bdecode(&params.resume_data[0], &params.resume_data[0]
+ params.resume_data.size(), tmp, ec, &pos) == 0
+ params.resume_data.size(), tmp, err, &pos) == 0
&& tmp.type() == bdecode_node::dict_t
&& (info = tmp.dict_find_dict("info")))
{
@ -4583,7 +4581,7 @@ retry:
#endif
params.ti = boost::make_shared<torrent_info>(resume_ih);
if (params.ti->parse_info_section(info, ec, 0))
if (params.ti->parse_info_section(info, err, 0))
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("successfully loaded metadata from resume file");
@ -4596,7 +4594,7 @@ retry:
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("failed to load metadata from resume file: %s"
, ec.message().c_str());
, err.message().c_str());
#endif
}
}
@ -4610,7 +4608,7 @@ retry:
#ifndef TORRENT_DISABLE_LOGGING
else
{
session_log("no metadata found");
session_log("no metadata found (\"%s\")", err.message().c_str());
}
#endif
}

View File

@ -4124,13 +4124,13 @@ namespace libtorrent
// (unless it has already been announced through predictive_piece_announce
// feature).
bool announce_piece = true;
std::vector<int>::iterator i = std::lower_bound(m_predictive_pieces.begin()
std::vector<int>::iterator it = std::lower_bound(m_predictive_pieces.begin()
, m_predictive_pieces.end(), index);
if (i != m_predictive_pieces.end() && *i == index)
if (it != m_predictive_pieces.end() && *it == index)
{
// this means we've already announced the piece
announce_piece = false;
m_predictive_pieces.erase(i);
m_predictive_pieces.erase(it);
}
// make a copy of the peer list since peers
@ -4339,9 +4339,9 @@ namespace libtorrent
if (m_ses.alerts().should_post<hash_failed_alert>())
m_ses.alerts().emplace_alert<hash_failed_alert>(get_handle(), index);
std::vector<int>::iterator i = std::lower_bound(m_predictive_pieces.begin()
std::vector<int>::iterator it = std::lower_bound(m_predictive_pieces.begin()
, m_predictive_pieces.end(), index);
if (i != m_predictive_pieces.end() && *i == index)
if (it != m_predictive_pieces.end() && *it == index)
{
for (peer_iterator p = m_connections.begin()
, end(m_connections.end()); p != end; ++p)
@ -4353,7 +4353,7 @@ namespace libtorrent
// know that we don't actually have this piece
(*p)->write_dont_have(index);
}
m_predictive_pieces.erase(i);
m_predictive_pieces.erase(it);
}
// increase the total amount of failed bytes
add_failed_bytes(m_torrent_file->piece_size(index));
@ -4382,7 +4382,7 @@ namespace libtorrent
for (std::vector<void*>::iterator i = downloaders.begin()
, end(downloaders.end()); i != end; ++i)
{
torrent_peer* p = (torrent_peer*)*i;
torrent_peer* p = static_cast<torrent_peer*>(*i);
if (p && p->connection)
{
peer_connection* peer = static_cast<peer_connection*>(p->connection);
@ -4583,7 +4583,7 @@ namespace libtorrent
}
#endif
}
// when we get a bitfield message, this is called for that piece
void torrent::peer_has(bitfield const& bits, peer_connection const* peer)
{
@ -7362,11 +7362,11 @@ namespace libtorrent
}
else
{
torrent_peer* p = static_cast<torrent_peer*>(info[j].peer);
TORRENT_ASSERT(p->in_use);
if (p->connection)
torrent_peer* tp = static_cast<torrent_peer*>(info[j].peer);
TORRENT_ASSERT(tp->in_use);
if (tp->connection)
{
peer_connection* peer = static_cast<peer_connection*>(p->connection);
peer_connection* peer = static_cast<peer_connection*>(tp->connection);
TORRENT_ASSERT(peer->m_in_use);
bi.set_peer(peer->remote());
if (bi.state == block_info::requested)
@ -7390,7 +7390,7 @@ namespace libtorrent
}
else
{
bi.set_peer(p->ip());
bi.set_peer(tp->ip());
bi.bytes_progress = complete ? bi.block_size : 0;
}
}
@ -8800,14 +8800,14 @@ namespace libtorrent
peer_connection const& p = *(*i);
fprintf(stderr, "peer: %s\n", print_endpoint(p.remote()).c_str());
for (std::vector<pending_block>::const_iterator i = p.request_queue().begin()
, end(p.request_queue().end()); i != end; ++i)
, end2(p.request_queue().end()); i != end2; ++i)
{
fprintf(stderr, " rq: (%d, %d) %s %s %s\n", i->block.piece_index
, i->block.block_index, i->not_wanted ? "not-wanted" : ""
, i->timed_out ? "timed-out" : "", i->busy ? "busy": "");
}
for (std::vector<pending_block>::const_iterator i = p.download_queue().begin()
, end(p.download_queue().end()); i != end; ++i)
, end2(p.download_queue().end()); i != end2; ++i)
{
fprintf(stderr, " dq: (%d, %d) %s %s %s\n", i->block.piece_index
, i->block.block_index, i->not_wanted ? "not-wanted" : ""

View File

@ -472,8 +472,8 @@ namespace libtorrent
{
for (int i = 0, end(s_p.list_size()); i < end; ++i)
{
std::string path_element = s_p.list_at(i).string_value();
symlink_path = combine_path(symlink_path, path_element);
std::string pe = s_p.list_at(i).string_value();
symlink_path = combine_path(symlink_path, pe);
}
}
else
@ -1386,9 +1386,9 @@ namespace libtorrent
int n = m_merkle_first_leaf + piece;
typedef std::map<int, sha1_hash>::const_iterator iter;
iter i = subtree.find(n);
if (i == subtree.end()) return false;
sha1_hash h = i->second;
iter it = subtree.find(n);
if (it == subtree.end()) return false;
sha1_hash h = it->second;
// if the verification passes, these are the
// nodes to add to our tree
@ -1529,7 +1529,7 @@ namespace libtorrent
{
bdecode_node tier = announce_node.list_at(j);
if (tier.type() != bdecode_node::list_t) continue;
for (int k = 0, end(tier.list_size()); k < end; ++k)
for (int k = 0, end2(tier.list_size()); k < end2; ++k)
{
announce_entry e(tier.list_string_value_at(k));
e.trim();

View File

@ -466,9 +466,8 @@ public:
// the send and receive buffers
// maps packet sequence numbers
// TODO 3: if the packet_buffer was a template, we could avoid some pointer casts
packet_buffer m_inbuf;
packet_buffer m_outbuf;
packet_buffer<packet> m_inbuf;
packet_buffer<packet> m_outbuf;
// the time when the last packet we sent times out. Including re-sends.
// if we ever end up not having sent anything in one second (
@ -1087,7 +1086,7 @@ size_t utp_stream::read_some(bool clear_buffers)
for (std::vector<packet*>::iterator i = m_impl->m_receive_buffer.begin()
, end(m_impl->m_receive_buffer.end()); i != end;)
{
if (target == m_impl->m_read_buffer.end())
if (target == m_impl->m_read_buffer.end())
{
UTP_LOGV(" No more target buffers: %d bytes left in buffer\n"
, m_impl->m_receive_buffer_size);
@ -1102,7 +1101,7 @@ size_t utp_stream::read_some(bool clear_buffers)
TORRENT_ASSERT(to_copy >= 0);
memcpy(target->buf, p->buf + p->header_size, to_copy);
ret += to_copy;
target->buf = ((char*)target->buf) + to_copy;
target->buf = static_cast<char*>(target->buf) + to_copy;
TORRENT_ASSERT(int(target->len) >= to_copy);
target->len -= to_copy;
m_impl->m_receive_buffer_size -= to_copy;
@ -1213,14 +1212,14 @@ utp_socket_impl::~utp_socket_impl()
+ m_inbuf.capacity()) & ACK_MASK);
i != end; i = (i + 1) & ACK_MASK)
{
void* p = m_inbuf.remove(i);
packet* p = m_inbuf.remove(i);
free(p);
}
for (boost::uint16_t i = m_outbuf.cursor(), end((m_outbuf.cursor()
+ m_outbuf.capacity()) & ACK_MASK);
i != end; i = (i + 1) & ACK_MASK)
{
void* p = m_outbuf.remove(i);
packet* p = m_outbuf.remove(i);
free(p);
}
@ -1360,7 +1359,7 @@ void utp_socket_impl::send_syn()
m_ack_nr = 0;
m_fast_resend_seq_nr = m_seq_nr;
packet* p = (packet*)malloc(sizeof(packet) + sizeof(utp_header));
packet* p = static_cast<packet*>(malloc(sizeof(packet) + sizeof(utp_header)));
p->size = sizeof(utp_header);
p->header_size = sizeof(utp_header);
p->num_transmissions = 0;
@ -1368,7 +1367,7 @@ void utp_socket_impl::send_syn()
p->num_fast_resend = 0;
#endif
p->need_resend = false;
utp_header* h = (utp_header*)p->buf;
utp_header* h = reinterpret_cast<utp_header*>(p->buf);
h->type_ver = (ST_SYN << 4) | 1;
h->extension = utp_no_extension;
// using recv_id here is intentional! This is an odd
@ -1393,8 +1392,8 @@ void utp_socket_impl::send_syn()
#endif
error_code ec;
m_sm->send_packet(udp::endpoint(m_remote_address, m_port), (char const*)h
, sizeof(utp_header), ec);
m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
, reinterpret_cast<char const*>(h) , sizeof(utp_header), ec);
if (ec == error::would_block || ec == error::try_again)
{
@ -1422,7 +1421,7 @@ void utp_socket_impl::send_syn()
TORRENT_ASSERT(!m_outbuf.at(m_seq_nr));
m_outbuf.insert(m_seq_nr, p);
TORRENT_ASSERT(h->seq_nr == m_seq_nr);
TORRENT_ASSERT(p->buf == (boost::uint8_t*)h);
TORRENT_ASSERT(p->buf == reinterpret_cast<boost::uint8_t*>(h));
m_seq_nr = (m_seq_nr + 1) & ACK_MASK;
@ -1484,7 +1483,8 @@ void utp_socket_impl::send_reset(utp_header* ph)
// ignore errors here
error_code ec;
m_sm->send_packet(udp::endpoint(m_remote_address, m_port), (char const*)&h, sizeof(h), ec);
m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
, reinterpret_cast<char const*>(&h), sizeof(h), ec);
}
std::size_t utp_socket_impl::available() const
@ -1558,7 +1558,7 @@ void utp_socket_impl::parse_sack(boost::uint16_t packet_ack, boost::uint8_t cons
if (compare_less_wrap(m_fast_resend_seq_nr, ack_nr, ACK_MASK)) ++dups;
// this bit was set, ack_nr was received
packet* p = (packet*)m_outbuf.remove(ack_nr);
packet* p = m_outbuf.remove(ack_nr);
if (p)
{
*acked_bytes += p->size - p->header_size;
@ -1596,7 +1596,7 @@ void utp_socket_impl::parse_sack(boost::uint16_t packet_ack, boost::uint8_t cons
int num_resent = 0;
while (m_fast_resend_seq_nr != last_ack)
{
packet* p = (packet*)m_outbuf.at(m_fast_resend_seq_nr);
packet* p = m_outbuf.at(m_fast_resend_seq_nr);
m_fast_resend_seq_nr = (m_fast_resend_seq_nr + 1) & ACK_MASK;
if (!p) continue;
++num_resent;
@ -1754,7 +1754,7 @@ bool utp_socket_impl::send_pkt(int flags)
// a separate list of sequence numbers that need resending
for (int i = (m_acked_seq_nr + 1) & ACK_MASK; i != m_seq_nr; i = (i + 1) & ACK_MASK)
{
packet* p = (packet*)m_outbuf.at(i);
packet* p = m_outbuf.at(i);
if (!p) continue;
if (!p->need_resend) continue;
if (!resend_packet(p))
@ -1880,9 +1880,9 @@ bool utp_socket_impl::send_pkt(int flags)
// this alloca() statement won't necessarily produce
// correctly aligned memory. That's why we ask for 7 more bytes
// and adjust our pointer to be aligned later
p = (packet*)TORRENT_ALLOCA(char, sizeof(packet) + packet_size
+ sizeof(packet*) - 1);
p = (packet*)align_pointer(p);
p = reinterpret_cast<packet*>(TORRENT_ALLOCA(char, sizeof(packet) + packet_size
+ sizeof(packet*) - 1));
p = reinterpret_cast<packet*>(align_pointer(p));
UTP_LOGV("%8p: allocating %d bytes on the stack\n", this, packet_size);
p->allocated = packet_size;
}
@ -2116,7 +2116,7 @@ bool utp_socket_impl::send_pkt(int flags)
// release the buffer, we're saving it in the circular
// buffer of outgoing packets
buf_holder.release();
packet* old = (packet*)m_outbuf.insert(m_seq_nr, p);
packet* old = m_outbuf.insert(m_seq_nr, p);
if (old)
{
TORRENT_ASSERT(((utp_header*)old->buf)->seq_nr == m_seq_nr);
@ -2544,7 +2544,7 @@ bool utp_socket_impl::consume_incoming_data(
{
int const next_ack_nr = (m_ack_nr + 1) & ACK_MASK;
packet* p = (packet*)m_inbuf.remove(next_ack_nr);
packet* p = m_inbuf.remove(next_ack_nr);
if (!p) break;
@ -2907,7 +2907,7 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
{
if (m_fast_resend_seq_nr == ack_nr)
m_fast_resend_seq_nr = (m_fast_resend_seq_nr + 1) & ACK_MASK;
packet* p = (packet*)m_outbuf.remove(ack_nr);
packet* p = m_outbuf.remove(ack_nr);
if (!p) continue;
@ -2974,7 +2974,7 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
UTP_LOGV("%8p: Packet %d lost. (%d duplicate acks, trigger fast-resend)\n", this, m_fast_resend_seq_nr, m_duplicate_acks);
// resend the lost packet
packet* p = (packet*)m_outbuf.at(m_fast_resend_seq_nr);
packet* p = m_outbuf.at(m_fast_resend_seq_nr);
TORRENT_ASSERT(p);
// don't fast-resend this again
@ -3609,7 +3609,7 @@ void utp_socket_impl::tick(time_point now)
i != ((m_seq_nr + 1) & ACK_MASK);
i = (i + 1) & ACK_MASK)
{
packet* p = (packet*)m_outbuf.at(i);
packet* p = m_outbuf.at(i);
if (!p) continue;
if (p->need_resend) continue;
p->need_resend = true;
@ -3621,7 +3621,7 @@ void utp_socket_impl::tick(time_point now)
TORRENT_ASSERT(m_bytes_in_flight == 0);
// if we have a packet that needs re-sending, resend it
packet* p = (packet*)m_outbuf.at((m_acked_seq_nr + 1) & ACK_MASK);
packet* p = m_outbuf.at((m_acked_seq_nr + 1) & ACK_MASK);
if (p)
{
if (p->num_transmissions >= m_sm->num_resends()
@ -3697,7 +3697,7 @@ void utp_socket_impl::check_invariant() const
i != int((m_outbuf.cursor() + m_outbuf.span()) & ACK_MASK);
i = (i + 1) & ACK_MASK)
{
packet* p = (packet*)m_outbuf.at(i);
packet* p = m_outbuf.at(i);
if (!p) continue;
if (m_mtu_seq == i && m_mtu_seq != 0)
{

View File

@ -38,62 +38,67 @@ using libtorrent::packet_buffer;
// test packet_buffer
TORRENT_TEST(insert)
{
packet_buffer pb;
packet_buffer<int> pb;
int a123 = 123;
int a125 = 125;
int a500 = 500;
int a501 = 501;
TEST_EQUAL(pb.capacity(), 0);
TEST_EQUAL(pb.size(), 0);
TEST_EQUAL(pb.span(), 0);
pb.insert(123, (void*)123);
pb.insert(123, &a123);
TEST_EQUAL(pb.at(123 + 16), 0);
TEST_CHECK(pb.at(123) == (void*)123);
TEST_CHECK(pb.at(123) == &a123);
TEST_CHECK(pb.capacity() > 0);
TEST_EQUAL(pb.size(), 1);
TEST_EQUAL(pb.span(), 1);
TEST_EQUAL(pb.cursor(), 123);
pb.insert(125, (void*)125);
pb.insert(125, &a125);
TEST_CHECK(pb.at(125) == (void*)125);
TEST_CHECK(pb.at(125) == &a125);
TEST_EQUAL(pb.size(), 2);
TEST_EQUAL(pb.span(), 3);
TEST_EQUAL(pb.cursor(), 123);
pb.insert(500, (void*)500);
pb.insert(500, &a500);
TEST_EQUAL(pb.size(), 3);
TEST_EQUAL(pb.span(), 501 - 123);
TEST_EQUAL(pb.capacity(), 512);
pb.insert(500, (void*)501);
pb.insert(500, &a501);
TEST_EQUAL(pb.size(), 3);
pb.insert(500, (void*)500);
pb.insert(500, &a500);
TEST_EQUAL(pb.size(), 3);
TEST_CHECK(pb.remove(123) == (void*)123);
TEST_CHECK(pb.remove(123) == &a123);
TEST_EQUAL(pb.size(), 2);
TEST_EQUAL(pb.span(), 501 - 125);
TEST_EQUAL(pb.cursor(), 125);
TEST_CHECK(pb.remove(125) == (void*)125);
TEST_CHECK(pb.remove(125) == &a125);
TEST_EQUAL(pb.size(), 1);
TEST_EQUAL(pb.span(), 1);
TEST_EQUAL(pb.cursor(), 500);
TEST_CHECK(pb.remove(500) == (void*)500);
TEST_CHECK(pb.remove(500) == &a500);
TEST_EQUAL(pb.size(), 0);
TEST_EQUAL(pb.span(), 0);
for (int i = 0; i < 0xff; ++i)
{
int index = (i + 0xfff0) & 0xffff;
pb.insert(index, reinterpret_cast<void*>(index + 1));
pb.insert(index, reinterpret_cast<int*>(index + 1));
fprintf(stderr, "insert: %u (mask: %x)\n", index, int(pb.capacity() - 1));
TEST_EQUAL(pb.capacity(), 512);
if (i >= 14)
{
index = (index - 14) & 0xffff;
fprintf(stderr, "remove: %u\n", index);
TEST_CHECK(pb.remove(index) == reinterpret_cast<void*>(index + 1));
TEST_CHECK(pb.remove(index) == reinterpret_cast<int*>(index + 1));
TEST_EQUAL(pb.size(), 14);
}
}
@ -102,7 +107,7 @@ TORRENT_TEST(insert)
TORRENT_TEST(wrap)
{
// test wrapping the indices
packet_buffer pb;
packet_buffer<void> pb;
TEST_EQUAL(pb.size(), 0);
@ -120,7 +125,7 @@ TORRENT_TEST(wrap)
TORRENT_TEST(wrap2)
{
// test wrapping the indices
packet_buffer pb;
packet_buffer<void> pb;
TEST_EQUAL(pb.size(), 0);
@ -140,7 +145,7 @@ TORRENT_TEST(wrap2)
TORRENT_TEST(reverse_wrap)
{
// test wrapping the indices backwards
packet_buffer pb;
packet_buffer<void> pb;
TEST_EQUAL(pb.size(), 0);