added asserts to make sure the pool allocator for dht messages allocates blocks of correct size

This commit is contained in:
Arvid Norberg 2008-01-13 04:24:10 +00:00
parent 7cea96ea88
commit 56210c1687
5 changed files with 12 additions and 0 deletions

View File

@ -93,6 +93,7 @@ public:
void reply_with_ping(msg& m);
#ifndef NDEBUG
size_t allocation_size() const;
void check_invariant() const;
#endif

View File

@ -100,6 +100,7 @@ closest_nodes::closest_nodes(
void closest_nodes::invoke(node_id const& id, udp::endpoint addr)
{
TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(closest_nodes_observer));
observer_ptr o(new (m_rpc.allocator().malloc()) closest_nodes_observer(this, id, m_target));
m_rpc.invoke(messages::find_node, addr, o);
}

View File

@ -109,6 +109,7 @@ void find_data::invoke(node_id const& id, asio::ip::udp::endpoint addr)
return;
}
TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(find_data_observer));
observer_ptr o(new (m_rpc.allocator().malloc()) find_data_observer(this, id, m_target));
m_rpc.invoke(messages::get_peers, addr, o);
}

View File

@ -103,6 +103,7 @@ void ping_observer::timeout()
void refresh::invoke(node_id const& nid, udp::endpoint addr)
{
TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(refresh_observer));
observer_ptr o(new (m_rpc.allocator().malloc()) refresh_observer(
this, nid, m_target));
@ -154,6 +155,7 @@ void refresh::invoke_pings_or_finish(bool prevent_request)
try
{
TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(ping_observer));
observer_ptr o(new (m_rpc.allocator().malloc()) ping_observer(
this, node.id));
m_rpc.invoke(messages::ping, node.addr, o);

View File

@ -136,6 +136,12 @@ rpc_manager::~rpc_manager()
}
#ifndef NDEBUG
size_t rpc_manager::allocation_size() const
{
size_t s = sizeof(mpl::deref<max_observer_type_iter::base>::type);
return s;
}
void rpc_manager::check_invariant() const
{
TORRENT_ASSERT(m_oldest_transaction_id >= 0);
@ -429,6 +435,7 @@ void rpc_manager::reply_with_ping(msg& m)
std::back_insert_iterator<std::string> out(m.ping_transaction_id);
io::write_uint16(m_next_transaction_id, out);
TORRENT_ASSERT(allocation_size() >= sizeof(null_observer));
observer_ptr o(new (allocator().malloc()) null_observer(allocator()));
TORRENT_ASSERT(!m_transactions[m_next_transaction_id]);
o->sent = time_now();