This commit is contained in:
jed
2012-06-07 15:02:22 -07:00
parent 6770fdf0b3
commit a098f95648
6 changed files with 33 additions and 5 deletions

View File

@@ -122,6 +122,7 @@
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="src\NetworkOPs.cpp" /> <ClCompile Include="src\NetworkOPs.cpp" />
<ClCompile Include="src\NewcoinAddress.cpp" /> <ClCompile Include="src\NewcoinAddress.cpp" />
<ClCompile Include="src\NicknameState.cpp" />
<ClCompile Include="src\PackedMessage.cpp" /> <ClCompile Include="src\PackedMessage.cpp" />
<ClCompile Include="src\ParseSection.cpp" /> <ClCompile Include="src\ParseSection.cpp" />
<ClCompile Include="src\Peer.cpp" /> <ClCompile Include="src\Peer.cpp" />

View File

@@ -243,6 +243,9 @@
<ClCompile Include="src\LedgerProposal.cpp"> <ClCompile Include="src\LedgerProposal.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\NicknameState.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Application.h"> <ClInclude Include="Application.h">

View File

@@ -145,6 +145,7 @@ Json::Value callRPC(const std::string& strMethod, const Json::Value& params)
throw std::runtime_error("no response from server"); throw std::runtime_error("no response from server");
// Parse reply // Parse reply
std::cout << "RPC reply: " << strReply << std::endl;
Json::Reader reader; Json::Reader reader;
Json::Value valReply; Json::Value valReply;
if (!reader.parse(strReply, valReply)) if (!reader.parse(strReply, valReply))

View File

@@ -11,7 +11,7 @@ using namespace boost::asio::ip;
RPCDoor::RPCDoor(boost::asio::io_service& io_service) : RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT)) mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT))
{ {
cerr << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << endl; cerr << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE << endl;
startListening(); startListening();
} }

View File

@@ -61,6 +61,7 @@ void RPCServer::handle_read(const boost::system::error_code& e,
if (result) if (result)
{ {
mReplyStr=handleRequest(mIncomingRequest.mBody); mReplyStr=handleRequest(mIncomingRequest.mBody);
sendReply(); sendReply();
} }
else if (!result) else if (!result)
@@ -2043,13 +2044,29 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
void RPCServer::sendReply() void RPCServer::sendReply()
{ {
std::cout << "RPC reply: " << mReplyStr << std::endl;
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::bind(&RPCServer::handle_write, shared_from_this(),
boost::asio::placeholders::error)); boost::asio::placeholders::error));
} }
void RPCServer::handle_write(const boost::system::error_code& /*error*/)
void RPCServer::handle_write(const boost::system::error_code& e)
{ {
std::cout << "async_write complete " << e << std::endl;
if(!e)
{
// Initiate graceful connection closure.
boost::system::error_code ignored_ec;
mSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
}
if (e != boost::asio::error::operation_aborted)
{
//connection_manager_.stop(shared_from_this());
}
} }
// vim:ts=4 // vim:ts=4

View File

@@ -96,18 +96,24 @@ std::string HTTPReply(int nStatus, const std::string& strMsg)
else if (nStatus == 403) strStatus = "Forbidden"; else if (nStatus == 403) strStatus = "Forbidden";
else if (nStatus == 404) strStatus = "Not Found"; else if (nStatus == 404) strStatus = "Not Found";
else if (nStatus == 500) strStatus = "Internal Server Error"; else if (nStatus == 500) strStatus = "Internal Server Error";
std::string access;
if(theConfig.RPC_ALLOW_REMOTE) access="Access-Control-Allow-Origin: *\r\n";
else access="";
return strprintf( return strprintf(
"HTTP/1.1 %d %s\r\n" "HTTP/1.1 %d %s\r\n"
"Date: %s\r\n" "Date: %s\r\n"
"Connection: close\r\n" "Connection: Keep-Alive\r\n"
"%s"
"Content-Length: %d\r\n" "Content-Length: %d\r\n"
"Content-Type: application/json\r\n" "Content-Type: application/json; charset=UTF-8\r\n"
"Server: coin-json-rpc/%s\r\n" "Server: coin-json-rpc/%s\r\n"
"\r\n" "\r\n"
"%s", "%s",
nStatus, nStatus,
strStatus.c_str(), strStatus.c_str(),
rfc1123Time().c_str(), rfc1123Time().c_str(),
access.c_str(),
strMsg.size(), strMsg.size(),
theConfig.VERSION_STR.c_str(), theConfig.VERSION_STR.c_str(),
strMsg.c_str()); strMsg.c_str());