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

Method threadFn

library/RemoteServer.cpp:260–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260void ServerConnection::threadFn()
261{
262 color_ostream_proxy out(Core::getInstance().getConsole());
263
264 /* Handshake */
265
266 {
267 RPCHandshakeHeader header;
268
269 if (!readFullBuffer(socket, &header, sizeof(header)))
270 {
271 out << "In RPC server: could not read handshake header." << endl;
272 return;
273 }
274
275 if (memcmp(header.magic, RPCHandshakeHeader::REQUEST_MAGIC, sizeof(header.magic)) ||
276 header.version < 1 || header.version > 255)
277 {
278 out << "In RPC server: invalid handshake header." << endl;
279 return;
280 }
281
282 memcpy(header.magic, RPCHandshakeHeader::RESPONSE_MAGIC, sizeof(header.magic));
283 header.version = 1;
284
285 if (socket->Send((uint8*)&header, sizeof(header)) != sizeof(header))
286 {
287 out << "In RPC server: could not send handshake response." << endl;
288 return;
289 }
290 }
291
292 /* Processing */
293
294 std::cerr << "Client connection established." << endl;
295
296 while (!in_error) {
297 // Read the message
298 RPCMessageHeader header;
299
300 if (!readFullBuffer(socket, &header, sizeof(header)))
301 {
302 out.printerr("In RPC server: I/O error in receive header.\n");
303 break;
304 }
305
306 if ((DFHack::DFHackReplyCode)header.id == RPC_REQUEST_QUIT)
307 break;
308
309 if (header.size < 0 || header.size > RPCMessageHeader::MAX_MESSAGE_SIZE)
310 {
311 out.printerr("In RPC server: invalid received size {}.\n", header.size);
312 break;
313 }
314
315 std::unique_ptr<uint8_t[]> buf(new uint8_t[header.size]);
316
317 if (!readFullBuffer(socket, buf.get(), header.size))

Callers 1

AcceptedMethod · 0.80

Calls 15

readFullBufferFunction · 0.85
vector_getFunction · 0.85
sendRemoteMessageFunction · 0.85
AcceptMethod · 0.80
getMethod · 0.45
ParseFromArrayMethod · 0.45
inMethod · 0.45
resetMethod · 0.45
outMethod · 0.45
executeMethod · 0.45
ByteSizeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected