diff options
author | Max Kellermann <max@musicpd.org> | 2019-03-25 08:58:45 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-09-07 20:07:18 +0200 |
commit | 1d332746afd2bb62c49d96409fff9487bbb7cb97 (patch) | |
tree | 32c063c618435fe5e49cce1057be66b4eda2ed58 /test | |
parent | f3e133c617f2fe76817b679abc9054f2395e2685 (diff) |
test/run_filter: move code to WriteOrThrow()
Diffstat (limited to 'test')
-rw-r--r-- | test/run_filter.cxx | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 7402f6838..481400e97 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -70,6 +70,16 @@ ReadOrThrow(FileDescriptor fd, void *buffer, size_t size) return nbytes; } +static size_t +WriteOrThrow(FileDescriptor fd, const void *buffer, size_t size) +{ + auto nbytes = fd.Write(buffer, size); + if (nbytes < 0) + throw MakeErrno("Write failed"); + + return nbytes; +} + static void FullRead(FileDescriptor fd, void *_buffer, size_t size) { @@ -153,13 +163,7 @@ try { break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - - nbytes = output_fd.Write(dest.data, dest.size); - if (nbytes < 0) { - fprintf(stderr, "Failed to write: %s\n", - strerror(errno)); - return 1; - } + WriteOrThrow(output_fd, dest.data, dest.size); } /* cleanup and exit */ |