make invocation to ReadProcessOutput() on Windows non-blocking
This commit is contained in:
parent
05e35b81f6
commit
b58608043d
16
src/rcore.c
16
src/rcore.c
|
|
@ -271,6 +271,13 @@
|
||||||
void **hWritePipe,
|
void **hWritePipe,
|
||||||
struct _SECURITY_ATTRIBUTES *lpPipeAttributes,
|
struct _SECURITY_ATTRIBUTES *lpPipeAttributes,
|
||||||
unsigned long nSize);
|
unsigned long nSize);
|
||||||
|
__declspec(dllimport) int __stdcall PeekNamedPipe(
|
||||||
|
void *hNamedPipe,
|
||||||
|
void *lpBuffer,
|
||||||
|
unsigned long nBufferSize,
|
||||||
|
unsigned long *lpBytesRead,
|
||||||
|
unsigned long *lpTotalBytesAvail,
|
||||||
|
unsigned long *lpBytesLeftThisMessage);
|
||||||
__declspec(dllimport) int __stdcall ReadFile(
|
__declspec(dllimport) int __stdcall ReadFile(
|
||||||
void *hFile,
|
void *hFile,
|
||||||
void *lpBuffer,
|
void *lpBuffer,
|
||||||
|
|
@ -4615,6 +4622,15 @@ RLAPI const char *ReadProcessOutput(Process process, int *length)
|
||||||
// Read from output pipe
|
// Read from output pipe
|
||||||
// NOTE: This will read whatever in the pipe buffer
|
// NOTE: This will read whatever in the pipe buffer
|
||||||
|
|
||||||
|
// ReadFile will block if there is no data, so call PeekNamedPipe to check for data before reading
|
||||||
|
unsigned long bytesAvail = 0;
|
||||||
|
if ((!PeekNamedPipe(process.internal->pipeStdoutRead, NULL, 0, NULL, &bytesAvail, NULL)) ||
|
||||||
|
(bytesAvail == 0))
|
||||||
|
{
|
||||||
|
*length = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long bytesRead = 0;
|
unsigned long bytesRead = 0;
|
||||||
if (!ReadFile(process.internal->pipeStdoutRead, output, sizeof(output), &bytesRead, NULL))
|
if (!ReadFile(process.internal->pipeStdoutRead, output, sizeof(output), &bytesRead, NULL))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user