From c31a8e7794a6d910586657a925c886fb953619ca Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 8 May 2013 10:52:21 -0700 Subject: [PATCH] Dispatch sends and pings to the websocket strand. --- src/cpp/ripple/WSConnection.h | 11 ++++++++--- src/cpp/ripple/WSHandler.h | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index ca9f64987a..f27ea00b26 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -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::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::pingTimer, mConnection, mHandler, boost::asio::placeholders::error))); + } } void rcvMessage(message_ptr msg, bool& msgRejected, bool& runQueue) diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index b95ed85fb7..ac2c2e4e19 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -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::ssend, cpClient, mpMessage)); + } + + void send(connection_ptr cpClient, const std::string& strMessage, bool broadcast) + { + cpClient->get_strand().post(boost::bind( + &WSServerHandler::ssend, cpClient, strMessage, broadcast)); + } + void send(connection_ptr cpClient, const Json::Value& jvObj, bool broadcast) { Json::FastWriter jfwWriter;