From f34f0aaebcf4163c345a45ceb849a7474e60c057 Mon Sep 17 00:00:00 2001 From: Markus Kalkbrenner Date: Fri, 5 Apr 2024 01:25:27 +0200 Subject: [PATCH] fix disconnect others for batocera --- platforms/android/arm64-v8a/external.sh | 2 +- platforms/ios/arm64/external.sh | 2 +- platforms/linux/aarch64/external.sh | 2 +- platforms/linux/x64/external.sh | 2 +- platforms/macos/arm64/external.sh | 2 +- platforms/macos/x64/external.sh | 2 +- platforms/tvos/arm64/external.sh | 2 +- platforms/win/x64/external.sh | 2 +- platforms/win/x86/external.sh | 2 +- src/dmdServer.cpp | 27 +++++++++++++++++++++++-- 10 files changed, 34 insertions(+), 11 deletions(-) diff --git a/platforms/android/arm64-v8a/external.sh b/platforms/android/arm64-v8a/external.sh index 8542f2e..55a7b6a 100755 --- a/platforms/android/arm64-v8a/external.sh +++ b/platforms/android/arm64-v8a/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/ios/arm64/external.sh b/platforms/ios/arm64/external.sh index ab4f6f6..8ff128d 100755 --- a/platforms/ios/arm64/external.sh +++ b/platforms/ios/arm64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/linux/aarch64/external.sh b/platforms/linux/aarch64/external.sh index f96b6f5..a08e7ee 100755 --- a/platforms/linux/aarch64/external.sh +++ b/platforms/linux/aarch64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/linux/x64/external.sh b/platforms/linux/x64/external.sh index d9ef7ef..1b2bb2e 100755 --- a/platforms/linux/x64/external.sh +++ b/platforms/linux/x64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/macos/arm64/external.sh b/platforms/macos/arm64/external.sh index c51acbe..5443e8c 100755 --- a/platforms/macos/arm64/external.sh +++ b/platforms/macos/arm64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/macos/x64/external.sh b/platforms/macos/x64/external.sh index 8ff16fc..a8016b1 100755 --- a/platforms/macos/x64/external.sh +++ b/platforms/macos/x64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/tvos/arm64/external.sh b/platforms/tvos/arm64/external.sh index ea480d7..270e7d0 100755 --- a/platforms/tvos/arm64/external.sh +++ b/platforms/tvos/arm64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/win/x64/external.sh b/platforms/win/x64/external.sh index f5bb10f..469684a 100755 --- a/platforms/win/x64/external.sh +++ b/platforms/win/x64/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/platforms/win/x86/external.sh b/platforms/win/x86/external.sh index 96aff02..68c8475 100755 --- a/platforms/win/x86/external.sh +++ b/platforms/win/x86/external.sh @@ -3,7 +3,7 @@ set -e CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251 -LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d +LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5 SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405 diff --git a/src/dmdServer.cpp b/src/dmdServer.cpp index 0ec97ee..59072c0 100644 --- a/src/dmdServer.cpp +++ b/src/dmdServer.cpp @@ -110,7 +110,9 @@ void run(sockpp::tcp_socket sock, uint32_t threadId) // Only the current (most recent) thread is allowed to disconnect other clients. if (handleDisconnectOthers && threadId == currentThreadId && pStreamHeader->disconnectOthers) { + threadMutex.lock(); disconnectOtherClients = true; + threadMutex.unlock(); handleDisconnectOthers = false; if (opt_verbose) DMDUtil::Log("%d: Other clients will be disconnected", threadId); } @@ -208,8 +210,29 @@ void run(sockpp::tcp_socket sock, uint32_t threadId) threadMutex.lock(); threads.erase(remove(threads.begin(), threads.end(), threadId), threads.end()); - currentThreadId = (threads.size() >= 1) ? threads.back() : 0; - if (threads.size() <= 1) disconnectOtherClients = false; + if (threadId == currentThreadId) + { + if (disconnectOtherClients) + { + // Wait until all other threads ended or a new client connnects in between. + while (threads.size() >= 1 && currentThreadId == threadId) + { + threadMutex.unlock(); + // Let other threads terminate. + this_thread::sleep_for(chrono::milliseconds(10)); + threadMutex.lock(); + } + + currentThreadId = 0; + disconnectOtherClients = false; + } + else + { + currentThreadId = (threads.size() >= 1) ? threads.back() : 0; + } + + if (opt_verbose) DMDUtil::Log("%d: DMD client %d set as current", currentThreadId, currentThreadId); + } threadMutex.unlock(); if (opt_verbose) DMDUtil::Log("%d: DMD client %d disconnected", threadId, threadId);