Skip to content

Commit

Permalink
fix disconnect others for batocera (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner authored Apr 5, 2024
1 parent 7697646 commit ce648da
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion platforms/android/arm64-v8a/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/ios/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/linux/aarch64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/linux/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/macos/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/macos/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/tvos/arm64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/win/x64/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
2 changes: 1 addition & 1 deletion platforms/win/x86/external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

CARGS_SHA=5949a20a926e902931de4a32adaad9f19c76f251
LIBZEDMD_SHA=cc62fff0765cddee4703e471d990e9bae3c0f94d
LIBZEDMD_SHA=d7e79b09f82144ee6a017bbea074efc23316201e
LIBSERUM_SHA=b69d2b436bc93570a2e7e78d0946cd3c43f7aed5
SOCKPP_SHA=e6c4688a576d95f42dd7628cefe68092f6c5cd0f
LIBPUPDMD_SHA=c640ea2cec94097e8baefee9dab39266970e4405
Expand Down
27 changes: 25 additions & 2 deletions src/dmdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ce648da

Please sign in to comment.