mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 14:05:51 +00:00
We have to dispatch RPCServer operations onto a strand, otherwise
an error while both a read and write are pending can crash.
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
SETUP_LOG (RPCServer)
|
SETUP_LOG (RPCServer)
|
||||||
|
|
||||||
RPCServer::RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::context& context, NetworkOPs* nopNetwork)
|
RPCServer::RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::context& context, NetworkOPs* nopNetwork)
|
||||||
: mNetOps (nopNetwork), mSocket (io_service, context)
|
: mNetOps (nopNetwork), mSocket (io_service, context), mStrand(io_service)
|
||||||
{
|
{
|
||||||
mRole = RPCHandler::GUEST;
|
mRole = RPCHandler::GUEST;
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ void RPCServer::connected ()
|
|||||||
{
|
{
|
||||||
//std::cerr << "RPC request" << std::endl;
|
//std::cerr << "RPC request" << std::endl;
|
||||||
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
||||||
boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error));
|
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCServer::handle_read_req (const boost::system::error_code& e)
|
void RPCServer::handle_read_req (const boost::system::error_code& e)
|
||||||
@@ -49,7 +49,7 @@ void RPCServer::handle_read_req (const boost::system::error_code& e)
|
|||||||
mReplyStr = handleRequest (req);
|
mReplyStr = handleRequest (req);
|
||||||
|
|
||||||
boost::asio::async_write (mSocket, boost::asio::buffer (mReplyStr),
|
boost::asio::async_write (mSocket, boost::asio::buffer (mReplyStr),
|
||||||
boost::bind (&RPCServer::handle_write, shared_from_this (), boost::asio::placeholders::error));
|
mStrand.wrap (boost::bind (&RPCServer::handle_write, shared_from_this (), boost::asio::placeholders::error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dummy_handler ()
|
static void dummy_handler ()
|
||||||
@@ -74,8 +74,8 @@ void RPCServer::handle_read_line (const boost::system::error_code& e)
|
|||||||
else if (action == haREAD_LINE)
|
else if (action == haREAD_LINE)
|
||||||
{
|
{
|
||||||
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
||||||
boost::bind (&RPCServer::handle_read_line, shared_from_this (),
|
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (),
|
||||||
boost::asio::placeholders::error));
|
boost::asio::placeholders::error)));
|
||||||
}
|
}
|
||||||
else if (action == haREAD_RAW)
|
else if (action == haREAD_RAW)
|
||||||
{
|
{
|
||||||
@@ -94,7 +94,7 @@ void RPCServer::handle_read_line (const boost::system::error_code& e)
|
|||||||
{
|
{
|
||||||
mQueryVec.resize (rLen - alreadyHave);
|
mQueryVec.resize (rLen - alreadyHave);
|
||||||
boost::asio::async_read (mSocket, boost::asio::buffer (mQueryVec),
|
boost::asio::async_read (mSocket, boost::asio::buffer (mQueryVec),
|
||||||
boost::bind (&RPCServer::handle_read_req, shared_from_this (), boost::asio::placeholders::error));
|
mStrand.wrap (boost::bind (&RPCServer::handle_read_req, shared_from_this (), boost::asio::placeholders::error)));
|
||||||
WriteLog (lsTRACE, RPCServer) << "Waiting for completed request: " << rLen;
|
WriteLog (lsTRACE, RPCServer) << "Waiting for completed request: " << rLen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -199,7 +199,7 @@ void RPCServer::handle_write (const boost::system::error_code& e)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n",
|
||||||
boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error));
|
mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ private:
|
|||||||
NetworkOPs* mNetOps;
|
NetworkOPs* mNetOps;
|
||||||
|
|
||||||
AutoSocket mSocket;
|
AutoSocket mSocket;
|
||||||
|
boost::asio::io_service::strand mStrand;
|
||||||
|
|
||||||
boost::asio::streambuf mLineBuffer;
|
boost::asio::streambuf mLineBuffer;
|
||||||
Blob mQueryVec;
|
Blob mQueryVec;
|
||||||
|
|||||||
Reference in New Issue
Block a user