/Src/Dependencies/Boost/boost/asio/detail/resolver_service_base.hpp

http://hadesmem.googlecode.com/ · C++ Header · 129 lines · 71 code · 30 blank · 28 comment · 2 complexity · 08eb38e7fc3378c227bddcff637f12e5 MD5 · raw file

  1. //
  2. // detail/resolver_service_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  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)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
  11. #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/error.hpp>
  17. #include <boost/asio/io_service.hpp>
  18. #include <boost/asio/detail/mutex.hpp>
  19. #include <boost/asio/detail/noncopyable.hpp>
  20. #include <boost/asio/detail/operation.hpp>
  21. #include <boost/asio/detail/socket_ops.hpp>
  22. #include <boost/asio/detail/socket_types.hpp>
  23. #include <boost/asio/detail/scoped_ptr.hpp>
  24. #include <boost/asio/detail/thread.hpp>
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. namespace detail {
  29. class resolver_service_base
  30. {
  31. public:
  32. // The implementation type of the resolver. A cancellation token is used to
  33. // indicate to the background thread that the operation has been cancelled.
  34. typedef socket_ops::shared_cancel_token_type implementation_type;
  35. // Constructor.
  36. BOOST_ASIO_DECL resolver_service_base(boost::asio::io_service& io_service);
  37. // Destructor.
  38. BOOST_ASIO_DECL ~resolver_service_base();
  39. // Destroy all user-defined handler objects owned by the service.
  40. BOOST_ASIO_DECL void shutdown_service();
  41. // Perform any fork-related housekeeping.
  42. BOOST_ASIO_DECL void fork_service(
  43. boost::asio::io_service::fork_event fork_ev);
  44. // Construct a new resolver implementation.
  45. BOOST_ASIO_DECL void construct(implementation_type& impl);
  46. // Destroy a resolver implementation.
  47. BOOST_ASIO_DECL void destroy(implementation_type&);
  48. // Cancel pending asynchronous operations.
  49. BOOST_ASIO_DECL void cancel(implementation_type& impl);
  50. protected:
  51. // Helper function to start an asynchronous resolve operation.
  52. BOOST_ASIO_DECL void start_resolve_op(operation* op);
  53. // Helper class to perform exception-safe cleanup of addrinfo objects.
  54. class auto_addrinfo
  55. : private boost::asio::detail::noncopyable
  56. {
  57. public:
  58. explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai)
  59. : ai_(ai)
  60. {
  61. }
  62. ~auto_addrinfo()
  63. {
  64. if (ai_)
  65. socket_ops::freeaddrinfo(ai_);
  66. }
  67. operator boost::asio::detail::addrinfo_type*()
  68. {
  69. return ai_;
  70. }
  71. private:
  72. boost::asio::detail::addrinfo_type* ai_;
  73. };
  74. // Helper class to run the work io_service in a thread.
  75. class work_io_service_runner;
  76. // Start the work thread if it's not already running.
  77. BOOST_ASIO_DECL void start_work_thread();
  78. // The io_service implementation used to post completions.
  79. io_service_impl& io_service_impl_;
  80. private:
  81. // Mutex to protect access to internal data.
  82. boost::asio::detail::mutex mutex_;
  83. // Private io_service used for performing asynchronous host resolution.
  84. boost::asio::detail::scoped_ptr<boost::asio::io_service> work_io_service_;
  85. // The work io_service implementation used to post completions.
  86. io_service_impl& work_io_service_impl_;
  87. // Work for the private io_service to perform.
  88. boost::asio::detail::scoped_ptr<boost::asio::io_service::work> work_;
  89. // Thread used for running the work io_service's run loop.
  90. boost::asio::detail::scoped_ptr<boost::asio::detail::thread> work_thread_;
  91. };
  92. } // namespace detail
  93. } // namespace asio
  94. } // namespace boost
  95. #include <boost/asio/detail/pop_options.hpp>
  96. #if defined(BOOST_ASIO_HEADER_ONLY)
  97. # include <boost/asio/detail/impl/resolver_service_base.ipp>
  98. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  99. #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP