From 17dfed27ee0eca00860ce02c80a61449fe76e1ee Mon Sep 17 00:00:00 2001 From: Sergey Sofeychuk Date: Tue, 24 Aug 2021 18:17:29 +0300 Subject: [PATCH] Server now restarts on losing all connections --- .gitignore | 1 + uxplay.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 567609b..01f9cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +.vscode/ \ No newline at end of file diff --git a/uxplay.cpp b/uxplay.cpp index abab187..1a987ba 100755 --- a/uxplay.cpp +++ b/uxplay.cpp @@ -48,6 +48,8 @@ static int start_server (std::vector hw_addr, std::string name, unsigned s static int stop_server (); static bool running = false; +static uint open_connections = 0; +static bool had_connection = false; static dnssd_t *dnssd = NULL; static raop_t *raop = NULL; static video_renderer_t *video_renderer = NULL; @@ -346,14 +348,16 @@ int main (int argc, char *argv[]) { mac_address.clear(); relaunch: + had_connection = false; if (start_server(server_hw_addr, server_name, display, tcp, udp, videoflip,use_audio, debug_log, videosink)) { return 1; } running = true; while (running) { - if ((video_renderer_listen(video_renderer))) { + if ((video_renderer_listen(video_renderer))||(had_connection&&(!open_connections))) { stop_server(); + LOGI("Re-launching server..."); goto relaunch; } } @@ -364,11 +368,16 @@ int main (int argc, char *argv[]) { // Server callbacks extern "C" void conn_init (void *cls) { + open_connections++; + had_connection = true; + LOGI("Open connections: %i", open_connections); video_renderer_update_background(video_renderer, 1); } extern "C" void conn_destroy (void *cls) { video_renderer_update_background(video_renderer, -1); + open_connections--; + LOGI("Open connections: %i", open_connections); } extern "C" void audio_process (void *cls, raop_ntp_t *ntp, aac_decode_struct *data) {