| 55 | } |
| 56 | |
| 57 | void LogThreadFunc() { |
| 58 | fasio::poll_reactor Reactor; |
| 59 | |
| 60 | auto Pipe = fasio::posix_descriptor {Reactor, LogClientQueuePipe[0]}; |
| 61 | fextl::vector<fasio::posix_descriptor> Clients; |
| 62 | |
| 63 | // Wait for AppendLogFD to send file descriptors over LogClientQueuePipe. |
| 64 | // When data becomes ready, we read the FD and register it to the reactor. |
| 65 | Pipe.async_wait([&](fasio::error ec) { |
| 66 | if (ec != fasio::error::success) { |
| 67 | return fasio::post_callback::stop_reactor; |
| 68 | } |
| 69 | |
| 70 | int ReceivedFD; |
| 71 | read(Pipe.FD, &ReceivedFD, sizeof(ReceivedFD)); |
| 72 | |
| 73 | // Register client and set up read callback |
| 74 | Clients.emplace_back(Reactor, ReceivedFD); |
| 75 | Clients.back().async_wait([&Clients, ReceivedFD](fasio::error ec) { |
| 76 | if (ec != fasio::error::success) { |
| 77 | std::iter_swap(std::find_if(Clients.begin(), Clients.end(), [=](auto& desc) { return desc.FD == ReceivedFD; }), std::prev(Clients.end())); |
| 78 | Clients.pop_back(); |
| 79 | return fasio::post_callback::drop; |
| 80 | } |
| 81 | |
| 82 | HandleLogData(ReceivedFD); |
| 83 | return fasio::post_callback::repeat; |
| 84 | }); |
| 85 | |
| 86 | return fasio::post_callback::repeat; |
| 87 | }); |
| 88 | |
| 89 | Reactor.run(); |
| 90 | } |
| 91 | |
| 92 | void StartLogThread() { |
| 93 | pipe2(LogClientQueuePipe, 0); |
nothing calls this directly
no test coverage detected