close websocket on destructor

This commit is contained in:
Nathan Nichols
2021-05-24 13:32:14 -05:00
parent c0465aae27
commit e1ab2e7dee

View File

@@ -107,6 +107,7 @@ boost::json::object
doLedger(
boost::json::object const& request,
BackendInterface const& backend);
boost::json::object
doLedgerRange(
boost::json::object const& request,
@@ -204,7 +205,10 @@ public:
)->run();
}
~session() = default;
~session()
{
close(1012);
}
void
send(std::string&& msg)
@@ -216,6 +220,15 @@ public:
&session::on_write, shared_from_this()));
}
void
close(boost::beast::websocket::close_reason const& cr)
{
ws_.async_close(
cr,
boost::beast::bind_front_handler(
&session::on_close, shared_from_this()));
}
private:
// Get on the correct executor
@@ -329,7 +342,7 @@ private:
}
void
on_write(boost::beast::error_code ec, std::size_t bytes_transferred)
on_write(boost::beast::error_code const& ec, std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -342,6 +355,13 @@ private:
// Do another read
do_read();
}
void
on_close(boost::beast::error_code const& ec)
{
if (ec)
return fail(ec, "close");
}
};
#endif // RIPPLE_REPORTING_SESSION_H