io_context.ipp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // impl/io_context.ipp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2025 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/config.hpp>
  17. #include <boost/asio/io_context.hpp>
  18. #include <boost/asio/detail/concurrency_hint.hpp>
  19. #include <boost/asio/detail/limits.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. : execution_context(config_from_concurrency_hint()),
  32. impl_(boost::asio::make_service<impl_type>(*this, false))
  33. {
  34. }
  35. io_context::io_context(int concurrency_hint)
  36. : execution_context(config_from_concurrency_hint(concurrency_hint)),
  37. impl_(boost::asio::make_service<impl_type>(*this, false))
  38. {
  39. }
  40. io_context::io_context(const execution_context::service_maker& initial_services)
  41. : execution_context(initial_services),
  42. impl_(boost::asio::make_service<impl_type>(*this, false))
  43. {
  44. }
  45. io_context::~io_context()
  46. {
  47. shutdown();
  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. io_context::count_type io_context::run_one()
  57. {
  58. boost::system::error_code ec;
  59. count_type s = impl_.run_one(ec);
  60. boost::asio::detail::throw_error(ec);
  61. return s;
  62. }
  63. io_context::count_type io_context::poll()
  64. {
  65. boost::system::error_code ec;
  66. count_type s = impl_.poll(ec);
  67. boost::asio::detail::throw_error(ec);
  68. return s;
  69. }
  70. io_context::count_type io_context::poll_one()
  71. {
  72. boost::system::error_code ec;
  73. count_type s = impl_.poll_one(ec);
  74. boost::asio::detail::throw_error(ec);
  75. return s;
  76. }
  77. void io_context::stop()
  78. {
  79. impl_.stop();
  80. }
  81. bool io_context::stopped() const
  82. {
  83. return impl_.stopped();
  84. }
  85. void io_context::restart()
  86. {
  87. impl_.restart();
  88. }
  89. io_context::service::service(boost::asio::io_context& owner)
  90. : execution_context::service(owner)
  91. {
  92. }
  93. io_context::service::~service()
  94. {
  95. }
  96. void io_context::service::shutdown()
  97. {
  98. }
  99. void io_context::service::notify_fork(io_context::fork_event)
  100. {
  101. }
  102. } // namespace asio
  103. } // namespace boost
  104. #include <boost/asio/detail/pop_options.hpp>
  105. #endif // BOOST_ASIO_IMPL_IO_CONTEXT_IPP