KISSCPP
a C++ library for rapid application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
io_service_pool.hpp
Go to the documentation of this file.
1 // File : io_service_pool.hpp
2 // Author: Dirk J. Botha <bothadj@gmail.com>
3 //
4 // This file is part of kisscpp library.
5 //
6 // The kisscpp library is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // The kisscpp library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with the kisscpp library. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _SERVER_IO_SERVICE_POOL_HPP
20 #define _SERVER_IO_SERVICE_POOL_HPP
21 
22 #include <stdexcept>
23 #include <vector>
24 #include <boost/asio.hpp>
25 #include <boost/bind.hpp>
26 #include <boost/noncopyable.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/thread/thread.hpp>
29 
30 namespace kisscpp
31 {
32  class IoServicePool : private boost::noncopyable
33  {
34  public:
35  explicit IoServicePool(std::size_t pool_size);
36  void run();
37  void stop();
38  boost::asio::io_service &get_io_service();
39 
40  private:
41  typedef boost::shared_ptr<boost::asio::io_service> io_service_ptr;
42  typedef boost::shared_ptr<boost::asio::io_service::work> work_ptr;
43 
44  std::vector<io_service_ptr> io_services_;
45  std::vector<work_ptr> work_;
46  std::size_t next_io_service_;
47  };
48 
49 } // namespace server
50 
51 #endif
Definition: io_service_pool.hpp:32
void run()
Construct the io_service pool.
Definition: io_service_pool.cpp:40
boost::asio::io_service & get_io_service()
Stop all io_service objects in the pool.
Definition: io_service_pool.cpp:65
void stop()
Run all io_service objects in the pool.
Definition: io_service_pool.cpp:56
IoServicePool(std::size_t pool_size)
Definition: io_service_pool.cpp:24