Use non-blocking pipes for process I/O on Windows

Fixes https://github.com/libsdl-org/SDL/issues/10846
This commit is contained in:
Sam Lantinga
2024-09-14 19:18:08 -07:00
parent dd07cc8991
commit 34b2f4ffca
2 changed files with 37 additions and 5 deletions

View File

@@ -200,6 +200,7 @@ bool SDL_SYS_CreateProcessWithProperties(SDL_Process *process, SDL_PropertiesID
HANDLE stdin_pipe[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
HANDLE stdout_pipe[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
HANDLE stderr_pipe[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
DWORD pipe_mode = PIPE_NOWAIT;
bool result = false;
// Keep the malloc() before exec() so that an OOM won't run a process at all
@@ -263,6 +264,10 @@ bool SDL_SYS_CreateProcessWithProperties(SDL_Process *process, SDL_PropertiesID
stdin_pipe[WRITE_END] = INVALID_HANDLE_VALUE;
goto done;
}
if (!SetNamedPipeHandleState(stdin_pipe[WRITE_END], &pipe_mode, NULL, NULL)) {
WIN_SetError("SetNamedPipeHandleState()");
goto done;
}
if (!SetHandleInformation(stdin_pipe[WRITE_END], HANDLE_FLAG_INHERIT, 0) ) {
WIN_SetError("SetHandleInformation()");
goto done;
@@ -296,6 +301,10 @@ bool SDL_SYS_CreateProcessWithProperties(SDL_Process *process, SDL_PropertiesID
stdout_pipe[WRITE_END] = INVALID_HANDLE_VALUE;
goto done;
}
if (!SetNamedPipeHandleState(stdout_pipe[READ_END], &pipe_mode, NULL, NULL)) {
WIN_SetError("SetNamedPipeHandleState()");
goto done;
}
if (!SetHandleInformation(stdout_pipe[READ_END], HANDLE_FLAG_INHERIT, 0) ) {
WIN_SetError("SetHandleInformation()");
goto done;
@@ -338,6 +347,10 @@ bool SDL_SYS_CreateProcessWithProperties(SDL_Process *process, SDL_PropertiesID
stderr_pipe[WRITE_END] = INVALID_HANDLE_VALUE;
goto done;
}
if (!SetNamedPipeHandleState(stderr_pipe[READ_END], &pipe_mode, NULL, NULL)) {
WIN_SetError("SetNamedPipeHandleState()");
goto done;
}
if (!SetHandleInformation(stderr_pipe[READ_END], HANDLE_FLAG_INHERIT, 0) ) {
WIN_SetError("SetHandleInformation()");
goto done;