This commit is contained in:
Nathan Nichols
2021-06-14 09:37:08 -05:00
committed by CJ Cobb
parent 7860ec6cd1
commit 3389a892b3
5 changed files with 529 additions and 8 deletions

View File

@@ -29,7 +29,6 @@
#include <server/DOSGuard.h>
#include <server/SubscriptionManager.h>
class session;
class SubscriptionManager;
class ETLLoadBalancer;
@@ -168,7 +167,7 @@ void
fail(boost::beast::error_code ec, char const* what);
// Echoes back all received WebSocket messages
class session : public std::enable_shared_from_this<session>
class WsSession : public std::enable_shared_from_this<WsSession>
{
boost::beast::websocket::stream<boost::beast::tcp_stream> ws_;
boost::beast::flat_buffer buffer_;
@@ -181,7 +180,7 @@ class session : public std::enable_shared_from_this<session>
public:
// Take ownership of the socket
explicit session(
explicit WsSession(
boost::asio::ip::tcp::socket&& socket,
std::shared_ptr<BackendInterface> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
@@ -246,7 +245,7 @@ private:
boost::asio::dispatch(
ws_.get_executor(),
boost::beast::bind_front_handler(
&session::on_run, shared_from_this()));
&WsSession::on_run, shared_from_this()));
}
// Start the asynchronous operation
@@ -267,7 +266,7 @@ private:
}));
// Accept the websocket handshake
ws_.async_accept(boost::beast::bind_front_handler(
&session::on_accept, shared_from_this()));
&WsSession::on_accept, shared_from_this()));
}
void
@@ -287,7 +286,7 @@ private:
ws_.async_read(
buffer_,
boost::beast::bind_front_handler(
&session::on_read, shared_from_this()));
&WsSession::on_read, shared_from_this()));
}
void
@@ -367,11 +366,21 @@ private:
ws_.async_write(
boost::asio::buffer(response_),
boost::beast::bind_front_handler(
&session::on_write, shared_from_this()));
&WsSession::on_write, shared_from_this()));
}
void
on_write(boost::beast::error_code const& ec, std::size_t bytes_transferred)
send(std::string&& msg)
{
ws_.text(ws_.got_text());
ws_.async_write(
boost::asio::buffer(msg),
boost::beast::bind_front_handler(
&WsSession::on_write, shared_from_this()));
}
void
on_write(boost::beast::error_code ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);