1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

NamedPipe: Avoid early exits from writes on unavailable pipes

This commit is contained in:
reuk 2021-10-12 19:52:42 +01:00
parent b41aeec9b1
commit d36c8b4c55
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

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)
};