io_context.ipp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // impl/io_context.ipp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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. shutdown();
  49. }
  50. io_context::count_type io_context::run()
  51. {
  52. boost::system::error_code ec;
  53. count_type s = impl_.run(ec);
  54. boost::asio::detail::throw_error(ec);
  55. return s;
  56. }
  57. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  58. io_context::count_type io_context::run(boost::system::error_code& ec)
  59. {
  60. return impl_.run(ec);
  61. }
  62. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  63. io_context::count_type io_context::run_one()
  64. {
  65. boost::system::error_code ec;
  66. count_type s = impl_.run_one(ec);
  67. boost::asio::detail::throw_error(ec);
  68. return s;
  69. }
  70. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  71. io_context::count_type io_context::run_one(boost::system::error_code& ec)
  72. {
  73. return impl_.run_one(ec);
  74. }
  75. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  76. io_context::count_type io_context::poll()
  77. {
  78. boost::system::error_code ec;
  79. count_type s = impl_.poll(ec);
  80. boost::asio::detail::throw_error(ec);
  81. return s;
  82. }
  83. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  84. io_context::count_type io_context::poll(boost::system::error_code& ec)
  85. {
  86. return impl_.poll(ec);
  87. }
  88. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  89. io_context::count_type io_context::poll_one()
  90. {
  91. boost::system::error_code ec;
  92. count_type s = impl_.poll_one(ec);
  93. boost::asio::detail::throw_error(ec);
  94. return s;
  95. }
  96. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  97. io_context::count_type io_context::poll_one(boost::system::error_code& ec)
  98. {
  99. return impl_.poll_one(ec);
  100. }
  101. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  102. void io_context::stop()
  103. {
  104. impl_.stop();
  105. }
  106. bool io_context::stopped() const
  107. {
  108. return impl_.stopped();
  109. }
  110. void io_context::restart()
  111. {
  112. impl_.restart();
  113. }
  114. io_context::service::service(boost::asio::io_context& owner)
  115. : execution_context::service(owner)
  116. {
  117. }
  118. io_context::service::~service()
  119. {
  120. }
  121. void io_context::service::shutdown()
  122. {
  123. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  124. shutdown_service();
  125. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  126. }
  127. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  128. void io_context::service::shutdown_service()
  129. {
  130. }
  131. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  132. void io_context::service::notify_fork(io_context::fork_event ev)
  133. {
  134. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  135. fork_service(ev);
  136. #else // !defined(BOOST_ASIO_NO_DEPRECATED)
  137. (void)ev;
  138. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  139. }
  140. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  141. void io_context::service::fork_service(io_context::fork_event)
  142. {
  143. }
  144. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  145. } // namespace asio
  146. } // namespace boost
  147. #include <boost/asio/detail/pop_options.hpp>
  148. #endif // BOOST_ASIO_IMPL_IO_CONTEXT_IPP