Browse Source

IPC: Prevent disconnection while a read is in progress

tags/2021-05-28
reuk 5 years ago
parent
commit
472fac976b
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
2 changed files with 11 additions and 9 deletions
  1. +10
    -8
      modules/juce_events/interprocess/juce_InterprocessConnection.cpp
  2. +1
    -1
      modules/juce_events/interprocess/juce_InterprocessConnection.h

+ 10
- 8
modules/juce_events/interprocess/juce_InterprocessConnection.cpp View File

@@ -103,7 +103,7 @@ bool InterprocessConnection::connectToSocket (const String& hostName,
if (s->connect (hostName, portNumber, timeOutMillisecs))
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedWriteLock sl (pipeAndSocketLock);
initialiseWithSocket (std::move (s));
return true;
}
@@ -119,7 +119,7 @@ bool InterprocessConnection::connectToPipe (const String& pipeName, int timeoutM
if (newPipe->openExisting (pipeName))
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedWriteLock sl (pipeAndSocketLock);
pipeReceiveMessageTimeout = timeoutMs;
initialiseWithPipe (std::move (newPipe));
return true;
@@ -136,7 +136,7 @@ bool InterprocessConnection::createPipe (const String& pipeName, int timeoutMs,
if (newPipe->createNewPipe (pipeName, mustNotExist))
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedWriteLock sl (pipeAndSocketLock);
pipeReceiveMessageTimeout = timeoutMs;
initialiseWithPipe (std::move (newPipe));
return true;
@@ -150,7 +150,7 @@ void InterprocessConnection::disconnect (int timeoutMs, Notify notify)
thread->signalThreadShouldExit();
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedReadLock sl (pipeAndSocketLock);
if (socket != nullptr) socket->close();
if (pipe != nullptr) pipe->close();
}
@@ -167,14 +167,14 @@ void InterprocessConnection::disconnect (int timeoutMs, Notify notify)
void InterprocessConnection::deletePipeAndSocket()
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedWriteLock sl (pipeAndSocketLock);
socket.reset();
pipe.reset();
}
bool InterprocessConnection::isConnected() const
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedReadLock sl (pipeAndSocketLock);
return ((socket != nullptr && socket->isConnected())
|| (pipe != nullptr && pipe->isOpen()))
@@ -184,7 +184,7 @@ bool InterprocessConnection::isConnected() const
String InterprocessConnection::getConnectedHostName() const
{
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedReadLock sl (pipeAndSocketLock);
if (pipe == nullptr && socket == nullptr)
return {};
@@ -211,7 +211,7 @@ bool InterprocessConnection::sendMessage (const MemoryBlock& message)
int InterprocessConnection::writeData (void* data, int dataSize)
{
const ScopedLock sl (pipeAndSocketLock);
const ScopedReadLock sl (pipeAndSocketLock);
if (socket != nullptr)
return socket->write (data, dataSize);
@@ -326,6 +326,8 @@ void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
//==============================================================================
int InterprocessConnection::readData (void* data, int num)
{
const ScopedReadLock sl (pipeAndSocketLock);
if (socket != nullptr)
return socket->read (data, num, true);


+ 1
- 1
modules/juce_events/interprocess/juce_InterprocessConnection.h View File

@@ -191,7 +191,7 @@ public:
private:
//==============================================================================
CriticalSection pipeAndSocketLock;
ReadWriteLock pipeAndSocketLock;
std::unique_ptr<StreamingSocket> socket;
std::unique_ptr<NamedPipe> pipe;
bool callbackConnectionState = false;


Loading…
Cancel
Save