diff options
| author | Alexander Gavrilov | 2012-03-17 15:36:42 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-17 15:36:42 +0400 |
| commit | 15ccfbb08693a3c89c01a522cd3d2af59c13b051 (patch) | |
| tree | af5e4ff318021dbc233f1954d8337b74b4d92fd1 /library/RemoteServer.cpp | |
| parent | 58eb199036db3662ec2f7a2d6d301e7f432d5639 (diff) | |
| download | dfhack-15ccfbb08693a3c89c01a522cd3d2af59c13b051.tar.gz dfhack-15ccfbb08693a3c89c01a522cd3d2af59c13b051.tar.bz2 dfhack-15ccfbb08693a3c89c01a522cd3d2af59c13b051.tar.xz | |
Add a ListMaterials remote call for bulk download of basic material info.
Diffstat (limited to 'library/RemoteServer.cpp')
| -rw-r--r-- | library/RemoteServer.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp index ae8b0024..bae62bb7 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -67,6 +67,11 @@ using dfproto::CoreTextNotification; using dfproto::CoreTextFragment; using google::protobuf::MessageLite; +bool readFullBuffer(CSimpleSocket *socket, void *buf, int size); +bool sendRemoteMessage(CSimpleSocket *socket, int16_t id, + const ::google::protobuf::MessageLite *msg, bool size_ready); + + RPCService::RPCService() { owner = NULL; @@ -183,7 +188,7 @@ void ServerConnection::connection_ostream::flush_proxy() buffer.clear(); - if (!sendRemoteMessage(owner->socket, RPC_REPLY_TEXT, &msg)) + if (!sendRemoteMessage(owner->socket, RPC_REPLY_TEXT, &msg, false)) { owner->in_error = true; Core::printerr("Error writing text into client socket.\n"); @@ -243,7 +248,7 @@ void ServerConnection::threadFn(void *arg) if (header.id == RPC_REQUEST_QUIT) break; - if (header.size < 0 || header.size > 2*1048576) + if (header.size < 0 || header.size > RPCMessageHeader::MAX_MESSAGE_SIZE) { out.printerr("In RPC server: invalid received size %d.\n", header.size); break; @@ -278,6 +283,8 @@ void ServerConnection::threadFn(void *arg) } else { + buf.reset(); + reply = fn->out(); res = fn->execute(me->stream); } @@ -287,16 +294,23 @@ void ServerConnection::threadFn(void *arg) if (me->in_error) break; - me->stream.flush(); - //out.print("Answer %d:%d\n", res, reply); // Send reply - int out_size = 0; + int out_size = (reply ? reply->ByteSize() : 0); + + if (out_size > RPCMessageHeader::MAX_MESSAGE_SIZE) + { + me->stream.printerr("In call to %s: reply too large: %d.\n", + (fn ? fn->name : "UNKNOWN"), out_size); + res = CR_LINK_FAILURE; + } + + me->stream.flush(); if (res == CR_OK && reply) { - if (!sendRemoteMessage(me->socket, RPC_REPLY_RESULT, reply, &out_size)) + if (!sendRemoteMessage(me->socket, RPC_REPLY_RESULT, reply, true)) { out.printerr("In RPC server: I/O error in send result.\n"); break; @@ -304,9 +318,6 @@ void ServerConnection::threadFn(void *arg) } else { - if (reply) - out_size = reply->ByteSize(); - header.id = RPC_REPLY_FAIL; header.size = res; |
