290{
291 using namespace std::string_literals;
292 try {
293
294 if (!lr_ipc_shared->
owner_alive_->load(std::memory_order_acquire)
296 return;
297 }
298
300 [lr_ipc_shared, alive = lr_ipc_shared->
owner_alive_](
const asio::error_code& error,
301 const std::size_t bytes_transferred) mutable {
302
303 if (!alive || !alive->load(std::memory_order_acquire)) { return; }
304
305 if (!error) [[likely]] {
306 if (bytes_transferred == 0) [[unlikely]] { std::this_thread::sleep_for(kEmptyWait); }
307 else {
309 std::string command {buffers_begin(buf.data()),
310 buffers_begin(buf.data()) + gsl::narrow<std::ptrdiff_t>(bytes_transferred)};
311 if (command == "TerminateApplication 1\n"s) {
313 }
314 lr_ipc_shared->
line_.
push(std::move(command));
315 buf.consume(bytes_transferred);
316 }
317
318 if (alive && alive->load(std::memory_order_acquire)) {
Read(std::move(lr_ipc_shared)); }
319 }
320 else {
321 rsj::Log(fmt::format(
"LR_IPC_In Read error: {}.", error.message()),
322 std::source_location::current());
323
324 if (error == asio::error::misc_errors::eof) {
325 if (auto* app = juce::JUCEApplication::getInstance()) { app->systemRequestedQuit(); }
326 }
327 }
328 });
329 }
330 catch (const std::exception& e) {
332 throw;
333 }
334}
rsj::ConcurrentQueue< std::string > line_
Definition LR_IPC_In.cpp:57
asio::streambuf streambuf_
Definition LR_IPC_In.cpp:56
std::shared_ptr< std::atomic< bool > > owner_alive_
Definition LR_IPC_In.cpp:62
static void Read(std::shared_ptr< LrIpcInShared > lr_ipc_shared)
Definition LR_IPC_In.cpp:289
std::atomic< bool > thread_should_exit_
Definition LR_IPC_In.cpp:58
void push(const T &value)
Definition Concurrency.h:162
void ExceptionResponse(gsl::czstring id, gsl::czstring fu, const std::exception &e) noexcept
void Log(const juce::String &info, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:112