summaryrefslogtreecommitdiff
path: root/library/RemoteServer.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-15 11:07:43 +0400
committerAlexander Gavrilov2012-03-15 11:07:43 +0400
commite7851f5abdd1a84d29020f2789efc0f932284bf0 (patch)
treed5912bf9ba41cb9fcc018540f4cad1972fb3a975 /library/RemoteServer.cpp
parent560e977f0589ac1c0feb6ea825d20d351e325826 (diff)
downloaddfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.gz
dfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.bz2
dfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.xz
Improve support for void RPC functions, dfhack-run, etc.
Diffstat (limited to 'library/RemoteServer.cpp')
-rw-r--r--library/RemoteServer.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp
index 5b082570..30208078 100644
--- a/library/RemoteServer.cpp
+++ b/library/RemoteServer.cpp
@@ -64,10 +64,11 @@ using dfproto::CoreTextFragment;
using google::protobuf::MessageLite;
CoreService::CoreService() {
- // This must be the first method, so that it gets id 0
+ // These 2 methods must be first, so that they get id 0 and 1
addMethod("BindMethod", &CoreService::BindMethod);
-
addMethod("RunCommand", &CoreService::RunCommand);
+
+ // Add others here:
}
command_result CoreService::BindMethod(color_ostream &stream,
@@ -96,8 +97,7 @@ command_result CoreService::BindMethod(color_ostream &stream,
}
command_result CoreService::RunCommand(color_ostream &stream,
- const dfproto::CoreRunCommandRequest *in,
- CoreVoidReply*)
+ const dfproto::CoreRunCommandRequest *in)
{
std::string cmd = in->command();
std::vector<std::string> args;
@@ -242,6 +242,7 @@ void ServerConnection::threadFn(void *arg)
std::cerr << "Client connection established." << endl;
while (!me->in_error) {
+ // Read the message
RPCMessageHeader header;
if (!readFullBuffer(*me->socket, &header, sizeof(header)))
@@ -269,6 +270,9 @@ void ServerConnection::threadFn(void *arg)
//out.print("Handling %d:%d\n", header.id, header.size);
+ // Find and call the function
+ int in_size = header.size;
+
ServerFunctionBase *fn = vector_get(me->functions, header.id);
MessageLite *reply = NULL;
command_result res = CR_FAILURE;
@@ -290,6 +294,7 @@ void ServerConnection::threadFn(void *arg)
}
}
+ // Flush all text output
if (me->in_error)
break;
@@ -297,9 +302,12 @@ void ServerConnection::threadFn(void *arg)
//out.print("Answer %d:%d\n", res, reply);
+ // Send reply
+ int out_size = 0;
+
if (res == CR_OK && reply)
{
- if (!sendRemoteMessage(*me->socket, RPC_REPLY_RESULT, reply))
+ if (!sendRemoteMessage(*me->socket, RPC_REPLY_RESULT, reply, &out_size))
{
out.printerr("In RPC server: I/O error in send result.\n");
break;
@@ -307,6 +315,9 @@ void ServerConnection::threadFn(void *arg)
}
else
{
+ if (reply)
+ out_size = reply->ByteSize();
+
header.id = RPC_REPLY_FAIL;
header.size = res;
@@ -316,6 +327,12 @@ void ServerConnection::threadFn(void *arg)
break;
}
}
+
+ // Cleanup
+ if (fn)
+ {
+ fn->reset(out_size > 32768 || in_size > 32768);
+ }
}
std::cerr << "Shutting down client connection." << endl;