From 9ddf8eece23c3139eb270fcf84e6c956c3a86ab3 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 18 Feb 2019 16:34:04 +0000 Subject: [PATCH] Fixed a bug where InterprocessConnection::isConnected() returned false inside the InterprocessConnection::connectionMade() callback in some cases --- .../interprocess/juce_InterprocessConnection.cpp | 9 ++++++++- .../interprocess/juce_InterprocessConnection.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/juce_events/interprocess/juce_InterprocessConnection.cpp b/modules/juce_events/interprocess/juce_InterprocessConnection.cpp index a4c674f9dc..a74979a5f1 100644 --- a/modules/juce_events/interprocess/juce_InterprocessConnection.cpp +++ b/modules/juce_events/interprocess/juce_InterprocessConnection.cpp @@ -59,6 +59,7 @@ bool InterprocessConnection::connectToSocket (const String& hostName, if (socket->connect (hostName, portNumber, timeOutMillisecs)) { + threadIsRunning = true; connectionMadeInt(); thread->startThread(); return true; @@ -130,7 +131,7 @@ bool InterprocessConnection::isConnected() const return ((socket != nullptr && socket->isConnected()) || (pipe != nullptr && pipe->isOpen())) - && thread->isThreadRunning(); + && threadIsRunning; } String InterprocessConnection::getConnectedHostName() const @@ -179,6 +180,8 @@ void InterprocessConnection::initialiseWithSocket (StreamingSocket* newSocket) { jassert (socket == nullptr && pipe == nullptr); socket.reset (newSocket); + + threadIsRunning = true; connectionMadeInt(); thread->startThread(); } @@ -187,6 +190,8 @@ void InterprocessConnection::initialiseWithPipe (NamedPipe* newPipe) { jassert (socket == nullptr && pipe == nullptr); pipe.reset (newPipe); + + threadIsRunning = true; connectionMadeInt(); thread->startThread(); } @@ -366,6 +371,8 @@ void InterprocessConnection::runThread() if (thread->threadShouldExit() || ! readNextMessage()) break; } + + threadIsRunning = false; } } // namespace juce diff --git a/modules/juce_events/interprocess/juce_InterprocessConnection.h b/modules/juce_events/interprocess/juce_InterprocessConnection.h index 43e207a0de..628c0f395e 100644 --- a/modules/juce_events/interprocess/juce_InterprocessConnection.h +++ b/modules/juce_events/interprocess/juce_InterprocessConnection.h @@ -198,6 +198,7 @@ private: struct ConnectionThread; std::unique_ptr thread; + std::atomic threadIsRunning { false }; void runThread(); int writeData (void*, int);