Chris@16: // Chris@16: // ip/resolver_service.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_IP_RESOLVER_SERVICE_HPP Chris@16: #define BOOST_ASIO_IP_RESOLVER_SERVICE_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: #if defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: # include Chris@16: #else Chris@16: # include Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ip { Chris@16: Chris@16: /// Default service implementation for a resolver. Chris@16: template Chris@16: class resolver_service Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: : public boost::asio::io_service::service Chris@16: #else Chris@16: : public boost::asio::detail::service_base< Chris@16: resolver_service > Chris@16: #endif Chris@16: { Chris@16: public: Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: /// The unique service identifier. Chris@16: static boost::asio::io_service::id id; Chris@16: #endif Chris@16: Chris@16: /// The protocol type. Chris@16: typedef InternetProtocol protocol_type; Chris@16: Chris@16: /// The endpoint type. Chris@16: typedef typename InternetProtocol::endpoint endpoint_type; Chris@16: Chris@16: /// The query type. Chris@16: typedef basic_resolver_query query_type; Chris@16: Chris@16: /// The iterator type. Chris@16: typedef basic_resolver_iterator iterator_type; Chris@16: Chris@16: private: Chris@16: // The type of the platform-specific implementation. Chris@16: #if defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: typedef boost::asio::detail::winrt_resolver_service Chris@16: service_impl_type; Chris@16: #else Chris@16: typedef boost::asio::detail::resolver_service Chris@16: service_impl_type; Chris@16: #endif Chris@16: Chris@16: public: Chris@16: /// The type of a resolver implementation. Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: typedef implementation_defined implementation_type; Chris@16: #else Chris@16: typedef typename service_impl_type::implementation_type implementation_type; Chris@16: #endif Chris@16: Chris@16: /// Construct a new resolver service for the specified io_service. Chris@16: explicit resolver_service(boost::asio::io_service& io_service) Chris@16: : boost::asio::detail::service_base< Chris@16: resolver_service >(io_service), Chris@16: service_impl_(io_service) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct a new resolver implementation. Chris@16: void construct(implementation_type& impl) Chris@16: { Chris@16: service_impl_.construct(impl); Chris@16: } Chris@16: Chris@16: /// Destroy a resolver implementation. Chris@16: void destroy(implementation_type& impl) Chris@16: { Chris@16: service_impl_.destroy(impl); Chris@16: } Chris@16: Chris@16: /// Cancel pending asynchronous operations. Chris@16: void cancel(implementation_type& impl) Chris@16: { Chris@16: service_impl_.cancel(impl); Chris@16: } Chris@16: Chris@16: /// Resolve a query to a list of entries. Chris@16: iterator_type resolve(implementation_type& impl, const query_type& query, Chris@16: boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.resolve(impl, query, ec); Chris@16: } Chris@16: Chris@16: /// Asynchronously resolve a query to a list of entries. Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler, Chris@16: void (boost::system::error_code, iterator_type)) Chris@16: async_resolve(implementation_type& impl, const query_type& query, Chris@16: BOOST_ASIO_MOVE_ARG(ResolveHandler) handler) Chris@16: { Chris@16: boost::asio::detail::async_result_init< Chris@16: ResolveHandler, void (boost::system::error_code, iterator_type)> init( Chris@16: BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler)); Chris@16: Chris@16: service_impl_.async_resolve(impl, query, init.handler); Chris@16: Chris@16: return init.result.get(); Chris@16: } Chris@16: Chris@16: /// Resolve an endpoint to a list of entries. Chris@16: iterator_type resolve(implementation_type& impl, Chris@16: const endpoint_type& endpoint, boost::system::error_code& ec) Chris@16: { Chris@16: return service_impl_.resolve(impl, endpoint, ec); Chris@16: } Chris@16: Chris@16: /// Asynchronously resolve an endpoint to a list of entries. Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler, Chris@16: void (boost::system::error_code, iterator_type)) Chris@16: async_resolve(implementation_type& impl, const endpoint_type& endpoint, Chris@16: BOOST_ASIO_MOVE_ARG(ResolveHandler) handler) Chris@16: { Chris@16: boost::asio::detail::async_result_init< Chris@16: ResolveHandler, void (boost::system::error_code, iterator_type)> init( Chris@16: BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler)); Chris@16: Chris@16: service_impl_.async_resolve(impl, endpoint, init.handler); Chris@16: Chris@16: return init.result.get(); Chris@16: } Chris@16: Chris@16: private: Chris@16: // Destroy all user-defined handler objects owned by the service. Chris@16: void shutdown_service() Chris@16: { Chris@16: service_impl_.shutdown_service(); Chris@16: } Chris@16: Chris@16: // Perform any fork-related housekeeping. Chris@16: void fork_service(boost::asio::io_service::fork_event event) Chris@16: { Chris@16: service_impl_.fork_service(event); Chris@16: } Chris@16: Chris@16: // The platform-specific implementation. Chris@16: service_impl_type service_impl_; Chris@16: }; Chris@16: Chris@16: } // namespace ip Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP