mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Fix WebSockets treatment of ping timer:
This solves a problem that caused a hang on shutdown related to the lifetime of the ping timer completion handlers used in WebSockets. * Turn the ping timer back on * Use std::weak_ptr for WebSockets timer callbacks. * Disable WebSocket pings if frequency in the .cfg is non-positive.
This commit is contained in:
committed by
Vinnie Falco
parent
2dbb7301fb
commit
29d644e9d3
@@ -22,6 +22,7 @@
|
||||
#include <ripple/websocket/Server.h>
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <beast/weak_fn.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace websocket {
|
||||
@@ -114,16 +115,19 @@ EndpointPtr04 WebSocket04::makeEndpoint (HandlerPtr&& handler)
|
||||
template <>
|
||||
void ConnectionImpl <WebSocket04>::setPingTimer ()
|
||||
{
|
||||
auto freq = getConfig ().WEBSOCKET_PING_FREQ;
|
||||
if (freq <= 0)
|
||||
return;
|
||||
if (auto con = m_connection.lock ())
|
||||
{
|
||||
auto t = boost::posix_time::seconds (getConfig ().WEBSOCKET_PING_FREQ);
|
||||
auto t = boost::posix_time::seconds (freq);
|
||||
auto ms = t.total_milliseconds();
|
||||
con->set_timer (
|
||||
ms,
|
||||
[this] (WebSocket04::ErrorCode const& e)
|
||||
{
|
||||
this->pingTimer (e);
|
||||
});
|
||||
std::bind (
|
||||
beast::weak_fn (&ConnectionImpl <WebSocket04>::pingTimer,
|
||||
shared_from_this()),
|
||||
beast::asio::placeholders::error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user