mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Disconnect WS connections when load exceeds threashold
This commit is contained in:
@@ -26,6 +26,7 @@ WSConnection::WSConnection (InfoSub::Source& source, bool isPublic,
|
||||
, m_sentPing (false)
|
||||
, m_receiveQueueRunning (false)
|
||||
, m_isDead (false)
|
||||
, m_io_service (io_service)
|
||||
{
|
||||
WriteLog (lsDEBUG, WSConnection) << "Websocket connection from " << m_remoteIP;
|
||||
}
|
||||
@@ -98,18 +99,8 @@ Json::Value WSConnection::invokeCommand (Json::Value& jvRequest)
|
||||
// VFALCO TODO Make LoadManager a ctor argument
|
||||
if (getApp().getLoadManager ().shouldCutoff (m_loadSource))
|
||||
{
|
||||
// VFALCO TODO This must be implemented before open sourcing
|
||||
#if BEAST_MSVC
|
||||
# pragma message(BEAST_FILEANDLINE_ "Need to implement before open sourcing")
|
||||
#else
|
||||
# warning message("WSConnection.h: Need implementation before open sourcing.")
|
||||
#endif
|
||||
|
||||
#if SHOULD_DISCONNECT
|
||||
disconnect ();
|
||||
|
||||
return rpcError (rpcSLOW_DOWN);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Requests without "command" are invalid.
|
||||
|
||||
@@ -50,6 +50,7 @@ protected:
|
||||
bool m_sentPing;
|
||||
bool m_receiveQueueRunning;
|
||||
bool m_isDead;
|
||||
boost::asio::io_service& m_io_service;
|
||||
|
||||
private:
|
||||
WSConnection (WSConnection const&);
|
||||
@@ -122,7 +123,17 @@ public:
|
||||
|
||||
void disconnect ()
|
||||
{
|
||||
// FIXME: Must dispatch to strand
|
||||
connection_ptr ptr = m_connection.lock ();
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
m_io_service.dispatch (ptr->get_strand ().wrap (boost::bind (
|
||||
&WSConnectionType <endpoint_type>::handle_disconnect, m_connection)));
|
||||
}
|
||||
}
|
||||
|
||||
void handle_disconnect()
|
||||
{
|
||||
connection_ptr ptr = m_connection.lock ();
|
||||
|
||||
if (ptr)
|
||||
|
||||
Reference in New Issue
Block a user