support asio handler allocators in deferred_handler

This commit is contained in:
arvidn 2017-12-25 09:02:18 +01:00 committed by Arvid Norberg
parent 40292a1d51
commit 56ca5fa63c
3 changed files with 21 additions and 3 deletions

View File

@ -120,7 +120,7 @@ namespace libtorrent { namespace aux {
std::size_t size, allocating_handler<Handler, Size>* ctx)
{
TORRENT_UNUSED(size);
TORRENT_ASSERT(size <= Size);
TORRENT_ASSERT_VAL(size <= Size, size);
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(!ctx->storage.used);
ctx->storage.used = true;
@ -135,7 +135,7 @@ namespace libtorrent { namespace aux {
TORRENT_UNUSED(size);
TORRENT_UNUSED(ctx);
TORRENT_ASSERT(size <= Size);
TORRENT_ASSERT_VAL(size <= Size, size);
TORRENT_ASSERT(ptr == &ctx->storage.bytes);
#if TORRENT_USE_ASSERTS
ctx->storage.used = false;

View File

@ -51,6 +51,20 @@ struct handler_wrapper
m_in_flight = false;
m_handler(std::forward<Args>(a)...);
}
// forward asio handler allocator to the underlying handler's
friend void* asio_handler_allocate(
std::size_t size, handler_wrapper<Handler>* h)
{
return asio_handler_allocate(size, &h->m_handler);
}
friend void asio_handler_deallocate(
void* ptr, std::size_t size, handler_wrapper<Handler>* h)
{
asio_handler_deallocate(ptr, size, &h->m_handler);
}
private:
Handler m_handler;
bool& m_in_flight;

View File

@ -1431,7 +1431,11 @@ namespace libtorrent {
// used to post a message to defer disconnecting peers
std::vector<std::shared_ptr<peer_connection>> m_peers_to_disconnect;
aux::deferred_handler m_deferred_disconnect;
aux::handler_storage<24> m_deferred_handler_storage;
#ifdef _M_AMD64
aux::handler_storage<96> m_deferred_handler_storage;
#else
aux::handler_storage<64> m_deferred_handler_storage;
#endif
// for torrents who have a bandwidth limit, this is != 0
// and refers to a peer_class in the session.