diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp b/3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp index d78e6c8..6701fb3 100644 --- a/3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/completion_handler.hpp @@ -1,6 +1,6 @@ // -// completion_handler.hpp -// ~~~~~~~~~~~~~~~~~~~~~~ +// detail/completion_handler.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com) // @@ -15,13 +15,14 @@ # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) -#include <boost/asio/detail/push_options.hpp> - +#include <boost/asio/detail/config.hpp> #include <boost/asio/detail/fenced_block.hpp> #include <boost/asio/detail/handler_alloc_helpers.hpp> #include <boost/asio/detail/handler_invoke_helpers.hpp> #include <boost/asio/detail/operation.hpp> +#include <boost/asio/detail/push_options.hpp> + namespace boost { namespace asio { namespace detail { @@ -30,6 +31,8 @@ template <typename Handler> class completion_handler : public operation { public: + BOOST_ASIO_DEFINE_HANDLER_PTR(completion_handler); + completion_handler(Handler h) : operation(&completion_handler::do_complete), handler_(h) @@ -41,20 +44,21 @@ public: { // Take ownership of the handler object. completion_handler* h(static_cast<completion_handler*>(base)); - typedef handler_alloc_traits<Handler, completion_handler> alloc_traits; - handler_ptr<alloc_traits> ptr(h->handler_, h); + ptr p = { boost::addressof(h->handler_), h, h }; + + // Make a copy of the handler so that the memory can be deallocated before + // the upcall is made. Even if we're not about to make an upcall, a + // sub-object of the handler may be the true owner of the memory associated + // with the handler. Consequently, a local copy of the handler is required + // to ensure that any owning sub-object remains valid until after we have + // deallocated the memory here. + Handler handler(h->handler_); + p.h = boost::addressof(handler); + p.reset(); // Make the upcall if required. if (owner) { - // Make a copy of the handler so that the memory can be deallocated - // before the upcall is made. Even if we're not about to make an - // upcall, a sub-object of the handler may be the true owner of the - // memory associated with the handler. Consequently, a local copy of - // the handler is required to ensure that any owning sub-object remains - // valid until after we have deallocated the memory here. - Handler handler(h->handler_); - ptr.reset(); boost::asio::detail::fenced_block b; boost_asio_handler_invoke_helpers::invoke(handler, handler); } |