2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2014 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 // We wrote this code based on the original code which has the
28 // io_service_pool.hpp
29 // ~~~~~~~~~~~~~~~~~~~
31 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
33 // Distributed under the Boost Software License, Version 1.0. (See accompanying
34 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
37 #ifndef ASIO_IO_SERVICE_POOL_H
38 #define ASIO_IO_SERVICE_POOL_H
40 #include "nghttp2_config.h"
46 #include <boost/noncopyable.hpp>
47 #include <boost/thread.hpp>
49 #include <nghttp2/asio_http2.h>
53 namespace asio_http2 {
55 /// A pool of io_service objects.
56 class io_service_pool : private boost::noncopyable {
58 /// Construct the io_service pool.
59 explicit io_service_pool(std::size_t pool_size);
61 /// Run all io_service objects in the pool.
62 void run(bool asynchronous = false);
64 /// Stop all io_service objects in the pool.
67 /// Join on all io_service objects in the pool.
70 /// Get an io_service to use.
71 boost::asio::io_service &get_io_service();
74 /// The pool of io_services.
75 std::vector<std::shared_ptr<boost::asio::io_service>> io_services_;
77 /// The work that keeps the io_services running.
78 std::vector<std::shared_ptr<boost::asio::io_service::work>> work_;
80 /// The next io_service to use for a connection.
81 std::size_t next_io_service_;
83 /// Futures to all the io_service objects
84 std::vector<std::future<std::size_t>> futures_;
87 } // namespace asio_http2
89 } // namespace nghttp2
91 #endif // ASIO_IO_SERVICE_POOL_H