File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
272304void WebServer::stop ()
273305{
274306 if (viewer_hook_) {
You can’t perform that action at this time.
0 commit comments