From a250567e74b9b6eb3a4c3967ab3492d710fc5a5d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 1 Jan 2022 17:54:47 -0500 Subject: [PATCH] add sleeping when no viewers and in ondemand mode --- src/zmc.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/zmc.cpp b/src/zmc.cpp index edc5a6611..52a352b4a 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -250,9 +250,12 @@ int main(int argc, char *argv[]) { monitor->Id()); zmDbDo(sql); - while ((monitor->Capturing() == Monitor::CAPTURING_ONDEMAND) and !monitor->hasViewers()) { - Debug(1, "ONDEMAND and no Viewers. Sleeping"); - sleep(1); + + if (monitor->Capturing() == Monitor::CAPTURING_ONDEMAND) { + while (!zm_terminate and !monitor->hasViewers()) { + Debug(1, "ONDEMAND and no Viewers. Sleeping"); + std::this_thread::sleep_for(Seconds(1)); + } } Seconds sleep_time = Seconds(0); @@ -284,7 +287,7 @@ int main(int argc, char *argv[]) { zmDbDo(sql); } // end foreach monitor - if (zm_terminate){ + if (zm_terminate) { break; } @@ -295,7 +298,8 @@ int main(int argc, char *argv[]) { for (size_t i = 0; i < monitors.size(); i++) { monitors[i]->CheckAction(); - if (monitors[i]->Capturing() == Monitor::CAPTURING_ONDEMAND and !monitors[i]->hasViewers()) { + if ((monitors[i]->Capturing() == Monitor::CAPTURING_ONDEMAND) and !monitors[i]->hasViewers()) { + std::this_thread::sleep_for(Microseconds(100000)); result = 0; continue; }