io_service.ipp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // impl/io_service.ipp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_IMPL_IO_SERVICE_IPP
  11. #define ASIO_IMPL_IO_SERVICE_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/io_service.hpp"
  17. #include "asio/detail/limits.hpp"
  18. #include "asio/detail/scoped_ptr.hpp"
  19. #include "asio/detail/service_registry.hpp"
  20. #include "asio/detail/throw_error.hpp"
  21. #if defined(ASIO_HAS_IOCP)
  22. # include "asio/detail/win_iocp_io_service.hpp"
  23. #else
  24. # include "asio/detail/task_io_service.hpp"
  25. #endif
  26. #include "asio/detail/push_options.hpp"
  27. namespace asio {
  28. io_service::io_service()
  29. : service_registry_(new asio::detail::service_registry(
  30. *this, static_cast<impl_type*>(0),
  31. (std::numeric_limits<std::size_t>::max)())),
  32. impl_(service_registry_->first_service<impl_type>())
  33. {
  34. }
  35. io_service::io_service(std::size_t concurrency_hint)
  36. : service_registry_(new asio::detail::service_registry(
  37. *this, static_cast<impl_type*>(0), concurrency_hint)),
  38. impl_(service_registry_->first_service<impl_type>())
  39. {
  40. }
  41. io_service::~io_service()
  42. {
  43. delete service_registry_;
  44. }
  45. std::size_t io_service::run()
  46. {
  47. asio::error_code ec;
  48. std::size_t s = impl_.run(ec);
  49. asio::detail::throw_error(ec);
  50. return s;
  51. }
  52. std::size_t io_service::run(asio::error_code& ec)
  53. {
  54. return impl_.run(ec);
  55. }
  56. std::size_t io_service::run_one()
  57. {
  58. asio::error_code ec;
  59. std::size_t s = impl_.run_one(ec);
  60. asio::detail::throw_error(ec);
  61. return s;
  62. }
  63. std::size_t io_service::run_one(asio::error_code& ec)
  64. {
  65. return impl_.run_one(ec);
  66. }
  67. std::size_t io_service::poll()
  68. {
  69. asio::error_code ec;
  70. std::size_t s = impl_.poll(ec);
  71. asio::detail::throw_error(ec);
  72. return s;
  73. }
  74. std::size_t io_service::poll(asio::error_code& ec)
  75. {
  76. return impl_.poll(ec);
  77. }
  78. std::size_t io_service::poll_one()
  79. {
  80. asio::error_code ec;
  81. std::size_t s = impl_.poll_one(ec);
  82. asio::detail::throw_error(ec);
  83. return s;
  84. }
  85. std::size_t io_service::poll_one(asio::error_code& ec)
  86. {
  87. return impl_.poll_one(ec);
  88. }
  89. void io_service::stop()
  90. {
  91. impl_.stop();
  92. }
  93. bool io_service::stopped() const
  94. {
  95. return impl_.stopped();
  96. }
  97. void io_service::reset()
  98. {
  99. impl_.reset();
  100. }
  101. void io_service::notify_fork(asio::io_service::fork_event event)
  102. {
  103. service_registry_->notify_fork(event);
  104. }
  105. io_service::service::service(asio::io_service& owner)
  106. : owner_(owner),
  107. next_(0)
  108. {
  109. }
  110. io_service::service::~service()
  111. {
  112. }
  113. void io_service::service::fork_service(asio::io_service::fork_event)
  114. {
  115. }
  116. service_already_exists::service_already_exists()
  117. : std::logic_error("Service already exists.")
  118. {
  119. }
  120. invalid_service_owner::invalid_service_owner()
  121. : std::logic_error("Invalid service owner.")
  122. {
  123. }
  124. } // namespace asio
  125. #include "asio/detail/pop_options.hpp"
  126. #endif // ASIO_IMPL_IO_SERVICE_IPP