io_context.ipp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // impl/io_context.ipp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_IMPL_IO_CONTEXT_IPP
  11. #define BOOST_ASIO_IMPL_IO_CONTEXT_IPP
  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/io_context.hpp>
  17. #include <boost/asio/detail/concurrency_hint.hpp>
  18. #include <boost/asio/detail/limits.hpp>
  19. #include <boost/asio/detail/scoped_ptr.hpp>
  20. #include <boost/asio/detail/service_registry.hpp>
  21. #include <boost/asio/detail/throw_error.hpp>
  22. #if defined(BOOST_ASIO_HAS_IOCP)
  23. # include <boost/asio/detail/win_iocp_io_context.hpp>
  24. #else
  25. # include <boost/asio/detail/scheduler.hpp>
  26. #endif
  27. #include <boost/asio/detail/push_options.hpp>
  28. namespace boost {
  29. namespace asio {
  30. io_context::io_context()
  31. : impl_(add_impl(new impl_type(*this,
  32. BOOST_ASIO_CONCURRENCY_HINT_DEFAULT, false)))
  33. {
  34. }
  35. io_context::io_context(int concurrency_hint)
  36. : impl_(add_impl(new impl_type(*this, concurrency_hint == 1
  37. ? BOOST_ASIO_CONCURRENCY_HINT_1 : concurrency_hint, false)))
  38. {
  39. }
  40. io_context::impl_type& io_context::add_impl(io_context::impl_type* impl)
  41. {
  42. boost::asio::detail::scoped_ptr<impl_type> scoped_impl(impl);
  43. boost::asio::add_service<impl_type>(*this, scoped_impl.get());
  44. return *scoped_impl.release();
  45. }
  46. io_context::~io_context()
  47. {
  48. }
  49. io_context::count_type io_context::run()
  50. {
  51. boost::system::error_code ec;
  52. count_type s = impl_.run(ec);
  53. boost::asio::detail::throw_error(ec);
  54. return s;
  55. }
  56. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  57. io_context::count_type io_context::run(boost::system::error_code& ec)
  58. {
  59. return impl_.run(ec);
  60. }
  61. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  62. io_context::count_type io_context::run_one()
  63. {
  64. boost::system::error_code ec;
  65. count_type s = impl_.run_one(ec);
  66. boost::asio::detail::throw_error(ec);
  67. return s;
  68. }
  69. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  70. io_context::count_type io_context::run_one(boost::system::error_code& ec)
  71. {
  72. return impl_.run_one(ec);
  73. }
  74. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  75. io_context::count_type io_context::poll()
  76. {
  77. boost::system::error_code ec;
  78. count_type s = impl_.poll(ec);
  79. boost::asio::detail::throw_error(ec);
  80. return s;
  81. }
  82. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  83. io_context::count_type io_context::poll(boost::system::error_code& ec)
  84. {
  85. return impl_.poll(ec);
  86. }
  87. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  88. io_context::count_type io_context::poll_one()
  89. {
  90. boost::system::error_code ec;
  91. count_type s = impl_.poll_one(ec);
  92. boost::asio::detail::throw_error(ec);
  93. return s;
  94. }
  95. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  96. io_context::count_type io_context::poll_one(boost::system::error_code& ec)
  97. {
  98. return impl_.poll_one(ec);
  99. }
  100. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  101. void io_context::stop()
  102. {
  103. impl_.stop();
  104. }
  105. bool io_context::stopped() const
  106. {
  107. return impl_.stopped();
  108. }
  109. void io_context::restart()
  110. {
  111. impl_.restart();
  112. }
  113. io_context::service::service(boost::asio::io_context& owner)
  114. : execution_context::service(owner)
  115. {
  116. }
  117. io_context::service::~service()
  118. {
  119. }
  120. void io_context::service::shutdown()
  121. {
  122. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  123. shutdown_service();
  124. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  125. }
  126. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  127. void io_context::service::shutdown_service()
  128. {
  129. }
  130. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  131. void io_context::service::notify_fork(io_context::fork_event ev)
  132. {
  133. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  134. fork_service(ev);
  135. #else // !defined(BOOST_ASIO_NO_DEPRECATED)
  136. (void)ev;
  137. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  138. }
  139. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  140. void io_context::service::fork_service(io_context::fork_event)
  141. {
  142. }
  143. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  144. } // namespace asio
  145. } // namespace boost
  146. #include <boost/asio/detail/pop_options.hpp>
  147. #endif // BOOST_ASIO_IMPL_IO_CONTEXT_IPP