From 21b1a4a3365d7e38113d764f5e958dba05f4e8fa Mon Sep 17 00:00:00 2001 From: loki Date: Sun, 4 Jul 2021 16:06:03 +0200 Subject: [PATCH] If all content has been read in RTSP request, no need for waiting for next message --- sunshine/main.cpp | 12 +++++++++--- sunshine/rtsp.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sunshine/main.cpp b/sunshine/main.cpp index 59b49024..59e010e8 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -189,10 +189,12 @@ int main(int argc, char *argv[]) { task_pool.start(1); + bool shutdown_by_interrupt = false; + util::TaskPool::task_id_t force_shutdown = nullptr; // Create signal handler after logging has been initialized auto shutdown_event = mail::man->event(mail::shutdown); - on_signal(SIGINT, [&force_shutdown, shutdown_event]() { + on_signal(SIGINT, [&shutdown_by_interrupt, &force_shutdown, shutdown_event]() { BOOST_LOG(info) << "Interrupt handler called"sv; auto task = []() { @@ -202,7 +204,7 @@ int main(int argc, char *argv[]) { }; force_shutdown = task_pool.pushDelayed(task, 10s).task_id; - + shutdown_by_interrupt = true; shutdown_event->raise(true); }); @@ -219,7 +221,11 @@ int main(int argc, char *argv[]) { shutdown_event->raise(true); }); - auto exit_guard = util::fail_guard([&force_shutdown]() { + auto exit_guard = util::fail_guard([&shutdown_by_interrupt, &force_shutdown]() { + if(!shutdown_by_interrupt) { + return; + } + task_pool.cancel(force_shutdown); std::cout << "Sunshine exited: Press enter to continue"sv << std::endl; diff --git a/sunshine/rtsp.cpp b/sunshine/rtsp.cpp index 67b30f47..2130146f 100644 --- a/sunshine/rtsp.cpp +++ b/sunshine/rtsp.cpp @@ -87,6 +87,13 @@ public: if("Content-length"sv == option->option) { BOOST_LOG(debug) << "Found Content-Length: "sv << option->content << " bytes"sv; + // If content_length > bytes read, then we need to store current data read, + // to be appended by the next read. + auto content_length = util::from_view(option->content); + if(content_length <= bytes) { + break; + } + auto incomplete_size = incomplete.size(); incomplete.resize(incomplete.size() + bytes);