mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Improved locking on InterprocessConnection.
This commit is contained in:
parent
1451d555c1
commit
4aa931def3
3 changed files with 33 additions and 49 deletions
|
|
@ -67,7 +67,7 @@ bool InterprocessConnection::connectToPipe (const String& pipeName, const int ti
|
|||
{
|
||||
disconnect();
|
||||
|
||||
ScopedPointer <NamedPipe> newPipe (new NamedPipe());
|
||||
ScopedPointer<NamedPipe> newPipe (new NamedPipe());
|
||||
|
||||
if (newPipe->openExisting (pipeName))
|
||||
{
|
||||
|
|
@ -84,7 +84,7 @@ bool InterprocessConnection::createPipe (const String& pipeName, const int timeo
|
|||
{
|
||||
disconnect();
|
||||
|
||||
ScopedPointer <NamedPipe> newPipe (new NamedPipe());
|
||||
ScopedPointer<NamedPipe> newPipe (new NamedPipe());
|
||||
|
||||
if (newPipe->createNewPipe (pipeName))
|
||||
{
|
||||
|
|
@ -99,23 +99,26 @@ bool InterprocessConnection::createPipe (const String& pipeName, const int timeo
|
|||
|
||||
void InterprocessConnection::disconnect()
|
||||
{
|
||||
if (socket != nullptr)
|
||||
socket->close();
|
||||
|
||||
if (pipe != nullptr)
|
||||
pipe->close();
|
||||
|
||||
stopThread (4000);
|
||||
signalThreadShouldExit();
|
||||
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
pipe = nullptr;
|
||||
if (socket != nullptr) socket->close();
|
||||
if (pipe != nullptr) pipe->close();
|
||||
}
|
||||
|
||||
stopThread (4000);
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
}
|
||||
|
||||
void InterprocessConnection::deletePipeAndSocket()
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
pipe = nullptr;
|
||||
}
|
||||
|
||||
bool InterprocessConnection::isConnected() const
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
|
|
@ -165,18 +168,18 @@ bool InterprocessConnection::sendMessage (const MemoryBlock& message)
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
|
||||
void InterprocessConnection::initialiseWithSocket (StreamingSocket* newSocket)
|
||||
{
|
||||
jassert (socket == nullptr);
|
||||
socket = socket_;
|
||||
jassert (socket == nullptr && pipe == nullptr);
|
||||
socket = newSocket;
|
||||
connectionMadeInt();
|
||||
startThread();
|
||||
}
|
||||
|
||||
void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
|
||||
void InterprocessConnection::initialiseWithPipe (NamedPipe* newPipe)
|
||||
{
|
||||
jassert (pipe == nullptr);
|
||||
pipe = pipe_;
|
||||
jassert (socket == nullptr && pipe == nullptr);
|
||||
pipe = newPipe;
|
||||
connectionMadeInt();
|
||||
startThread();
|
||||
}
|
||||
|
|
@ -299,10 +302,7 @@ bool InterprocessConnection::readNextMessageInt()
|
|||
else if (bytes < 0)
|
||||
{
|
||||
if (socket != nullptr)
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
}
|
||||
deletePipeAndSocket();
|
||||
|
||||
connectionLostInt();
|
||||
return false;
|
||||
|
|
@ -321,45 +321,32 @@ void InterprocessConnection::run()
|
|||
|
||||
if (ready < 0)
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
socket = nullptr;
|
||||
}
|
||||
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
break;
|
||||
}
|
||||
else if (ready > 0)
|
||||
|
||||
if (ready == 0)
|
||||
{
|
||||
if (! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread::sleep (1);
|
||||
wait (1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (pipe != nullptr)
|
||||
{
|
||||
if (! pipe->isOpen())
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (pipeAndSocketLock);
|
||||
pipe = nullptr;
|
||||
}
|
||||
|
||||
deletePipeAndSocket();
|
||||
connectionLostInt();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (threadShouldExit() || ! readNextMessageInt())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ private:
|
|||
friend class InterprocessConnectionServer;
|
||||
void initialiseWithSocket (StreamingSocket*);
|
||||
void initialiseWithPipe (NamedPipe*);
|
||||
void deletePipeAndSocket();
|
||||
void connectionMadeInt();
|
||||
void connectionLostInt();
|
||||
void deliverDataInt (const MemoryBlock&);
|
||||
|
|
|
|||
|
|
@ -64,14 +64,10 @@ void InterprocessConnectionServer::run()
|
|||
{
|
||||
while ((! threadShouldExit()) && socket != nullptr)
|
||||
{
|
||||
ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
|
||||
ScopedPointer<StreamingSocket> clientSocket (socket->waitForNextConnection());
|
||||
|
||||
if (clientSocket != nullptr)
|
||||
{
|
||||
InterprocessConnection* newConnection = createConnectionObject();
|
||||
|
||||
if (newConnection != nullptr)
|
||||
if (InterprocessConnection* newConnection = createConnectionObject())
|
||||
newConnection->initialiseWithSocket (clientSocket.release());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue