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 |