From dea1155983e4bd0a2c400b6f9caf7d39ce8d95bc Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 3 Feb 2024 16:52:10 -0600 Subject: [PATCH] Inform clients of graceful termination when Sunshine exits --- src/stream.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/stream.cpp b/src/stream.cpp index f99e68c1..b00de23e 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1035,8 +1035,12 @@ namespace stream { // This thread handles latency-sensitive control messages platf::adjust_thread_priority(platf::thread_priority_e::critical); - auto shutdown_event = mail::man->event(mail::broadcast_shutdown); - while (!shutdown_event->peek()) { + // Check for both the full shutdown event and the shutdown event for this + // broadcast to ensure we can inform connected clients of our graceful + // termination when we shut down. + auto shutdown_event = mail::man->event(mail::shutdown); + auto broadcast_shutdown_event = mail::man->event(mail::broadcast_shutdown); + while (!shutdown_event->peek() && !broadcast_shutdown_event->peek()) { bool has_session_awaiting_peer = false; { @@ -1045,6 +1049,11 @@ namespace stream { auto now = std::chrono::steady_clock::now(); KITTY_WHILE_LOOP(auto pos = std::begin(*server->_sessions), pos != std::end(*server->_sessions), { + // Don't perform additional session processing if we're shutting down + if (shutdown_event->peek() || broadcast_shutdown_event->peek()) { + break; + } + auto session = *pos; if (now > session->pingTimeout) {