Chris@16: // Chris@16: // detail/reactive_null_buffers_op.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_REACTIVE_NULL_BUFFERS_OP_HPP Chris@16: #define BOOST_ASIO_DETAIL_REACTIVE_NULL_BUFFERS_OP_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: class reactive_null_buffers_op : public reactor_op Chris@16: { Chris@16: public: Chris@16: BOOST_ASIO_DEFINE_HANDLER_PTR(reactive_null_buffers_op); Chris@16: Chris@16: reactive_null_buffers_op(Handler& handler) Chris@16: : reactor_op(&reactive_null_buffers_op::do_perform, Chris@16: &reactive_null_buffers_op::do_complete), Chris@16: handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)) Chris@16: { Chris@16: } Chris@16: Chris@16: static bool do_perform(reactor_op*) Chris@16: { Chris@16: return true; Chris@16: } Chris@16: Chris@16: static void do_complete(io_service_impl* owner, operation* base, Chris@16: const boost::system::error_code& /*ec*/, Chris@16: std::size_t /*bytes_transferred*/) Chris@16: { Chris@16: // Take ownership of the handler object. Chris@16: reactive_null_buffers_op* o(static_cast(base)); Chris@16: ptr p = { boost::asio::detail::addressof(o->handler_), o, o }; Chris@16: Chris@16: BOOST_ASIO_HANDLER_COMPLETION((o)); Chris@16: Chris@16: // Make a copy of the handler so that the memory can be deallocated before Chris@16: // the upcall is made. Even if we're not about to make an upcall, a Chris@16: // sub-object of the handler may be the true owner of the memory associated Chris@16: // with the handler. Consequently, a local copy of the handler is required Chris@16: // to ensure that any owning sub-object remains valid until after we have Chris@16: // deallocated the memory here. Chris@16: detail::binder2 Chris@16: handler(o->handler_, o->ec_, o->bytes_transferred_); Chris@16: p.h = boost::asio::detail::addressof(handler.handler_); Chris@16: p.reset(); Chris@16: Chris@16: // Make the upcall if required. Chris@16: if (owner) Chris@16: { Chris@16: fenced_block b(fenced_block::half); Chris@16: BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_)); Chris@16: boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_); Chris@16: BOOST_ASIO_HANDLER_INVOCATION_END; Chris@16: } Chris@16: } Chris@16: Chris@16: private: Chris@16: Handler handler_; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_REACTIVE_NULL_BUFFERS_OP_HPP