Browse Source

NamedPipe: Avoid early exits from writes on unavailable pipes

v6.1.6
reuk 4 years ago
parent
commit
d36c8b4c55
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 23 additions and 3 deletions
  1. +23
    -3
      modules/juce_core/native/juce_posix_NamedPipe.cpp

+ 23
- 3
modules/juce_core/native/juce_posix_NamedPipe.cpp View File

@@ -66,7 +66,9 @@ public:
if (numRead <= 0)
{
if (errno != EWOULDBLOCK || stopReadOperation.load() || hasExpired (timeoutEnd))
const auto error = errno;
if (! (error == EWOULDBLOCK || error == EAGAIN) || stopReadOperation.load() || hasExpired (timeoutEnd))
return -1;
const int maxWaitingTime = 30;
@@ -97,8 +99,20 @@ public:
auto bytesThisTime = numBytesToWrite - bytesWritten;
auto numWritten = (int) ::write (pipeOut, sourceBuffer, (size_t) bytesThisTime);
if (numWritten <= 0)
return -1;
if (numWritten < 0)
{
const auto error = errno;
const int maxWaitingTime = 30;
if (error == EWOULDBLOCK || error == EAGAIN)
waitToWrite (pipeOut, timeoutEnd == 0 ? maxWaitingTime
: jmin (maxWaitingTime,
(int) (timeoutEnd - Time::getMillisecondCounter())));
else
return -1;
numWritten = 0;
}
bytesWritten += numWritten;
sourceBuffer += numWritten;
@@ -178,6 +192,12 @@ private:
poll (&pfd, 1, timeoutMsecs);
}
static void waitToWrite (int handle, int timeoutMsecs) noexcept
{
pollfd pfd { handle, POLLOUT, 0 };
poll (&pfd, 1, timeoutMsecs);
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl)
};


Loading…
Cancel
Save