Chris@16: // Chris@16: // detail/resolver_service_base.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_RESOLVER_SERVICE_BASE_HPP Chris@16: #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_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: #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: class resolver_service_base Chris@16: { Chris@16: public: Chris@16: // The implementation type of the resolver. A cancellation token is used to Chris@16: // indicate to the background thread that the operation has been cancelled. Chris@16: typedef socket_ops::shared_cancel_token_type implementation_type; Chris@16: Chris@16: // Constructor. Chris@16: BOOST_ASIO_DECL resolver_service_base(boost::asio::io_service& io_service); Chris@16: Chris@16: // Destructor. Chris@16: BOOST_ASIO_DECL ~resolver_service_base(); Chris@16: Chris@16: // Destroy all user-defined handler objects owned by the service. Chris@16: BOOST_ASIO_DECL void shutdown_service(); Chris@16: Chris@16: // Perform any fork-related housekeeping. Chris@16: BOOST_ASIO_DECL void fork_service( Chris@16: boost::asio::io_service::fork_event fork_ev); Chris@16: Chris@16: // Construct a new resolver implementation. Chris@16: BOOST_ASIO_DECL void construct(implementation_type& impl); Chris@16: Chris@16: // Destroy a resolver implementation. Chris@16: BOOST_ASIO_DECL void destroy(implementation_type&); Chris@16: Chris@16: // Cancel pending asynchronous operations. Chris@16: BOOST_ASIO_DECL void cancel(implementation_type& impl); Chris@16: Chris@16: protected: Chris@16: // Helper function to start an asynchronous resolve operation. Chris@16: BOOST_ASIO_DECL void start_resolve_op(operation* op); Chris@16: Chris@16: #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: // Helper class to perform exception-safe cleanup of addrinfo objects. Chris@16: class auto_addrinfo Chris@16: : private boost::asio::detail::noncopyable Chris@16: { Chris@16: public: Chris@16: explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai) Chris@16: : ai_(ai) Chris@16: { Chris@16: } Chris@16: Chris@16: ~auto_addrinfo() Chris@16: { Chris@16: if (ai_) Chris@16: socket_ops::freeaddrinfo(ai_); Chris@16: } Chris@16: Chris@16: operator boost::asio::detail::addrinfo_type*() Chris@16: { Chris@16: return ai_; Chris@16: } Chris@16: Chris@16: private: Chris@16: boost::asio::detail::addrinfo_type* ai_; Chris@16: }; Chris@16: #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: // Helper class to run the work io_service in a thread. Chris@16: class work_io_service_runner; Chris@16: Chris@16: // Start the work thread if it's not already running. Chris@16: BOOST_ASIO_DECL void start_work_thread(); Chris@16: Chris@16: // The io_service implementation used to post completions. Chris@16: io_service_impl& io_service_impl_; Chris@16: Chris@16: private: Chris@16: // Mutex to protect access to internal data. Chris@16: boost::asio::detail::mutex mutex_; Chris@16: Chris@16: // Private io_service used for performing asynchronous host resolution. Chris@16: boost::asio::detail::scoped_ptr work_io_service_; Chris@16: Chris@16: // The work io_service implementation used to post completions. Chris@16: io_service_impl& work_io_service_impl_; Chris@16: Chris@16: // Work for the private io_service to perform. Chris@16: boost::asio::detail::scoped_ptr work_; Chris@16: Chris@16: // Thread used for running the work io_service's run loop. Chris@16: boost::asio::detail::scoped_ptr work_thread_; 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: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP