MCPcopy Create free account
hub / github.com/DFHack/dfhack / execute

Method execute

library/RemoteClient.cpp:371–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371command_result RemoteFunctionBase::execute(color_ostream &out,
372 const message_type *input, message_type *output)
373{
374 if (!isValid())
375 {
376 out.printerr("Calling an unbound RPC function {}:{}.\n",
377 this->plugin, this->name);
378 return CR_NOT_IMPLEMENTED;
379 }
380
381 if (!p_client->socket->IsSocketValid())
382 {
383 out.printerr("In call to {}:{}: invalid socket.\n",
384 this->plugin, this->name);
385 return CR_LINK_FAILURE;
386 }
387
388 int send_size = input->ByteSize();
389
390 if (send_size > RPCMessageHeader::MAX_MESSAGE_SIZE)
391 {
392 out.printerr("In call to {}:{}: message too large: {}.\n",
393 this->plugin, this->name, send_size);
394 return CR_LINK_FAILURE;
395 }
396
397 if (!sendRemoteMessage(p_client->socket, id, input, true))
398 {
399 out.printerr("In call to {}:{}: I/O error in send.\n",
400 this->plugin, this->name);
401 return CR_LINK_FAILURE;
402 }
403
404 color_ostream_proxy text_decoder(out);
405 CoreTextNotification text_data;
406
407 output->Clear();
408
409 for (;;) {
410 RPCMessageHeader header;
411
412 if (!readFullBuffer(p_client->socket, &header, sizeof(header)))
413 {
414 out.printerr("In call to {}:{}: I/O error in receive header.\n",
415 this->plugin, this->name);
416 return CR_LINK_FAILURE;
417 }
418
419 //out.print("Received %d:%d\n", header.id, header.size);
420
421 if ((DFHack::DFHackReplyCode)header.id == RPC_REPLY_FAIL)
422 return header.size == CR_OK ? CR_FAILURE : command_result(header.size);
423
424 if (header.size < 0 || header.size > RPCMessageHeader::MAX_MESSAGE_SIZE)
425 {
426 out.printerr("In call to {}:{}: invalid received size {}.\n",
427 this->plugin, this->name, header.size);
428 return CR_LINK_FAILURE;

Callers 1

threadFnMethod · 0.45

Calls 8

sendRemoteMessageFunction · 0.85
readFullBufferFunction · 0.85
command_resultEnum · 0.85
isValidFunction · 0.50
ByteSizeMethod · 0.45
ClearMethod · 0.45
ParseFromArrayMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected