Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 946692
Collapse All | Expand All

(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/connection.cpp (-19 / +14 lines)
Lines 10-25 Link Here
10
10
11
#include "connection.hpp"
11
#include "connection.hpp"
12
#include <vector>
12
#include <vector>
13
#include <boost/bind.hpp>
13
#include <boost/bind/bind.hpp>
14
using namespace boost::placeholders;
14
#include "request_handler.hpp"
15
#include "request_handler.hpp"
15
#include <osg/Notify>
16
#include <osg/Notify>
16
17
17
namespace http {
18
namespace http {
18
namespace server {
19
namespace server {
19
20
20
connection::connection(asio::io_service& io_service,
21
connection::connection(boost::asio::io_context& io_context,
21
    request_handler& handler)
22
    request_handler& handler)
22
  : socket_(io_service),
23
  : socket_(io_context),
23
    request_handler_(handler)
24
    request_handler_(handler)
24
{
25
{
25
    OSG_DEBUG << "RestHttpDevice :: connection::connection" << std::endl;
26
    OSG_DEBUG << "RestHttpDevice :: connection::connection" << std::endl;
Lines 29-35 connection::~connection() Link Here
29
{
30
{
30
    OSG_DEBUG << "RestHttpDevice :: connection::~connection" << std::endl;
31
    OSG_DEBUG << "RestHttpDevice :: connection::~connection" << std::endl;
31
}
32
}
32
asio::ip::tcp::socket& connection::socket()
33
boost::asio::ip::tcp::socket& connection::socket()
33
{
34
{
34
  return socket_;
35
  return socket_;
35
}
36
}
Lines 38-47 void connection::start() Link Here
38
{
39
{
39
  OSG_DEBUG << "RestHttpDevice :: connection::start" << std::endl;
40
  OSG_DEBUG << "RestHttpDevice :: connection::start" << std::endl;
40
41
41
  socket_.async_read_some(asio::buffer(buffer_),
42
  socket_.async_read_some(boost::asio::buffer(buffer_),
42
      boost::bind(&connection::handle_read, shared_from_this(),
43
      boost::bind(&connection::handle_read, shared_from_this(), _1, _2));
43
        asio::placeholders::error,
44
        asio::placeholders::bytes_transferred));
45
}
44
}
46
45
47
void connection::handle_read(const boost::system::error_code& e,
46
void connection::handle_read(const boost::system::error_code& e,
Lines 56-78 void connection::handle_read(const boost Link Here
56
    if (result)
55
    if (result)
57
    {
56
    {
58
      request_handler_.handle_request(request_, reply_);
57
      request_handler_.handle_request(request_, reply_);
59
      asio::async_write(socket_, reply_.to_buffers(),
58
      boost::asio::async_write(socket_, reply_.to_buffers(),
60
          boost::bind(&connection::handle_write, shared_from_this(),
59
          boost::bind(&connection::handle_write, shared_from_this(), _1));
61
            asio::placeholders::error));
62
    }
60
    }
63
    else if (!result)
61
    else if (!result)
64
    {
62
    {
65
      reply_ = reply::stock_reply(reply::bad_request);
63
      reply_ = reply::stock_reply(reply::bad_request);
66
      asio::async_write(socket_, reply_.to_buffers(),
64
      boost::asio::async_write(socket_, reply_.to_buffers(),
67
          boost::bind(&connection::handle_write, shared_from_this(),
65
          boost::bind(&connection::handle_write, shared_from_this(), _1));
68
            asio::placeholders::error));
69
    }
66
    }
70
    else
67
    else
71
    {
68
    {
72
      socket_.async_read_some(asio::buffer(buffer_),
69
      socket_.async_read_some(boost::asio::buffer(buffer_),
73
          boost::bind(&connection::handle_read, shared_from_this(),
70
          boost::bind(&connection::handle_read, shared_from_this(), _1, _2));
74
            asio::placeholders::error,
75
            asio::placeholders::bytes_transferred));
76
    }
71
    }
77
  }
72
  }
78
73
Lines 88-94 void connection::handle_write(const boos Link Here
88
  {
83
  {
89
    // Initiate graceful connection closure.
84
    // Initiate graceful connection closure.
90
    boost::system::error_code ignored_ec;
85
    boost::system::error_code ignored_ec;
91
    socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec);
86
    socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
92
  }
87
  }
93
88
94
  // No new asynchronous operations are started. This means that all shared_ptr
89
  // No new asynchronous operations are started. This means that all shared_ptr
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/connection.hpp (-1 / +1 lines)
Lines 33-39 class connection Link Here
33
{
33
{
34
public:
34
public:
35
  /// Construct a connection with the given io_service.
35
  /// Construct a connection with the given io_service.
36
  explicit connection(asio::io_service& io_service,
36
  explicit connection(boost::asio::io_context& io_context,
37
      request_handler& handler);
37
      request_handler& handler);
38
38
39
  /// Get the socket associated with the connection.
39
  /// Get the socket associated with the connection.
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/io_service_pool.cpp (-19 / +24 lines)
Lines 8-23 Link Here
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
//
9
//
10
10
11
#include "server.hpp"
11
#include "io_service_pool.hpp"
12
#include <stdexcept>
12
#include <stdexcept>
13
#include <boost/bind.hpp>
13
#include <boost/bind/bind.hpp>
14
using namespace boost::placeholders;
15
#include <boost/shared_ptr.hpp>
14
#include <boost/thread.hpp>
16
#include <boost/thread.hpp>
15
17
16
namespace http {
18
namespace http {
17
namespace server {
19
namespace server {
18
20
19
io_service_pool::io_service_pool(std::size_t pool_size)
21
io_service_pool::io_service_pool(std::size_t pool_size)
20
  : next_io_service_(0)
22
  : next_io_context_(0)
21
{
23
{
22
  if (pool_size == 0)
24
  if (pool_size == 0)
23
    throw std::runtime_error("io_service_pool size is 0");
25
    throw std::runtime_error("io_service_pool size is 0");
Lines 26-34 io_service_pool::io_service_pool(std::si Link Here
26
  // exit until they are explicitly stopped.
28
  // exit until they are explicitly stopped.
27
  for (std::size_t i = 0; i < pool_size; ++i)
29
  for (std::size_t i = 0; i < pool_size; ++i)
28
  {
30
  {
29
    io_service_ptr io_service(new asio::io_service);
31
    io_context_ptr io_context(new boost::asio::io_context);
30
    work_ptr work(new asio::io_service::work(*io_service));
32
    work_ptr work(new boost::asio::executor_work_guard<boost::asio::io_context::executor_type>(boost::asio::make_work_guard(*io_context)));
31
    io_services_.push_back(io_service);
33
    io_contexts_.push_back(io_context);
32
    work_.push_back(work);
34
    work_.push_back(work);
33
  }
35
  }
34
}
36
}
Lines 36-66 io_service_pool::io_service_pool(std::si Link Here
36
void io_service_pool::run()
38
void io_service_pool::run()
37
{
39
{
38
  // Create a pool of threads to run all of the io_services.
40
  // Create a pool of threads to run all of the io_services.
39
  std::vector<thread> threads;
41
  std::vector<boost::shared_ptr<boost::thread>> threads;
40
  for (std::size_t i = 0; i < io_services_.size(); ++i)
42
  for (std::size_t i = 0; i < io_contexts_.size(); ++i)
41
    threads.emplace_back(thread(boost::bind(&asio::io_service::run,
43
  {
42
                                            io_services_[i])));
44
    boost::shared_ptr<boost::thread> thread(new boost::thread(
45
      boost::bind(&boost::asio::io_context::run, io_contexts_[i])));
46
    threads.push_back(thread);
47
  }
43
48
44
  // Wait for all threads in the pool to exit.
49
  // Wait for all threads in the pool to exit.
45
  for (std::size_t i = 0; i < threads.size(); ++i)
50
  for (std::size_t i = 0; i < threads.size(); ++i)
46
    threads[i].join();
51
    threads[i]->join();
47
}
52
}
48
53
49
void io_service_pool::stop()
54
void io_service_pool::stop()
50
{
55
{
51
  // Explicitly stop all io_services.
56
  // Explicitly stop all io_services.
52
  for (std::size_t i = 0; i < io_services_.size(); ++i)
57
  for (std::size_t i = 0; i < io_contexts_.size(); ++i)
53
    io_services_[i]->stop();
58
    io_contexts_[i]->stop();
54
}
59
}
55
60
56
asio::io_service& io_service_pool::get_io_service()
61
boost::asio::io_context& io_service_pool::get_io_context()
57
{
62
{
58
  // Use a round-robin scheme to choose the next io_service to use.
63
  // Use a round-robin scheme to choose the next io_service to use.
59
  asio::io_service& io_service = *io_services_[next_io_service_];
64
  boost::asio::io_context& io_context = *io_contexts_[next_io_context_];
60
  ++next_io_service_;
65
  ++next_io_context_;
61
  if (next_io_service_ == io_services_.size())
66
  if (next_io_context_ == io_contexts_.size())
62
    next_io_service_ = 0;
67
    next_io_context_ = 0;
63
  return io_service;
68
  return io_context;
64
}
69
}
65
70
66
} // namespace server
71
} // namespace server
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/io_service_pool.hpp (-7 / +5 lines)
Lines 16-23 Link Here
16
#include <boost/noncopyable.hpp>
16
#include <boost/noncopyable.hpp>
17
#include <boost/shared_ptr.hpp>
17
#include <boost/shared_ptr.hpp>
18
18
19
using namespace boost;
20
21
namespace http {
19
namespace http {
22
namespace server {
20
namespace server {
23
21
Lines 36-55 public: Link Here
36
  void stop();
34
  void stop();
37
35
38
  /// Get an io_service to use.
36
  /// Get an io_service to use.
39
  asio::io_service& get_io_service();
37
  boost::asio::io_context& get_io_context();
40
38
41
private:
39
private:
42
  typedef boost::shared_ptr<asio::io_service> io_service_ptr;
40
  typedef boost::shared_ptr<boost::asio::io_context> io_context_ptr;
43
  typedef boost::shared_ptr<asio::io_service::work> work_ptr;
41
  typedef boost::shared_ptr<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>> work_ptr;
44
42
45
  /// The pool of io_services.
43
  /// The pool of io_services.
46
  std::vector<io_service_ptr> io_services_;
44
  std::vector<io_context_ptr> io_contexts_;
47
45
48
  /// The work that keeps the io_services running.
46
  /// The work that keeps the io_services running.
49
  std::vector<work_ptr> work_;
47
  std::vector<work_ptr> work_;
50
48
51
  /// The next io_service to use for a connection.
49
  /// The next io_service to use for a connection.
52
  std::size_t next_io_service_;
50
  std::size_t next_io_context_;
53
};
51
};
54
52
55
} // namespace server
53
} // namespace server
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/ReaderWriterRestHttpDevice.cpp (+2 lines)
Lines 35-40 Link Here
35
#include <osgDB/FileNameUtils>
35
#include <osgDB/FileNameUtils>
36
#include <osgDB/FileUtils>
36
#include <osgDB/FileUtils>
37
#include "RestHttpDevice.hpp"
37
#include "RestHttpDevice.hpp"
38
#include <boost/bind/bind.hpp>
39
using namespace boost::placeholders;
38
40
39
41
40
42
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/RestHttpDevice.cpp (+2 lines)
Lines 16-21 Link Here
16
#include <osg/ValueObject>
16
#include <osg/ValueObject>
17
#include <osgDB/FileUtils>
17
#include <osgDB/FileUtils>
18
#include "request_handler.hpp"
18
#include "request_handler.hpp"
19
#include <boost/bind/bind.hpp>
20
using namespace boost::placeholders;
19
21
20
namespace RestHttp {
22
namespace RestHttp {
21
23
(-)openscenegraph-3.6.5-orig/src/osgPlugins/RestHttpDevice/server.cpp (-12 / +11 lines)
Lines 9-15 Link Here
9
//
9
//
10
10
11
#include "server.hpp"
11
#include "server.hpp"
12
#include <boost/bind.hpp>
12
#include <boost/bind/bind.hpp>
13
using namespace boost::placeholders;
13
14
14
namespace http {
15
namespace http {
15
namespace server {
16
namespace server {
Lines 17-38 namespace server { Link Here
17
server::server(const std::string& address, const std::string& port,
18
server::server(const std::string& address, const std::string& port,
18
    const std::string& doc_root, std::size_t io_service_pool_size)
19
    const std::string& doc_root, std::size_t io_service_pool_size)
19
  : io_service_pool_(io_service_pool_size),
20
  : io_service_pool_(io_service_pool_size),
20
    acceptor_(io_service_pool_.get_io_service()),
21
    acceptor_(io_service_pool_.get_io_context()),
21
    new_connection_(new connection(
22
    new_connection_(new connection(
22
          io_service_pool_.get_io_service(), request_handler_)),
23
          io_service_pool_.get_io_context(), request_handler_)),
23
    request_handler_(doc_root)
24
    request_handler_(doc_root)
24
{
25
{
25
  // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
26
  // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
26
  asio::ip::tcp::resolver resolver(io_service_pool_.get_io_service());
27
  boost::asio::ip::tcp::resolver resolver(io_service_pool_.get_io_context());
27
  asio::ip::tcp::resolver::query query(address, port);
28
  boost::asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(address, port);
28
  asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
29
  boost::asio::ip::tcp::endpoint endpoint = *endpoints.begin();
29
  acceptor_.open(endpoint.protocol());
30
  acceptor_.open(endpoint.protocol());
30
  acceptor_.set_option(asio::ip::tcp::acceptor::reuse_address(true));
31
  acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
31
  acceptor_.bind(endpoint);
32
  acceptor_.bind(endpoint);
32
  acceptor_.listen();
33
  acceptor_.listen();
33
  acceptor_.async_accept(new_connection_->socket(),
34
  acceptor_.async_accept(new_connection_->socket(),
34
      boost::bind(&server::handle_accept, this,
35
      boost::bind(&server::handle_accept, this, _1));
35
        asio::placeholders::error));
36
}
36
}
37
37
38
void server::run()
38
void server::run()
Lines 54-63 void server::handle_accept(const boost:: Link Here
54
    OSG_DEBUG << "RestHttpDevice :: server::handle_accept" << std::endl;
54
    OSG_DEBUG << "RestHttpDevice :: server::handle_accept" << std::endl;
55
    new_connection_->start();
55
    new_connection_->start();
56
    new_connection_.reset(new connection(
56
    new_connection_.reset(new connection(
57
          io_service_pool_.get_io_service(), request_handler_));
57
          io_service_pool_.get_io_context(), request_handler_));
58
    acceptor_.async_accept(new_connection_->socket(),
58
    acceptor_.async_accept(new_connection_->socket(),
59
        boost::bind(&server::handle_accept, this,
59
        boost::bind(&server::handle_accept, this, _1));
60
          asio::placeholders::error));
61
  }
60
  }
62
  else
61
  else
63
  {
62
  {

Return to bug 946692