File indexing completed on 2025-01-18 09:28:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP
0012 #define BOOST_ASIO_DETAIL_COMPLETION_HANDLER_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/fenced_block.hpp>
0020 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0021 #include <boost/asio/detail/handler_work.hpp>
0022 #include <boost/asio/detail/memory.hpp>
0023 #include <boost/asio/detail/operation.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030
0031 template <typename Handler, typename IoExecutor>
0032 class completion_handler : public operation
0033 {
0034 public:
0035 BOOST_ASIO_DEFINE_HANDLER_PTR(completion_handler);
0036
0037 completion_handler(Handler& h, const IoExecutor& io_ex)
0038 : operation(&completion_handler::do_complete),
0039 handler_(static_cast<Handler&&>(h)),
0040 work_(handler_, io_ex)
0041 {
0042 }
0043
0044 static void do_complete(void* owner, operation* base,
0045 const boost::system::error_code& ,
0046 std::size_t )
0047 {
0048
0049 completion_handler* h(static_cast<completion_handler*>(base));
0050 ptr p = { boost::asio::detail::addressof(h->handler_), h, h };
0051
0052 BOOST_ASIO_HANDLER_COMPLETION((*h));
0053
0054
0055 handler_work<Handler, IoExecutor> w(
0056 static_cast<handler_work<Handler, IoExecutor>&&>(
0057 h->work_));
0058
0059
0060
0061
0062
0063
0064
0065 Handler handler(static_cast<Handler&&>(h->handler_));
0066 p.h = boost::asio::detail::addressof(handler);
0067 p.reset();
0068
0069
0070 if (owner)
0071 {
0072 fenced_block b(fenced_block::half);
0073 BOOST_ASIO_HANDLER_INVOCATION_BEGIN(());
0074 w.complete(handler, handler);
0075 BOOST_ASIO_HANDLER_INVOCATION_END;
0076 }
0077 }
0078
0079 private:
0080 Handler handler_;
0081 handler_work<Handler, IoExecutor> work_;
0082 };
0083
0084 }
0085 }
0086 }
0087
0088 #include <boost/asio/detail/pop_options.hpp>
0089
0090 #endif