2 // detail/impl/resolver_service_base.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/resolver_service_base.hpp>
21 #include <boost/asio/detail/push_options.hpp>
27 class resolver_service_base::work_scheduler_runner
30 work_scheduler_runner(scheduler_impl& work_scheduler)
31 : work_scheduler_(work_scheduler)
37 boost::system::error_code ec;
38 work_scheduler_.run(ec);
42 scheduler_impl& work_scheduler_;
45 resolver_service_base::resolver_service_base(execution_context& context)
46 : scheduler_(boost::asio::use_service<scheduler_impl>(context)),
47 work_scheduler_(new scheduler_impl(context, -1, false)),
50 work_scheduler_->work_started();
53 resolver_service_base::~resolver_service_base()
58 void resolver_service_base::base_shutdown()
60 if (work_scheduler_.get())
62 work_scheduler_->work_finished();
63 work_scheduler_->stop();
64 if (work_thread_.get())
69 work_scheduler_.reset();
73 void resolver_service_base::base_notify_fork(
74 execution_context::fork_event fork_ev)
76 if (work_thread_.get())
78 if (fork_ev == execution_context::fork_prepare)
80 work_scheduler_->stop();
86 work_scheduler_->restart();
87 work_thread_.reset(new boost::asio::detail::thread(
88 work_scheduler_runner(*work_scheduler_)));
93 void resolver_service_base::construct(
94 resolver_service_base::implementation_type& impl)
96 impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
99 void resolver_service_base::destroy(
100 resolver_service_base::implementation_type& impl)
102 BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(),
103 "resolver", &impl, 0, "cancel"));
108 void resolver_service_base::move_construct(implementation_type& impl,
109 implementation_type& other_impl)
111 impl = BOOST_ASIO_MOVE_CAST(implementation_type)(other_impl);
114 void resolver_service_base::move_assign(implementation_type& impl,
115 resolver_service_base&, implementation_type& other_impl)
118 impl = BOOST_ASIO_MOVE_CAST(implementation_type)(other_impl);
121 void resolver_service_base::cancel(
122 resolver_service_base::implementation_type& impl)
124 BOOST_ASIO_HANDLER_OPERATION((scheduler_.context(),
125 "resolver", &impl, 0, "cancel"));
127 impl.reset(static_cast<void*>(0), socket_ops::noop_deleter());
130 void resolver_service_base::start_resolve_op(resolve_op* op)
132 if (BOOST_ASIO_CONCURRENCY_HINT_IS_LOCKING(SCHEDULER,
133 scheduler_.concurrency_hint()))
136 scheduler_.work_started();
137 work_scheduler_->post_immediate_completion(op, false);
141 op->ec_ = boost::asio::error::operation_not_supported;
142 scheduler_.post_immediate_completion(op, false);
146 void resolver_service_base::start_work_thread()
148 boost::asio::detail::mutex::scoped_lock lock(mutex_);
149 if (!work_thread_.get())
151 work_thread_.reset(new boost::asio::detail::thread(
152 work_scheduler_runner(*work_scheduler_)));
156 } // namespace detail
160 #include <boost/asio/detail/pop_options.hpp>
162 #endif // BOOST_ASIO_DETAIL_IMPL_RESOLVER_SERVICE_BASE_IPP