Dispatch sends and pings to the websocket strand.

This commit is contained in:
JoelKatz
2013-05-08 10:52:21 -07:00
parent 2b6a91143b
commit c31a8e7794
2 changed files with 22 additions and 5 deletions

View File

@@ -101,6 +101,7 @@ public:
if (theApp->getLoadManager().shouldCutoff(mLoadSource))
{
#if SHOULD_DISCONNECT
// FIXME: Must dispatch to strand
connection_ptr ptr = mConnection.lock();
if (ptr)
ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload");
@@ -199,9 +200,13 @@ public:
void setPingTimer()
{
mPingTimer.expires_from_now(boost::posix_time::seconds(WEBSOCKET_PING_FREQUENCY));
mPingTimer.async_wait(boost::bind(
&WSConnection<endpoint_type>::pingTimer, mConnection, mHandler, boost::asio::placeholders::error));
connection_ptr ptr = mConnection.lock();
if (ptr)
{
mPingTimer.expires_from_now(boost::posix_time::seconds(WEBSOCKET_PING_FREQUENCY));
mPingTimer.async_wait(ptr->get_strand().wrap(boost::bind(
&WSConnection<endpoint_type>::pingTimer, mConnection, mHandler, boost::asio::placeholders::error)));
}
}
void rcvMessage(message_ptr msg, bool& msgRejected, bool& runQueue)

View File

@@ -49,7 +49,7 @@ public:
bool getPublic() { return mPublic; };
void send(connection_ptr cpClient, message_ptr mpMessage)
static void ssend(connection_ptr cpClient, message_ptr mpMessage)
{
try
{
@@ -61,7 +61,7 @@ public:
}
}
void send(connection_ptr cpClient, const std::string& strMessage, bool broadcast)
static void ssend(connection_ptr cpClient, const std::string& strMessage, bool broadcast)
{
try
{
@@ -75,6 +75,18 @@ public:
}
}
void send(connection_ptr cpClient, message_ptr mpMessage)
{
cpClient->get_strand().post(boost::bind(
&WSServerHandler<endpoint_type>::ssend, cpClient, mpMessage));
}
void send(connection_ptr cpClient, const std::string& strMessage, bool broadcast)
{
cpClient->get_strand().post(boost::bind(
&WSServerHandler<endpoint_type>::ssend, cpClient, strMessage, broadcast));
}
void send(connection_ptr cpClient, const Json::Value& jvObj, bool broadcast)
{
Json::FastWriter jfwWriter;