mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
IPC: Add some missing locks in native NamedPipe implementations
This commit is contained in:
parent
9b90398cf9
commit
389e7436ef
3 changed files with 33 additions and 21 deletions
|
|
@ -181,14 +181,20 @@ private:
|
|||
|
||||
void NamedPipe::close()
|
||||
{
|
||||
if (pimpl != nullptr)
|
||||
{
|
||||
pimpl->stopReadOperation = true;
|
||||
ScopedReadLock sl (lock);
|
||||
|
||||
char buffer[1] = { 0 };
|
||||
ssize_t done = ::write (pimpl->pipeIn, buffer, 1);
|
||||
ignoreUnused (done);
|
||||
if (pimpl != nullptr)
|
||||
{
|
||||
pimpl->stopReadOperation = true;
|
||||
|
||||
char buffer[1] = { 0 };
|
||||
ssize_t done = ::write (pimpl->pipeIn, buffer, 1);
|
||||
ignoreUnused (done);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScopedWriteLock sl (lock);
|
||||
pimpl.reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1071,14 +1071,12 @@ public:
|
|||
return 0;
|
||||
|
||||
OverlappedEvent over;
|
||||
unsigned long numRead;
|
||||
unsigned long numRead = 0;
|
||||
|
||||
if (ReadFile (pipeH, destBuffer, (DWORD) maxBytesToRead, &numRead, &over.over))
|
||||
return (int) numRead;
|
||||
|
||||
const DWORD lastError = GetLastError();
|
||||
|
||||
if (lastError == ERROR_IO_PENDING)
|
||||
if (GetLastError() == ERROR_IO_PENDING)
|
||||
{
|
||||
if (! waitForIO (over, timeOutMilliseconds))
|
||||
return -1;
|
||||
|
|
@ -1087,7 +1085,9 @@ public:
|
|||
return (int) numRead;
|
||||
}
|
||||
|
||||
if (ownsPipe && (GetLastError() == ERROR_BROKEN_PIPE || GetLastError() == ERROR_PIPE_NOT_CONNECTED))
|
||||
const auto lastError = GetLastError();
|
||||
|
||||
if (ownsPipe && (lastError == ERROR_BROKEN_PIPE || lastError == ERROR_PIPE_NOT_CONNECTED))
|
||||
disconnectPipe();
|
||||
else
|
||||
break;
|
||||
|
|
@ -1127,7 +1127,8 @@ public:
|
|||
|
||||
const String filename;
|
||||
HANDLE pipeH, cancelEvent;
|
||||
bool connected, ownsPipe, shouldStop;
|
||||
bool connected, ownsPipe;
|
||||
std::atomic<bool> shouldStop;
|
||||
CriticalSection createFileLock;
|
||||
|
||||
private:
|
||||
|
|
@ -1172,11 +1173,17 @@ private:
|
|||
|
||||
void NamedPipe::close()
|
||||
{
|
||||
if (pimpl != nullptr)
|
||||
{
|
||||
pimpl->shouldStop = true;
|
||||
SetEvent (pimpl->cancelEvent);
|
||||
ScopedReadLock sl (lock);
|
||||
|
||||
if (pimpl != nullptr)
|
||||
{
|
||||
pimpl->shouldStop = true;
|
||||
SetEvent (pimpl->cancelEvent);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScopedWriteLock sl (lock);
|
||||
pimpl.reset();
|
||||
}
|
||||
|
|
@ -1184,22 +1191,19 @@ void NamedPipe::close()
|
|||
|
||||
bool NamedPipe::openInternal (const String& pipeName, const bool createPipe, bool mustNotExist)
|
||||
{
|
||||
pimpl.reset (new Pimpl (pipeName, createPipe, mustNotExist));
|
||||
auto newPimpl = std::make_unique<Pimpl> (pipeName, createPipe, mustNotExist);
|
||||
|
||||
if (createPipe)
|
||||
{
|
||||
if (pimpl->pipeH == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
pimpl.reset();
|
||||
if (newPimpl->pipeH == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (! pimpl->connect (200))
|
||||
else if (! newPimpl->connect (200))
|
||||
{
|
||||
pimpl.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
pimpl = std::move (newPimpl);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ bool NamedPipe::openExisting (const String& pipeName)
|
|||
|
||||
bool NamedPipe::isOpen() const
|
||||
{
|
||||
ScopedReadLock sl (lock);
|
||||
return pimpl != nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +56,7 @@ bool NamedPipe::createNewPipe (const String& pipeName, bool mustNotExist)
|
|||
|
||||
String NamedPipe::getName() const
|
||||
{
|
||||
ScopedReadLock sl (lock);
|
||||
return currentPipeName;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue