2014-09-21 11:28:06 +02:00
|
|
|
/*
|
|
|
|
* nghttp2 - HTTP/2 C Library
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
// We wrote this code based on the original code which has the
|
|
|
|
// following license:
|
|
|
|
//
|
|
|
|
// io_service_pool.hpp
|
|
|
|
// ~~~~~~~~~~~~~~~~~~~
|
|
|
|
//
|
|
|
|
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
#ifndef ASIO_IO_SERVICE_POOL_H
|
|
|
|
#define ASIO_IO_SERVICE_POOL_H
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
#include "nghttp2_config.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2015-04-22 11:51:28 +02:00
|
|
|
#include <future>
|
2015-03-03 18:43:13 +01:00
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
#include <boost/noncopyable.hpp>
|
2014-09-28 09:17:43 +02:00
|
|
|
#include <boost/thread.hpp>
|
2014-09-21 11:28:06 +02:00
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
#include <nghttp2/asio_http2.h>
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
namespace nghttp2 {
|
|
|
|
|
|
|
|
namespace asio_http2 {
|
|
|
|
|
|
|
|
/// A pool of io_service objects.
|
2014-11-27 15:39:04 +01:00
|
|
|
class io_service_pool : private boost::noncopyable {
|
2014-09-21 11:28:06 +02:00
|
|
|
public:
|
|
|
|
/// Construct the io_service pool.
|
2015-03-03 17:46:59 +01:00
|
|
|
explicit io_service_pool(std::size_t pool_size);
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
/// Run all io_service objects in the pool.
|
2015-04-22 11:51:28 +02:00
|
|
|
void run(bool asynchronous = false);
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
/// Stop all io_service objects in the pool.
|
2017-02-10 05:34:19 +01:00
|
|
|
void force_stop();
|
|
|
|
|
|
|
|
/// Destroy all work objects to signals end of work
|
2014-09-21 11:28:06 +02:00
|
|
|
void stop();
|
|
|
|
|
2015-04-22 11:51:28 +02:00
|
|
|
/// Join on all io_service objects in the pool.
|
|
|
|
void join();
|
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
/// Get an io_service to use.
|
2014-11-27 15:39:04 +01:00
|
|
|
boost::asio::io_service &get_io_service();
|
2014-09-21 11:28:06 +02:00
|
|
|
|
2015-12-08 15:47:04 +01:00
|
|
|
/// Get access to all io_service objects.
|
2015-12-20 04:48:39 +01:00
|
|
|
const std::vector<std::shared_ptr<boost::asio::io_service>> &
|
2015-12-25 13:06:25 +01:00
|
|
|
io_services() const;
|
2015-12-08 15:47:04 +01:00
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
private:
|
|
|
|
/// The pool of io_services.
|
2015-03-03 17:46:59 +01:00
|
|
|
std::vector<std::shared_ptr<boost::asio::io_service>> io_services_;
|
2014-09-28 09:17:43 +02:00
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
/// The work that keeps the io_services running.
|
2015-03-03 17:46:59 +01:00
|
|
|
std::vector<std::shared_ptr<boost::asio::io_service::work>> work_;
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
/// The next io_service to use for a connection.
|
|
|
|
std::size_t next_io_service_;
|
2015-04-22 11:51:28 +02:00
|
|
|
|
|
|
|
/// Futures to all the io_service objects
|
|
|
|
std::vector<std::future<std::size_t>> futures_;
|
2014-09-21 11:28:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace asio_http2
|
|
|
|
|
|
|
|
} // namespace nghttp2
|
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
#endif // ASIO_IO_SERVICE_POOL_H
|