mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
IPC: Prevent disconnection while a read is in progress
This commit is contained in:
parent
a70101e3ec
commit
472fac976b
2 changed files with 11 additions and 9 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
CriticalSection pipeAndSocketLock;
|
||||
ReadWriteLock pipeAndSocketLock;
|
||||
std::unique_ptr<StreamingSocket> socket;
|
||||
std::unique_ptr<NamedPipe> pipe;
|
||||
bool callbackConnectionState = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue