MCPcopy Create free account
hub / github.com/crownengine/crown / run_output_thread

Method run_output_thread

src/device/console_server.cpp:583–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

581}
582
583s32 ConsoleServer::run_output_thread()
584{
585 while (1) {
586 _output_mutex.lock();
587 while (array::size(*_output_write) == 0 && !_thread_exit)
588 _output_condition.wait(_output_mutex);
589
590 if (_thread_exit) {
591 _output_mutex.unlock();
592 break;
593 }
594
595 Buffer *temp = _output_read;
596 _output_read = _output_write;
597 _output_write = temp;
598 _output_mutex.unlock();
599
600 FileBuffer fb(*_output_read);
601 BinaryReader br(fb);
602 while (!fb.end_of_file()) {
603 // Read client, message size and message.
604 u32 client_id;
605 u32 msg_len;
606 br.read(client_id);
607 br.read(msg_len);
608 const char *msg = array::begin(*_output_read) + fb.position();
609 br.skip(msg_len);
610
611 // Lookup socket by its ID.
612 TCPSocket socket;
613 if (console_server_internal::get_socket_by_id(&socket, *this, client_id) != true)
614 continue;
615
616 socket.write(msg - 4, msg_len + 4);
617 }
618
619 array::clear(*_output_read);
620 }
621
622 return 0;
623}
624
625namespace console_server_globals
626{

Callers 1

listenMethod · 0.80

Calls 12

get_socket_by_idFunction · 0.85
sizeFunction · 0.50
beginFunction · 0.50
clearFunction · 0.50
lockMethod · 0.45
waitMethod · 0.45
unlockMethod · 0.45
end_of_fileMethod · 0.45
readMethod · 0.45
positionMethod · 0.45
skipMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected