Processing (Windows): fix hanging when executing cygwin processes

This commit is contained in:
李通洲
2023-07-11 19:45:16 +08:00
parent 992fd6e5ad
commit 11adefd839
2 changed files with 22 additions and 19 deletions
+21 -18
View File
@@ -82,31 +82,34 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
DWORD nRead = 0;
OVERLAPPED overlapped = {};
// ReadFile always completes synchronously if the pipe is not created with FILE_FLAG_OVERLAPPED
if (!ReadFile(hChildPipeRead, str, sizeof(str), &nRead, &overlapped))
do
{
if (!GetOverlappedResultEx(hChildPipeRead, &overlapped, &nRead, (DWORD) timeout, TRUE))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
return "Child process closed its end (nothing to read)";
CancelIo(hChildPipeRead);
TerminateProcess(piProcInfo.hProcess, 1);
return "GetOverlappedResultEx(hChildPipeRead) failed or timeout";
}
}
while (nRead > 0)
{
ffStrbufAppendNS(buffer, nRead, str);
if (!ReadFile(hChildPipeRead, str, sizeof(str), &nRead, &overlapped))
{
if (!GetOverlappedResult(hChildPipeRead, &overlapped, &nRead, TRUE))
switch (GetLastError())
{
if (GetLastError() == ERROR_BROKEN_PIPE)
return NULL;
case ERROR_IO_PENDING:
if (!GetOverlappedResultEx(hChildPipeRead, &overlapped, &nRead, (DWORD) timeout, TRUE))
{
if (GetLastError() == ERROR_BROKEN_PIPE)
return NULL;
CancelIo(hChildPipeRead);
TerminateProcess(piProcInfo.hProcess, 1);
return "GetOverlappedResultEx(hChildPipeRead) failed or timeout";
}
break;
case ERROR_BROKEN_PIPE:
return NULL;
default:
CancelIo(hChildPipeRead);
return "GetOverlappedResult(hChildPipeRead) failed";
TerminateProcess(piProcInfo.hProcess, 1);
return "ReadFile(hChildPipeRead) failed";
}
}
}
ffStrbufAppendNS(buffer, nRead, str);
} while (nRead > 0);
return NULL;
}