| 581 | } |
| 582 | |
| 583 | s32 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 | |
| 625 | namespace console_server_globals |
| 626 | { |
no test coverage detected