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