From 56ca5fa63cd6fccd2eddb6d795cfb2131e4275ce Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 25 Dec 2017 09:02:18 +0100 Subject: [PATCH] support asio handler allocators in deferred_handler --- include/libtorrent/aux_/allocating_handler.hpp | 4 ++-- include/libtorrent/aux_/deferred_handler.hpp | 14 ++++++++++++++ include/libtorrent/torrent.hpp | 6 +++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/aux_/allocating_handler.hpp b/include/libtorrent/aux_/allocating_handler.hpp index a66d3d689..d5d386ce0 100644 --- a/include/libtorrent/aux_/allocating_handler.hpp +++ b/include/libtorrent/aux_/allocating_handler.hpp @@ -120,7 +120,7 @@ namespace libtorrent { namespace aux { std::size_t size, allocating_handler* 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; diff --git a/include/libtorrent/aux_/deferred_handler.hpp b/include/libtorrent/aux_/deferred_handler.hpp index b8f5bec3d..ebb83be9b 100644 --- a/include/libtorrent/aux_/deferred_handler.hpp +++ b/include/libtorrent/aux_/deferred_handler.hpp @@ -51,6 +51,20 @@ struct handler_wrapper m_in_flight = false; m_handler(std::forward(a)...); } + + // forward asio handler allocator to the underlying handler's + friend void* asio_handler_allocate( + std::size_t size, handler_wrapper* h) + { + return asio_handler_allocate(size, &h->m_handler); + } + + friend void asio_handler_deallocate( + void* ptr, std::size_t size, handler_wrapper* h) + { + asio_handler_deallocate(ptr, size, &h->m_handler); + } + private: Handler m_handler; bool& m_in_flight; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 5334ff163..01478e7be 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1431,7 +1431,11 @@ namespace libtorrent { // used to post a message to defer disconnecting peers std::vector> 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.