Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:44

0001 //
0002 // detail/resolver_service_base.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
0012 #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/error.hpp>
0020 #include <boost/asio/execution_context.hpp>
0021 #include <boost/asio/detail/mutex.hpp>
0022 #include <boost/asio/detail/noncopyable.hpp>
0023 #include <boost/asio/detail/resolve_op.hpp>
0024 #include <boost/asio/detail/socket_ops.hpp>
0025 #include <boost/asio/detail/socket_types.hpp>
0026 #include <boost/asio/detail/scoped_ptr.hpp>
0027 #include <boost/asio/detail/thread.hpp>
0028 
0029 #if defined(BOOST_ASIO_HAS_IOCP)
0030 # include <boost/asio/detail/win_iocp_io_context.hpp>
0031 #else // defined(BOOST_ASIO_HAS_IOCP)
0032 # include <boost/asio/detail/scheduler.hpp>
0033 #endif // defined(BOOST_ASIO_HAS_IOCP)
0034 
0035 #include <boost/asio/detail/push_options.hpp>
0036 
0037 namespace boost {
0038 namespace asio {
0039 namespace detail {
0040 
0041 class resolver_service_base
0042 {
0043 public:
0044   // The implementation type of the resolver. A cancellation token is used to
0045   // indicate to the background thread that the operation has been cancelled.
0046   typedef socket_ops::shared_cancel_token_type implementation_type;
0047 
0048   // Constructor.
0049   BOOST_ASIO_DECL resolver_service_base(execution_context& context);
0050 
0051   // Destructor.
0052   BOOST_ASIO_DECL ~resolver_service_base();
0053 
0054   // Destroy all user-defined handler objects owned by the service.
0055   BOOST_ASIO_DECL void base_shutdown();
0056 
0057   // Perform any fork-related housekeeping.
0058   BOOST_ASIO_DECL void base_notify_fork(
0059       execution_context::fork_event fork_ev);
0060 
0061   // Construct a new resolver implementation.
0062   BOOST_ASIO_DECL void construct(implementation_type& impl);
0063 
0064   // Destroy a resolver implementation.
0065   BOOST_ASIO_DECL void destroy(implementation_type&);
0066 
0067   // Move-construct a new resolver implementation.
0068   BOOST_ASIO_DECL void move_construct(implementation_type& impl,
0069       implementation_type& other_impl);
0070 
0071   // Move-assign from another resolver implementation.
0072   BOOST_ASIO_DECL void move_assign(implementation_type& impl,
0073       resolver_service_base& other_service,
0074       implementation_type& other_impl);
0075 
0076   // Move-construct a new timer implementation.
0077   void converting_move_construct(implementation_type& impl,
0078       resolver_service_base&, implementation_type& other_impl)
0079   {
0080     move_construct(impl, other_impl);
0081   }
0082 
0083   // Move-assign from another timer implementation.
0084   void converting_move_assign(implementation_type& impl,
0085       resolver_service_base& other_service,
0086       implementation_type& other_impl)
0087   {
0088     move_assign(impl, other_service, other_impl);
0089   }
0090 
0091   // Cancel pending asynchronous operations.
0092   BOOST_ASIO_DECL void cancel(implementation_type& impl);
0093 
0094 protected:
0095   // Helper function to start an asynchronous resolve operation.
0096   BOOST_ASIO_DECL void start_resolve_op(resolve_op* op);
0097 
0098 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0099   // Helper class to perform exception-safe cleanup of addrinfo objects.
0100   class auto_addrinfo
0101     : private boost::asio::detail::noncopyable
0102   {
0103   public:
0104     explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai)
0105       : ai_(ai)
0106     {
0107     }
0108 
0109     ~auto_addrinfo()
0110     {
0111       if (ai_)
0112         socket_ops::freeaddrinfo(ai_);
0113     }
0114 
0115     operator boost::asio::detail::addrinfo_type*()
0116     {
0117       return ai_;
0118     }
0119 
0120   private:
0121     boost::asio::detail::addrinfo_type* ai_;
0122   };
0123 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0124 
0125   // Helper class to run the work scheduler in a thread.
0126   class work_scheduler_runner;
0127 
0128   // Start the work scheduler if it's not already running.
0129   BOOST_ASIO_DECL void start_work_thread();
0130 
0131   // The scheduler implementation used to post completions.
0132 #if defined(BOOST_ASIO_HAS_IOCP)
0133   typedef class win_iocp_io_context scheduler_impl;
0134 #else
0135   typedef class scheduler scheduler_impl;
0136 #endif
0137   scheduler_impl& scheduler_;
0138 
0139 private:
0140   // Mutex to protect access to internal data.
0141   boost::asio::detail::mutex mutex_;
0142 
0143   // Private scheduler used for performing asynchronous host resolution.
0144   boost::asio::detail::scoped_ptr<scheduler_impl> work_scheduler_;
0145 
0146   // Thread used for running the work io_context's run loop.
0147   boost::asio::detail::scoped_ptr<boost::asio::detail::thread> work_thread_;
0148 };
0149 
0150 } // namespace detail
0151 } // namespace asio
0152 } // namespace boost
0153 
0154 #include <boost/asio/detail/pop_options.hpp>
0155 
0156 #if defined(BOOST_ASIO_HEADER_ONLY)
0157 # include <boost/asio/detail/impl/resolver_service_base.ipp>
0158 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0159 
0160 #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP