From 664acef494af3fa509b12bc8c1825cfa707ea7f4 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Mon, 24 Feb 2020 11:57:46 +1100 Subject: [PATCH] libobs/util: Retry pipe writes to avoid short-write failures Previously, any short write would be treated elsewhere as a failure. The easiest solution is to have pipe_write() automatically retry until either it's written everything, or it couldn't write anything at all. --- libobs/util/pipe-posix.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libobs/util/pipe-posix.c b/libobs/util/pipe-posix.c index 7eb0d83f4..09bd6f623 100644 --- a/libobs/util/pipe-posix.c +++ b/libobs/util/pipe-posix.c @@ -93,5 +93,12 @@ size_t os_process_pipe_write(os_process_pipe_t *pp, const uint8_t *data, return 0; } - return fwrite(data, 1, len, pp->file); + size_t written = 0; + while (written < len) { + size_t ret = fwrite(data + written, 1, len - written, pp->file); + if (!ret) + return written; + written += ret; + } + return written; }