add functionality to clear session

This commit is contained in:
Nathan Nichols
2021-05-25 20:19:33 -05:00
parent e1ab2e7dee
commit 58413a7473
3 changed files with 25 additions and 17 deletions

View File

@@ -130,4 +130,24 @@ void
SubscriptionManager::unsubProposedTransactions(std::shared_ptr<session>& session)
{
streamSubscribers_[TransactionsProposed].erase(session);
}
void
SubscriptionManager::clearSession(std::shared_ptr<session> const& session)
{
for(auto& stream : streamSubscribers_)
stream.erase(session);
for(auto& [account, subscribers] : accountSubscribers_)
{
if (subscribers.find(session) != subscribers.end())
accountSubscribers_[account].erase(session);
}
for(auto& [account, subscribers] : accountProposedSubscribers_)
{
if (subscribers.find(session) != subscribers.end())
accountProposedSubscribers_[account].erase(session);
}
}

View File

@@ -93,6 +93,9 @@ public:
void
unsubProposedTransactions(std::shared_ptr<session>& session);
void
clearSession(std::shared_ptr<session> const& session);
};
#endif //SUBSCRIPTION_MANAGER_H

View File

@@ -220,15 +220,6 @@ 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
@@ -296,7 +287,8 @@ private:
return;
if (ec)
fail(ec, "read");
return fail(ec, "read");
std::string msg{
static_cast<char const*>(buffer_.data().data()), buffer_.size()};
// BOOST_LOG_TRIVIAL(debug) << __func__ << msg;
@@ -355,13 +347,6 @@ 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