From 9508a4a7d6f6078a7e65ceb4c3d37d01105be80d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 21 Feb 2013 14:22:08 -0800 Subject: [PATCH] Try to prevent websocket connections from pinging out. --- src/cpp/ripple/WSConnection.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index c09c1553b..4e29c80f2 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -5,6 +5,7 @@ #include "../json/value.h" #include +#include #include "WSDoor.h" #include "Application.h" @@ -53,7 +54,7 @@ public: WSConnection(WSServerHandler* wshpHandler, const connection_ptr& cpConnection) : mHandler(wshpHandler), mConnection(cpConnection), mNetwork(theApp->getOPs()), - mPingTimer(theApp->getAuxService()), mPinged(false) + mPingTimer(cpConnection->get_io_service()), mPinged(false) { mRemoteIP = cpConnection->get_socket().lowest_layer().remote_endpoint().address().to_string(); cLog(lsDEBUG) << "Websocket connection from " << mRemoteIP; @@ -62,6 +63,7 @@ public: void preDestroy() { // sever connection + mPingTimer.cancel(); mConnection.reset(); } @@ -143,10 +145,10 @@ public: bool onPingTimer() { if (mPinged) - return true; + return true; // causes connection to close mPinged = true; setPingTimer(); - return false; + return false; // causes ping to be sent } void onPong() @@ -154,8 +156,11 @@ public: mPinged = false; } - static void pingTimer(weak_connection_ptr c, WSServerHandler* h) + static void pingTimer(weak_connection_ptr c, WSServerHandler* h, const boost::system::error_code& e) { + if (e) + return; + connection_ptr ptr = c.lock(); if (ptr) h->pingTimer(ptr); @@ -164,10 +169,10 @@ public: void setPingTimer() { mPingTimer.expires_from_now(boost::posix_time::seconds(WEBSOCKET_PING_FREQUENCY)); - mPingTimer.async_wait(boost::bind(&WSConnection::pingTimer, mConnection, mHandler)); + mPingTimer.async_wait(boost::bind( + &WSConnection::pingTimer, mConnection, mHandler, boost::asio::placeholders::error)); } }; - // vim:ts=4