Skip to content

Commit a3f4135

Browse files
Fix clang-format violations in web_serve.cpp
Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
1 parent 2be6d04 commit a3f4135

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/web/src/web_serve.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,38 @@ void WebServer::requestStop()
269269
stop_cv_.notify_one();
270270
}
271271

272+
void WebServer::waitForStop()
273+
{
274+
std::unique_lock<std::mutex> lock(stop_mutex_);
275+
stop_cv_.wait(lock, [this] { return stop_requested_; });
276+
stop_requested_ = false;
277+
lock.unlock();
278+
279+
// Notify connected browsers so they can show "Server stopped" and
280+
// disable auto-reconnect. broadcastAndWait() waits for the write to
281+
// complete before stop() tears down the io_context.
282+
if (viewer_hook_) {
283+
constexpr auto kShutdownFlushTimeout = std::chrono::seconds(2);
284+
viewer_hook_->sessions().broadcastAndWait(R"({"type":"shutdown"})",
285+
kShutdownFlushTimeout);
286+
}
287+
288+
stop();
289+
}
290+
291+
void WebServer::requestStop()
292+
{
293+
if (!isRunning()) {
294+
logger_->warn(utl::WEB, 36, "Web server is not running.");
295+
return;
296+
}
297+
{
298+
std::lock_guard<std::mutex> lock(stop_mutex_);
299+
stop_requested_ = true;
300+
}
301+
stop_cv_.notify_one();
302+
}
303+
272304
void WebServer::stop()
273305
{
274306
if (viewer_hook_) {

0 commit comments

Comments
 (0)