Disconnect WS connections when load exceeds threashold

This commit is contained in:
Vinnie Falco
2013-09-25 14:32:04 -07:00
parent 69dc722a7a
commit a655662098
2 changed files with 13 additions and 11 deletions

View File

@@ -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.

View File

@@ -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)