diff options
author | Max Kellermann <max@musicpd.org> | 2019-03-25 08:58:35 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-09-07 20:07:24 +0200 |
commit | 68bcfd8bf0cedbb0e6d6b3d5b02018b4e407a1f7 (patch) | |
tree | a6d64dd11a8c29f546f3c259584d3777a62df595 | |
parent | 1d332746afd2bb62c49d96409fff9487bbb7cb97 (diff) |
test/run_filter: check for partial writes
-rw-r--r-- | test/run_filter.cxx | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 481400e97..5a0155802 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -95,6 +95,21 @@ FullRead(FileDescriptor fd, void *_buffer, size_t size) } } +static void +FullWrite(FileDescriptor fd, const void *_buffer, size_t size) +{ + auto buffer = (const uint8_t *)_buffer; + + while (size > 0) { + size_t nbytes = WriteOrThrow(fd, buffer, size); + if (nbytes == 0) + throw std::runtime_error("Premature end of input"); + + buffer += nbytes; + size -= nbytes; + } +} + static size_t ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) { @@ -163,7 +178,7 @@ try { break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - WriteOrThrow(output_fd, dest.data, dest.size); + FullWrite(output_fd, dest.data, dest.size); } /* cleanup and exit */ |