diff options
author | Max Kellermann <max@musicpd.org> | 2019-03-25 08:58:45 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-03-25 08:59:25 +0100 |
commit | 2220383d83583cfc8fa8e26c871fc0c403171158 (patch) | |
tree | 51bfcaf18076c00fdee7a457f81ac8c10013ca93 | |
parent | 32317066282dbccaf2d97003da4322a6782d913c (diff) |
test/run_filter: move code to WriteOrThrow()
-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 dd85b6fd0..805751943 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -69,6 +69,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) { @@ -152,13 +162,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 */ |