Fixes to support Asio changes (API Change):

This adjusts Beast's interfaces and implementation to match
the changes in Boost.Asio.
This commit is contained in:
Vinnie Falco committed 2019-02-19 16:23:30 -08:00
1 parent ac24e58fb3
commit 6baa607295
58 files changed
+762 -723

No files matched your search

@@ -21,7 +21,7 @@
*/
class http_session : public boost::enable_shared_from_this<http_session>
{
beast::tcp_stream<net::io_context::strand> stream_;
beast::tcp_stream stream_;
beast::flat_buffer buffer_;
boost::shared_ptr<shared_state> state_;
http::request<http::string_body> req_;
@@ -16,7 +16,9 @@ listener(
net::io_context& ioc,
tcp::endpoint endpoint,
boost::shared_ptr<shared_state> const& state)
: acceptor_(ioc)
: ioc_(ioc)
, acceptor_(ioc)
, socket_(beast::make_strand(ioc))
, state_(state)
{
beast::error_code ec;
@@ -61,6 +63,7 @@ run()
{
// Start accepting a connection
acceptor_.async_accept(
socket_,
beast::bind_front_handler(
&listener::on_accept,
shared_from_this()));
@@ -80,18 +83,22 @@ fail(beast::error_code ec, char const* what)
// Handle a connection
void
listener::
on_accept(beast::error_code ec, tcp::socket socket)
on_accept(beast::error_code ec)
{
if(ec)
return fail(ec, "accept");
else
// Launch a new session for this connection
boost::make_shared<http_session>(
std::move(socket),
std::move(socket_),
state_)->run();
// Make sure each session gets its own strand
socket_ = tcp::socket(beast::make_strand(ioc_));
// Accept another connection
acceptor_.async_accept(
socket_,
beast::bind_front_handler(
&listener::on_accept,
shared_from_this()));
@@ -22,11 +22,13 @@ class shared_state;
// Accepts incoming connections and launches the sessions
class listener : public boost::enable_shared_from_this<listener>
{
net::io_context& ioc_;
tcp::acceptor acceptor_;
tcp::socket socket_;
boost::shared_ptr<shared_state> state_;
void fail(beast::error_code ec, char const* what);
void on_accept(beast::error_code ec, tcp::socket socket);
void on_accept(beast::error_code ec);
public:
listener(
@@ -83,17 +83,22 @@ void
websocket_session::
send(boost::shared_ptr<std::string const> const& ss)
{
// Get on the strand if we aren't already,
// otherwise we will concurrently access
// objects which are not thread-safe.
if(! ws_.get_executor().running_in_this_thread())
return net::post(
ws_.get_executor(),
beast::bind_front_handler(
&websocket_session::send,
shared_from_this(),
ss));
// Post our work to the strand, this ensures
// that the members of `this` will not be
// accessed concurrently.
net::post(
ws_.get_executor(),
beast::bind_front_handler(
&websocket_session::on_send,
shared_from_this(),
ss));
}
void
websocket_session::
on_send(boost::shared_ptr<std::string const> const& ss)
{
// Always add to queue
queue_.push_back(ss);
@@ -27,7 +27,7 @@ class shared_state;
class websocket_session : public boost::enable_shared_from_this<websocket_session>
{
beast::flat_buffer buffer_;
websocket::stream<beast::tcp_stream<net::io_context::strand>> ws_;
websocket::stream<beast::tcp_stream> ws_;
boost::shared_ptr<shared_state> state_;
std::vector<boost::shared_ptr<std::string const>> queue_;
@@ -50,6 +50,10 @@ public:
// Send a message
void
send(boost::shared_ptr<std::string const> const& ss);
private:
void
on_send(boost::shared_ptr<std::string const> const& ss);
};
template<class Body, class Allocator>