From 8bb19e9c45b3695180c9c496a19bc5355c005b3f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 19 Jun 2013 10:22:38 -0700 Subject: [PATCH] Persist the RPCServer object during the shutdown to avoid a crash. --- src/cpp/ripple/RPCServer.cpp | 18 +++++++++--------- src/cpp/ripple/RPCServer.h | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cpp/ripple/RPCServer.cpp b/src/cpp/ripple/RPCServer.cpp index 8a2e084ff..188beb9b8 100644 --- a/src/cpp/ripple/RPCServer.cpp +++ b/src/cpp/ripple/RPCServer.cpp @@ -52,11 +52,6 @@ void RPCServer::handle_read_req (const boost::system::error_code& e) mStrand.wrap (boost::bind (&RPCServer::handle_write, shared_from_this (), boost::asio::placeholders::error))); } -static void dummy_handler () -{ - ; -} - void RPCServer::handle_read_line (const boost::system::error_code& e) { if (e) @@ -68,7 +63,7 @@ void RPCServer::handle_read_line (const boost::system::error_code& e) { // request with no body WriteLog (lsWARNING, RPCServer) << "RPC HTTP request with no body"; - mSocket.async_shutdown (boost::bind (&dummy_handler)); + mSocket.async_shutdown (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)); return; } else if (action == haREAD_LINE) @@ -84,7 +79,7 @@ void RPCServer::handle_read_line (const boost::system::error_code& e) if ((rLen < 0) || (rLen > RPC_MAXIMUM_QUERY)) { WriteLog (lsWARNING, RPCServer) << "Illegal RPC request length " << rLen; - mSocket.async_shutdown (boost::bind (&dummy_handler)); + mSocket.async_shutdown (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)); return; } @@ -105,7 +100,7 @@ void RPCServer::handle_read_line (const boost::system::error_code& e) } } else - mSocket.async_shutdown (boost::bind (&dummy_handler)); + mSocket.async_shutdown (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)); } std::string RPCServer::handleRequest (const std::string& requestStr) @@ -195,7 +190,7 @@ void RPCServer::handle_write (const boost::system::error_code& e) HTTPRequestAction action = mHTTPRequest.requestDone (false); if (action == haCLOSE_CONN) - mSocket.async_shutdown (boost::bind (&dummy_handler)); + mSocket.async_shutdown (boost::bind (&RPCServer::handle_shutdown, shared_from_this(), boost::asio::placeholders::error)); else { boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n", @@ -209,4 +204,9 @@ void RPCServer::handle_write (const boost::system::error_code& e) } } +// nothing to do, we just keep the object alive +void RPCServer::handle_shutdown (const boost::system::error_code& e) +{ +} + // vim:ts=4 diff --git a/src/cpp/ripple/RPCServer.h b/src/cpp/ripple/RPCServer.h index 3ccc261f7..ebc262d5f 100644 --- a/src/cpp/ripple/RPCServer.h +++ b/src/cpp/ripple/RPCServer.h @@ -35,6 +35,7 @@ private: void handle_write (const boost::system::error_code& ec); void handle_read_line (const boost::system::error_code& ec); void handle_read_req (const boost::system::error_code& ec); + void handle_shutdown (const boost::system::error_code& ec); std::string handleRequest (const std::string& requestStr);