mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Fix, I hope, the websocket connection leak.
This commit is contained in:
@@ -4,11 +4,16 @@
|
|||||||
|
|
||||||
#include "../json/value.h"
|
#include "../json/value.h"
|
||||||
|
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
|
||||||
#include "WSDoor.h"
|
#include "WSDoor.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "NetworkOPs.h"
|
#include "NetworkOPs.h"
|
||||||
#include "CallRPC.h"
|
#include "CallRPC.h"
|
||||||
|
#include "InstanceCounter.h"
|
||||||
|
|
||||||
|
DEFINE_INSTANCE(WebSocketConnection);
|
||||||
|
|
||||||
template <typename endpoint_type>
|
template <typename endpoint_type>
|
||||||
class WSServerHandler;
|
class WSServerHandler;
|
||||||
@@ -17,17 +22,19 @@ class WSServerHandler;
|
|||||||
// - Subscriptions
|
// - Subscriptions
|
||||||
//
|
//
|
||||||
template <typename endpoint_type>
|
template <typename endpoint_type>
|
||||||
class WSConnection : public InfoSub
|
class WSConnection : public InfoSub, public IS_INSTANCE(WebSocketConnection)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename endpoint_type::handler::connection_ptr connection_ptr;
|
typedef typename endpoint_type::connection_type connection;
|
||||||
|
typedef typename boost::shared_ptr<connection> connection_ptr;
|
||||||
|
typedef typename boost::weak_ptr<connection> weak_connection_ptr;
|
||||||
typedef typename endpoint_type::handler::message_ptr message_ptr;
|
typedef typename endpoint_type::handler::message_ptr message_ptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef void (WSConnection::*doFuncPtr)(Json::Value& jvResult, Json::Value &jvRequest);
|
typedef void (WSConnection::*doFuncPtr)(Json::Value& jvResult, Json::Value &jvRequest);
|
||||||
|
|
||||||
WSServerHandler<endpoint_type>* mHandler;
|
WSServerHandler<endpoint_type>* mHandler;
|
||||||
connection_ptr mConnection;
|
weak_connection_ptr mConnection;
|
||||||
NetworkOPs& mNetwork;
|
NetworkOPs& mNetwork;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -35,7 +42,7 @@ public:
|
|||||||
// : mHandler((WSServerHandler<websocketpp::WSDOOR_SERVER>*)(NULL)),
|
// : mHandler((WSServerHandler<websocketpp::WSDOOR_SERVER>*)(NULL)),
|
||||||
// mConnection(connection_ptr()) { ; }
|
// mConnection(connection_ptr()) { ; }
|
||||||
|
|
||||||
WSConnection(WSServerHandler<endpoint_type>* wshpHandler, connection_ptr cpConnection)
|
WSConnection(WSServerHandler<endpoint_type>* wshpHandler, const connection_ptr& cpConnection)
|
||||||
: mHandler(wshpHandler), mConnection(cpConnection), mNetwork(theApp->getOPs()) { ; }
|
: mHandler(wshpHandler), mConnection(cpConnection), mNetwork(theApp->getOPs()) { ; }
|
||||||
|
|
||||||
virtual ~WSConnection()
|
virtual ~WSConnection()
|
||||||
@@ -51,7 +58,9 @@ public:
|
|||||||
// Implement overridden functions from base class:
|
// Implement overridden functions from base class:
|
||||||
void send(const Json::Value& jvObj)
|
void send(const Json::Value& jvObj)
|
||||||
{
|
{
|
||||||
mHandler->send(mConnection, jvObj);
|
connection_ptr ptr = mConnection.lock();
|
||||||
|
if (ptr)
|
||||||
|
mHandler->send(ptr, jvObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ SETUP_LOG();
|
|||||||
#include <boost/mem_fn.hpp>
|
#include <boost/mem_fn.hpp>
|
||||||
#include <boost/unordered_set.hpp>
|
#include <boost/unordered_set.hpp>
|
||||||
|
|
||||||
|
DECLARE_INSTANCE(WebSocketConnection);
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is a light weight, untrusted interface for web clients.
|
// This is a light weight, untrusted interface for web clients.
|
||||||
|
|||||||
Reference in New Issue
Block a user