Persist the RPCServer object during the shutdown to avoid a crash.

This commit is contained in:
JoelKatz
2013-06-19 10:22:38 -07:00
parent 5360f69e1e
commit 8a134ede67
2 changed files with 10 additions and 9 deletions

View File

@@ -58,11 +58,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)
@@ -74,7 +69,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)
@@ -90,7 +85,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;
}
@@ -111,7 +106,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)
@@ -201,7 +196,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",
@@ -215,4 +210,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

View File

@@ -40,6 +40,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);