Removed SDL_WriteProcess()
This had the unfortunate side-effect of blocking if you tried to write too much. Instead you can use SDL_GetProcessInput() and handle SDL_IO_STATUS_NOT_READY as needed. Fixes https://github.com/libsdl-org/SDL/issues/10834
This commit is contained in:
@@ -431,8 +431,8 @@ SDL3_0.0.0 {
|
||||
SDL_GetPreferredLocales;
|
||||
SDL_GetPrimaryDisplay;
|
||||
SDL_GetPrimarySelectionText;
|
||||
SDL_GetProcessInputStream;
|
||||
SDL_GetProcessOutputStream;
|
||||
SDL_GetProcessInput;
|
||||
SDL_GetProcessOutput;
|
||||
SDL_GetProcessProperties;
|
||||
SDL_GetPropertyType;
|
||||
SDL_GetRGB;
|
||||
@@ -978,7 +978,6 @@ SDL3_0.0.0 {
|
||||
SDL_WindowSupportsGPUPresentMode;
|
||||
SDL_WindowSupportsGPUSwapchainComposition;
|
||||
SDL_WriteIO;
|
||||
SDL_WriteProcess;
|
||||
SDL_WriteS16BE;
|
||||
SDL_WriteS16LE;
|
||||
SDL_WriteS32BE;
|
||||
|
||||
@@ -456,8 +456,8 @@
|
||||
#define SDL_GetPreferredLocales SDL_GetPreferredLocales_REAL
|
||||
#define SDL_GetPrimaryDisplay SDL_GetPrimaryDisplay_REAL
|
||||
#define SDL_GetPrimarySelectionText SDL_GetPrimarySelectionText_REAL
|
||||
#define SDL_GetProcessInputStream SDL_GetProcessInputStream_REAL
|
||||
#define SDL_GetProcessOutputStream SDL_GetProcessOutputStream_REAL
|
||||
#define SDL_GetProcessInput SDL_GetProcessInput_REAL
|
||||
#define SDL_GetProcessOutput SDL_GetProcessOutput_REAL
|
||||
#define SDL_GetProcessProperties SDL_GetProcessProperties_REAL
|
||||
#define SDL_GetPropertyType SDL_GetPropertyType_REAL
|
||||
#define SDL_GetRGB SDL_GetRGB_REAL
|
||||
@@ -1003,7 +1003,6 @@
|
||||
#define SDL_WindowSupportsGPUPresentMode SDL_WindowSupportsGPUPresentMode_REAL
|
||||
#define SDL_WindowSupportsGPUSwapchainComposition SDL_WindowSupportsGPUSwapchainComposition_REAL
|
||||
#define SDL_WriteIO SDL_WriteIO_REAL
|
||||
#define SDL_WriteProcess SDL_WriteProcess_REAL
|
||||
#define SDL_WriteS16BE SDL_WriteS16BE_REAL
|
||||
#define SDL_WriteS16LE SDL_WriteS16LE_REAL
|
||||
#define SDL_WriteS32BE SDL_WriteS32BE_REAL
|
||||
|
||||
@@ -476,8 +476,8 @@ SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),retur
|
||||
SDL_DYNAPI_PROC(SDL_Locale**,SDL_GetPreferredLocales,(int *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return)
|
||||
SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_IOStream*,SDL_GetProcessInputStream,(SDL_Process *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_IOStream*,SDL_GetProcessOutputStream,(SDL_Process *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_IOStream*,SDL_GetProcessInput,(SDL_Process *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_IOStream*,SDL_GetProcessOutput,(SDL_Process *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetProcessProperties,(SDL_Process *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_PropertyType,SDL_GetPropertyType,(SDL_PropertiesID a, const char *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormatDetails *b, const SDL_Palette *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
|
||||
@@ -1013,7 +1013,6 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_WindowHasSurface,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WindowSupportsGPUPresentMode,(SDL_GPUDevice *a, SDL_Window *b, SDL_GPUPresentMode c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WindowSupportsGPUSwapchainComposition,(SDL_GPUDevice *a, SDL_Window *b, SDL_GPUSwapchainComposition c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(size_t,SDL_WriteIO,(SDL_IOStream *a, const void *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteProcess,(SDL_Process *a, const void *b, size_t c, SDL_bool d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS16BE,(SDL_IOStream *a, Sint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS16LE,(SDL_IOStream *a, Sint16 b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS32BE,(SDL_IOStream *a, Sint32 b),(a,b),return)
|
||||
|
||||
@@ -108,68 +108,7 @@ void *SDL_ReadProcess(SDL_Process *process, size_t *datasize, int *exitcode)
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_bool SDL_WriteProcess(SDL_Process *process, const void *ptr, size_t size, SDL_bool closeio)
|
||||
{
|
||||
bool result = false;
|
||||
SDL_IOStream *io = NULL;
|
||||
|
||||
if (!process) {
|
||||
SDL_InvalidParamError("process");
|
||||
goto done;
|
||||
}
|
||||
|
||||
io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDIN_POINTER, NULL);
|
||||
if (!io) {
|
||||
SDL_SetError("Process not created with I/O enabled");
|
||||
goto done;
|
||||
}
|
||||
|
||||
size_t written = 0, left = size;
|
||||
while (left > 0) {
|
||||
size_t amount = SDL_WriteIO(io, (Uint8 *)ptr + written, left);
|
||||
if (amount > 0) {
|
||||
written += amount;
|
||||
left -= amount;
|
||||
continue;
|
||||
} else if (SDL_GetIOStatus(io) == SDL_IO_STATUS_NOT_READY) {
|
||||
// Wait for the stream to be ready
|
||||
SDL_Delay(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// The stream status will remain set for the caller to check
|
||||
break;
|
||||
}
|
||||
|
||||
result = (written == size);
|
||||
|
||||
done:
|
||||
if (result) {
|
||||
result = SDL_FlushIO(io);
|
||||
}
|
||||
if (closeio) {
|
||||
result &= SDL_CloseIO(io);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_IOStream *SDL_GetProcessOutputStream(SDL_Process *process)
|
||||
{
|
||||
if (!process) {
|
||||
SDL_InvalidParamError("process");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_IOStream *io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDOUT_POINTER, NULL);
|
||||
if (!io) {
|
||||
SDL_SetError("Process not created with I/O enabled");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return io;
|
||||
}
|
||||
|
||||
SDL_IOStream *SDL_GetProcessInputStream(SDL_Process *process)
|
||||
SDL_IOStream *SDL_GetProcessInput(SDL_Process *process)
|
||||
{
|
||||
if (!process) {
|
||||
SDL_InvalidParamError("process");
|
||||
@@ -178,7 +117,23 @@ SDL_IOStream *SDL_GetProcessInputStream(SDL_Process *process)
|
||||
|
||||
SDL_IOStream *io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDIN_POINTER, NULL);
|
||||
if (!io) {
|
||||
SDL_SetError("Process not created with I/O enabled");
|
||||
SDL_SetError("Process not created with standard input available");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return io;
|
||||
}
|
||||
|
||||
SDL_IOStream *SDL_GetProcessOutput(SDL_Process *process)
|
||||
{
|
||||
if (!process) {
|
||||
SDL_InvalidParamError("process");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_IOStream *io = (SDL_IOStream *)SDL_GetPointerProperty(process->props, SDL_PROP_PROCESS_STDOUT_POINTER, NULL);
|
||||
if (!io) {
|
||||
SDL_SetError("Process not created with standard output available");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user