5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef HTTP_SERVER2_IO_SERVICE_POOL_HPP
12 #define HTTP_SERVER2_IO_SERVICE_POOL_HPP
14 #include <boost/asio.hpp>
17 #include <boost/noncopyable.hpp>
18 #include <boost/shared_ptr.hpp>
23 /// A pool of io_context objects.
25 : private boost::noncopyable
28 /// Construct the io_context pool.
29 explicit io_context_pool(std::size_t pool_size);
31 /// Run all io_context objects in the pool.
34 /// Stop all io_context objects in the pool.
37 /// Get an io_context to use.
38 boost::asio::io_context& get_io_context();
41 typedef boost::shared_ptr<boost::asio::io_context> io_context_ptr;
42 typedef boost::asio::executor_work_guard<
43 boost::asio::io_context::executor_type> io_context_work;
45 /// The pool of io_contexts.
46 std::vector<io_context_ptr> io_contexts_;
48 /// The work that keeps the io_contexts running.
49 std::list<io_context_work> work_;
51 /// The next io_context to use for a connection.
52 std::size_t next_io_context_;
55 } // namespace server2
58 #endif // HTTP_SERVER2_IO_SERVICE_POOL_HPP