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/RemoteClient.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/RemoteClient.cpp')
| -rw-r--r-- | library/RemoteClient.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/library/RemoteClient.cpp b/library/RemoteClient.cpp index 3a497ba8..a66421aa 100644 --- a/library/RemoteClient.cpp +++ b/library/RemoteClient.cpp @@ -112,7 +112,7 @@ RemoteClient::~RemoteClient() delete p_default_output; } -bool DFHack::readFullBuffer(CSimpleSocket *socket, void *buf, int size) +bool readFullBuffer(CSimpleSocket *socket, void *buf, int size) { if (!socket->IsSocketValid()) return false; @@ -324,14 +324,11 @@ bool RemoteFunctionBase::bind(color_ostream &out, RemoteClient *client, return client->bind(out, this, name, proto); } -bool DFHack::sendRemoteMessage(CSimpleSocket *socket, int16_t id, const MessageLite *msg, int *psz) +bool sendRemoteMessage(CSimpleSocket *socket, int16_t id, const MessageLite *msg, bool size_ready) { - int size = msg->ByteSize(); + int size = size_ready ? msg->GetCachedSize() : msg->ByteSize(); int fullsz = size + sizeof(RPCMessageHeader); - if (psz) - *psz = size; - std::auto_ptr<uint8_t> data(new uint8_t[fullsz]); RPCMessageHeader *hdr = (RPCMessageHeader*)data.get(); @@ -361,7 +358,16 @@ command_result RemoteFunctionBase::execute(color_ostream &out, return CR_LINK_FAILURE; } - if (!sendRemoteMessage(p_client->socket, id, input)) + int send_size = input->ByteSize(); + + if (send_size > RPCMessageHeader::MAX_MESSAGE_SIZE) + { + out.printerr("In call to %s::%s: message too large: %d.\n", + this->proto.c_str(), this->name.c_str(), send_size); + return CR_LINK_FAILURE; + } + + if (!sendRemoteMessage(p_client->socket, id, input, true)) { out.printerr("In call to %s::%s: I/O error in send.\n", this->proto.c_str(), this->name.c_str()); @@ -388,7 +394,7 @@ command_result RemoteFunctionBase::execute(color_ostream &out, if (header.id == RPC_REPLY_FAIL) return header.size == CR_OK ? CR_FAILURE : command_result(header.size); - if (header.size < 0 || header.size > 2*1048576) + if (header.size < 0 || header.size > RPCMessageHeader::MAX_MESSAGE_SIZE) { out.printerr("In call to %s::%s: invalid received size %d.\n", this->proto.c_str(), this->name.c_str(), header.size); |
