2 // detail/resolver_service_base.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2011 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_RESOLVER_SERVICE_BASE_HPP
12 #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
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/error.hpp>
20 #include <boost/asio/io_service.hpp>
21 #include <boost/asio/detail/mutex.hpp>
22 #include <boost/asio/detail/noncopyable.hpp>
23 #include <boost/asio/detail/operation.hpp>
24 #include <boost/asio/detail/socket_ops.hpp>
25 #include <boost/asio/detail/socket_types.hpp>
26 #include <boost/asio/detail/scoped_ptr.hpp>
27 #include <boost/asio/detail/thread.hpp>
29 #include <boost/asio/detail/push_options.hpp>
35 class resolver_service_base
38 // The implementation type of the resolver. A cancellation token is used to
39 // indicate to the background thread that the operation has been cancelled.
40 typedef socket_ops::shared_cancel_token_type implementation_type;
43 BOOST_ASIO_DECL resolver_service_base(boost::asio::io_service& io_service);
46 BOOST_ASIO_DECL ~resolver_service_base();
48 // Destroy all user-defined handler objects owned by the service.
49 BOOST_ASIO_DECL void shutdown_service();
51 // Perform any fork-related housekeeping.
52 BOOST_ASIO_DECL void fork_service(
53 boost::asio::io_service::fork_event fork_ev);
55 // Construct a new resolver implementation.
56 BOOST_ASIO_DECL void construct(implementation_type& impl);
58 // Destroy a resolver implementation.
59 BOOST_ASIO_DECL void destroy(implementation_type&);
61 // Cancel pending asynchronous operations.
62 BOOST_ASIO_DECL void cancel(implementation_type& impl);
65 // Helper function to start an asynchronous resolve operation.
66 BOOST_ASIO_DECL void start_resolve_op(operation* op);
68 // Helper class to perform exception-safe cleanup of addrinfo objects.
70 : private boost::asio::detail::noncopyable
73 explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai)
81 socket_ops::freeaddrinfo(ai_);
84 operator boost::asio::detail::addrinfo_type*()
90 boost::asio::detail::addrinfo_type* ai_;
93 // Helper class to run the work io_service in a thread.
94 class work_io_service_runner;
96 // Start the work thread if it's not already running.
97 BOOST_ASIO_DECL void start_work_thread();
99 // The io_service implementation used to post completions.
100 io_service_impl& io_service_impl_;
103 // Mutex to protect access to internal data.
104 boost::asio::detail::mutex mutex_;
106 // Private io_service used for performing asynchronous host resolution.
107 boost::asio::detail::scoped_ptr<boost::asio::io_service> work_io_service_;
109 // The work io_service implementation used to post completions.
110 io_service_impl& work_io_service_impl_;
112 // Work for the private io_service to perform.
113 boost::asio::detail::scoped_ptr<boost::asio::io_service::work> work_;
115 // Thread used for running the work io_service's run loop.
116 boost::asio::detail::scoped_ptr<boost::asio::detail::thread> work_thread_;
119 } // namespace detail
123 #include <boost/asio/detail/pop_options.hpp>
125 #if defined(BOOST_ASIO_HEADER_ONLY)
126 # include <boost/asio/detail/impl/resolver_service_base.ipp>
127 #endif // defined(BOOST_ASIO_HEADER_ONLY)
129 #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP