From 2e93a83dd5c3c5fd301e963904f114c7f72e9a6d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Sep 2020 20:01:51 +0200 Subject: test/run_input: convert pointer to reference --- test/run_input.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/run_input.cxx b/test/run_input.cxx index a3b5e7277..d5648f11a 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -130,20 +130,20 @@ tag_save(FILE *file, const Tag &tag) } static int -dump_input_stream(InputStream *is) +dump_input_stream(InputStream &is) { - const std::lock_guard protect(is->mutex); + const std::lock_guard protect(is.mutex); /* print meta data */ - if (is->HasMimeType()) - fprintf(stderr, "MIME type: %s\n", is->GetMimeType()); + if (is.HasMimeType()) + fprintf(stderr, "MIME type: %s\n", is.GetMimeType()); /* read data and tags from the stream */ - while (!is->IsEOF()) { + while (!is.IsEOF()) { { - auto tag = is->ReadTag(); + auto tag = is.ReadTag(); if (tag) { fprintf(stderr, "Received a tag:\n"); tag_save(stderr, *tag); @@ -151,7 +151,7 @@ dump_input_stream(InputStream *is) } char buffer[4096]; - size_t num_read = is->Read(buffer, sizeof(buffer)); + size_t num_read = is.Read(buffer, sizeof(buffer)); if (num_read == 0) break; @@ -160,7 +160,7 @@ dump_input_stream(InputStream *is) break; } - is->Check(); + is.Check(); return 0; } @@ -234,7 +234,7 @@ try { Mutex mutex; auto is = InputStream::OpenReady(c.uri, mutex); - return dump_input_stream(is.get()); + return dump_input_stream(*is); } catch (...) { PrintException(std::current_exception()); return EXIT_FAILURE; -- cgit v1.2.3 From d7838950d8866127bab5072532fa6e438728c9c1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Sep 2020 20:02:50 +0200 Subject: test/run_input: use WithBufferedOutputStream() --- test/dump_playlist.cxx | 6 +++--- test/run_input.cxx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index ea3be3a3f..ba973703b 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -41,9 +41,9 @@ static void tag_save(FILE *file, const Tag &tag) { StdioOutputStream sos(file); - BufferedOutputStream bos(sos); - tag_save(bos, tag); - bos.Flush(); + WithBufferedOutputStream(sos, [&](auto &bos){ + tag_save(bos, tag); + }); } int main(int argc, char **argv) diff --git a/test/run_input.cxx b/test/run_input.cxx index d5648f11a..4c067fb45 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -124,9 +124,9 @@ static void tag_save(FILE *file, const Tag &tag) { StdioOutputStream sos(file); - BufferedOutputStream bos(sos); - tag_save(bos, tag); - bos.Flush(); + WithBufferedOutputStream(sos, [&](auto &bos){ + tag_save(bos, tag); + }); } static int -- cgit v1.2.3 From b4dc2c07d515b5f0360c88b10292788591ae1117 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Mar 2019 13:57:21 +0100 Subject: test/run_filter: move the buffer into the loop --- test/run_filter.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 5a70d6828..bcc3ea2af 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -62,8 +62,6 @@ LoadFilter(const ConfigData &config, const char *name) int main(int argc, char **argv) try { - char buffer[4096]; - if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: run_filter CONFIG NAME [FORMAT] Date: Thu, 14 Mar 2019 14:13:53 +0100 Subject: test/run_filter: ensure that partial frames will not get passed to the filter --- test/run_filter.cxx | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index bcc3ea2af..9b2994da1 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -27,6 +27,7 @@ #include "filter/Prepared.hxx" #include "pcm/Volume.hxx" #include "mixer/MixerControl.hxx" +#include "system/Error.hxx" #include "util/ConstBuffer.hxx" #include "util/StringBuffer.hxx" #include "util/RuntimeError.hxx" @@ -60,6 +61,50 @@ LoadFilter(const ConfigData &config, const char *name) return filter_configured_new(*param); } +static size_t +ReadOrThrow(int fd, void *buffer, size_t size) +{ + auto nbytes = read(fd, buffer, size); + if (nbytes < 0) + throw MakeErrno("Read failed"); + + return nbytes; +} + +static void +FullRead(int fd, void *_buffer, size_t size) +{ + auto buffer = (uint8_t *)_buffer; + + while (size > 0) { + size_t nbytes = ReadOrThrow(fd, buffer, size); + if (nbytes == 0) + throw std::runtime_error("Premature end of input"); + + buffer += nbytes; + size -= nbytes; + } +} + +static size_t +ReadFrames(int fd, void *_buffer, size_t size, size_t frame_size) +{ + auto buffer = (uint8_t *)_buffer; + + size = (size / frame_size) * frame_size; + + size_t nbytes = ReadOrThrow(fd, buffer, size); + + const size_t modulo = nbytes % frame_size; + if (modulo > 0) { + size_t rest = frame_size - modulo; + FullRead(fd, buffer + nbytes, rest); + nbytes += rest; + } + + return nbytes; +} + int main(int argc, char **argv) try { if (argc < 3 || argc > 4) { @@ -80,6 +125,8 @@ try { if (argc > 3) audio_format = ParseAudioFormat(argv[3], false); + const size_t in_frame_size = audio_format.GetFrameSize(); + /* initialize the filter */ auto prepared_filter = LoadFilter(config, argv[2]); @@ -98,10 +145,9 @@ try { while (true) { char buffer[4096]; - ssize_t nbytes; - - nbytes = read(0, buffer, sizeof(buffer)); - if (nbytes <= 0) + ssize_t nbytes = ReadFrames(0, buffer, sizeof(buffer), + in_frame_size); + if (nbytes == 0) break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); -- cgit v1.2.3 From f3e133c617f2fe76817b679abc9054f2395e2685 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Mar 2019 08:53:58 +0100 Subject: test/run_filter: use class FileDescriptor --- test/run_filter.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 9b2994da1..7402f6838 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -28,6 +28,7 @@ #include "pcm/Volume.hxx" #include "mixer/MixerControl.hxx" #include "system/Error.hxx" +#include "system/FileDescriptor.hxx" #include "util/ConstBuffer.hxx" #include "util/StringBuffer.hxx" #include "util/RuntimeError.hxx" @@ -40,8 +41,6 @@ #include #include #include -#include -#include void mixer_set_volume(gcc_unused Mixer *mixer, @@ -62,9 +61,9 @@ LoadFilter(const ConfigData &config, const char *name) } static size_t -ReadOrThrow(int fd, void *buffer, size_t size) +ReadOrThrow(FileDescriptor fd, void *buffer, size_t size) { - auto nbytes = read(fd, buffer, size); + auto nbytes = fd.Read(buffer, size); if (nbytes < 0) throw MakeErrno("Read failed"); @@ -72,7 +71,7 @@ ReadOrThrow(int fd, void *buffer, size_t size) } static void -FullRead(int fd, void *_buffer, size_t size) +FullRead(FileDescriptor fd, void *_buffer, size_t size) { auto buffer = (uint8_t *)_buffer; @@ -87,7 +86,7 @@ FullRead(int fd, void *_buffer, size_t size) } static size_t -ReadFrames(int fd, void *_buffer, size_t size, size_t frame_size) +ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) { auto buffer = (uint8_t *)_buffer; @@ -142,17 +141,20 @@ try { /* play */ + FileDescriptor input_fd(STDIN_FILENO); + FileDescriptor output_fd(STDOUT_FILENO); + while (true) { char buffer[4096]; - ssize_t nbytes = ReadFrames(0, buffer, sizeof(buffer), + ssize_t nbytes = ReadFrames(input_fd, buffer, sizeof(buffer), in_frame_size); if (nbytes == 0) break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - nbytes = write(1, dest.data, dest.size); + nbytes = output_fd.Write(dest.data, dest.size); if (nbytes < 0) { fprintf(stderr, "Failed to write: %s\n", strerror(errno)); -- cgit v1.2.3 From 1d332746afd2bb62c49d96409fff9487bbb7cb97 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Mar 2019 08:58:45 +0100 Subject: test/run_filter: move code to WriteOrThrow() --- test/run_filter.cxx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'test') 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 */ -- cgit v1.2.3 From 68bcfd8bf0cedbb0e6d6b3d5b02018b4e407a1f7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Mar 2019 08:58:35 +0100 Subject: test/run_filter: check for partial writes --- test/run_filter.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'test') 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 */ -- cgit v1.2.3 From fd4823c507ef8d9c93456cb0029f22b48a3c816d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 26 Aug 2019 21:17:11 +0200 Subject: test/run_filter: fix error message --- test/run_filter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 5a0155802..6d8a270f0 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -103,7 +103,7 @@ FullWrite(FileDescriptor fd, const void *_buffer, size_t size) while (size > 0) { size_t nbytes = WriteOrThrow(fd, buffer, size); if (nbytes == 0) - throw std::runtime_error("Premature end of input"); + throw std::runtime_error("Write failed"); buffer += nbytes; size -= nbytes; -- cgit v1.2.3 From 6238cc073474ce079197ff62e3f66f81963fc127 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 26 Aug 2019 21:14:19 +0200 Subject: test/run_filter: pass ConstBuffer to FullWrite() --- test/run_filter.cxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 6d8a270f0..d51461511 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -96,20 +96,23 @@ FullRead(FileDescriptor fd, void *_buffer, size_t size) } static void -FullWrite(FileDescriptor fd, const void *_buffer, size_t size) +FullWrite(FileDescriptor fd, ConstBuffer src) { - auto buffer = (const uint8_t *)_buffer; - - while (size > 0) { - size_t nbytes = WriteOrThrow(fd, buffer, size); + while (!src.empty()) { + size_t nbytes = WriteOrThrow(fd, src.data, src.size); if (nbytes == 0) throw std::runtime_error("Write failed"); - buffer += nbytes; - size -= nbytes; + src.skip_front(nbytes); } } +static void +FullWrite(FileDescriptor fd, ConstBuffer src) +{ + FullWrite(fd, ConstBuffer::FromVoid(src)); +} + static size_t ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) { @@ -178,7 +181,7 @@ try { break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - FullWrite(output_fd, dest.data, dest.size); + FullWrite(output_fd, dest); } /* cleanup and exit */ -- cgit v1.2.3 From 88446ccde961cde1ec21ec6036fef2f2b81af3b4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 26 Aug 2019 21:14:02 +0200 Subject: test/run_filter: use Filter::Flush() --- test/run_filter.cxx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index d51461511..c6b6f9bff 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -184,6 +184,13 @@ try { FullWrite(output_fd, dest); } + while (true) { + auto dest = filter->Flush(); + if (dest.IsNull()) + break; + FullWrite(output_fd, dest); + } + /* cleanup and exit */ return EXIT_SUCCESS; -- cgit v1.2.3 From 398281cd76f398b6db1a5f7bc8bed9d11374a465 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Nov 2019 21:25:04 +0100 Subject: io/FileDescriptor: add method FullRead() --- test/run_filter.cxx | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index c6b6f9bff..40dce22c2 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -80,21 +80,6 @@ WriteOrThrow(FileDescriptor fd, const void *buffer, size_t size) return nbytes; } -static void -FullRead(FileDescriptor fd, void *_buffer, size_t size) -{ - auto buffer = (uint8_t *)_buffer; - - while (size > 0) { - size_t nbytes = ReadOrThrow(fd, buffer, size); - if (nbytes == 0) - throw std::runtime_error("Premature end of input"); - - buffer += nbytes; - size -= nbytes; - } -} - static void FullWrite(FileDescriptor fd, ConstBuffer src) { @@ -125,7 +110,7 @@ ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) const size_t modulo = nbytes % frame_size; if (modulo > 0) { size_t rest = frame_size - modulo; - FullRead(fd, buffer + nbytes, rest); + fd.FullRead(buffer + nbytes, rest); nbytes += rest; } -- cgit v1.2.3 From 540919f256c761a3e5ce5cfa3d5c343ef09ed673 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 1 Feb 2020 13:49:19 +0100 Subject: *: use nullptr instead of NULL --- test/DumpDatabase.cxx | 2 +- test/dump_playlist.cxx | 6 +++--- test/dump_rva2.cxx | 2 +- test/read_mixer.cxx | 2 +- test/read_tags.cxx | 4 ++-- test/run_encoder.cxx | 2 +- test/run_filter.cxx | 2 +- test/test_vorbis_encoder.cxx | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 39801baf2..81fa14418 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -112,7 +112,7 @@ try { const char *const plugin_name = argv[2]; const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name); - if (plugin == NULL) { + if (plugin == nullptr) { cerr << "No such database plugin: " << plugin_name << endl; return EXIT_FAILURE; } diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index ba973703b..a7416bf5d 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -75,7 +75,7 @@ try { InputStreamPtr is; auto playlist = playlist_list_open_uri(uri, mutex); - if (playlist == NULL) { + if (playlist == nullptr) { /* open the stream and wait until it becomes ready */ is = InputStream::OpenReady(uri, mutex); @@ -83,7 +83,7 @@ try { /* open the playlist */ playlist = playlist_list_open_stream(std::move(is), uri); - if (playlist == NULL) { + if (playlist == nullptr) { fprintf(stderr, "Failed to open playlist\n"); return 2; } @@ -92,7 +92,7 @@ try { /* dump the playlist */ std::unique_ptr song; - while ((song = playlist->NextSong()) != NULL) { + while ((song = playlist->NextSong()) != nullptr) { printf("%s\n", song->GetURI()); const unsigned start_ms = song->GetStartTime().ToMS(); diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx index 3f454606d..ebeb9e582 100644 --- a/test/dump_rva2.cxx +++ b/test/dump_rva2.cxx @@ -70,7 +70,7 @@ try { auto is = OpenLocalInputStream(path, mutex); const auto tag = tag_id3_load(*is); - if (tag == NULL) { + if (tag == nullptr) { fprintf(stderr, "No ID3 tag found\n"); return EXIT_FAILURE; } diff --git a/test/read_mixer.cxx b/test/read_mixer.cxx index ad50b8bb4..008ab29e6 100644 --- a/test/read_mixer.cxx +++ b/test/read_mixer.cxx @@ -36,7 +36,7 @@ const FilterPlugin * filter_plugin_by_name(gcc_unused const char *name) noexcept { assert(false); - return NULL; + return nullptr; } int main(int argc, gcc_unused char **argv) diff --git a/test/read_tags.cxx b/test/read_tags.cxx index 7c392dc2b..aafc58a3b 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -100,7 +100,7 @@ try { const ScopeDecoderPluginsInit decoder_plugins_init({}); plugin = decoder_plugin_from_name(decoder_name); - if (plugin == NULL) { + if (plugin == nullptr) { fprintf(stderr, "No such decoder: %s\n", decoder_name); return EXIT_FAILURE; } @@ -117,7 +117,7 @@ try { Mutex mutex; InputStreamPtr is; - if (!success && plugin->scan_stream != NULL) { + if (!success && plugin->scan_stream != nullptr) { is = InputStream::OpenReady(path, mutex); success = plugin->ScanStream(*is, h); } diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx index 9096d9e5b..97f9d90b5 100644 --- a/test/run_encoder.cxx +++ b/test/run_encoder.cxx @@ -55,7 +55,7 @@ try { /* create the encoder */ const auto plugin = encoder_plugin_get(encoder_name); - if (plugin == NULL) { + if (plugin == nullptr) { fprintf(stderr, "No such encoder: %s\n", encoder_name); return EXIT_FAILURE; } diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 40dce22c2..5113a7250 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -53,7 +53,7 @@ LoadFilter(const ConfigData &config, const char *name) { const auto *param = config.FindBlock(ConfigBlockOption::AUDIO_FILTER, "name", name); - if (param == NULL) + if (param == nullptr) throw FormatRuntimeError("No such configured filter: %s", name); diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx index 2524d4564..26c8a8784 100644 --- a/test/test_vorbis_encoder.cxx +++ b/test/test_vorbis_encoder.cxx @@ -41,7 +41,7 @@ try { /* create the encoder */ const auto plugin = encoder_plugin_get("vorbis"); - assert(plugin != NULL); + assert(plugin != nullptr); ConfigBlock block; block.AddBlockParam("quality", "5.0", -1); -- cgit v1.2.3 From ae23682372c92c5416f5bd4ec5cd3c276f7add14 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Sep 2020 20:11:00 +0200 Subject: system/FileDescriptor: add method FullWrite() --- test/run_filter.cxx | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 5113a7250..dc8f11586 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -70,34 +70,6 @@ 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 -FullWrite(FileDescriptor fd, ConstBuffer src) -{ - while (!src.empty()) { - size_t nbytes = WriteOrThrow(fd, src.data, src.size); - if (nbytes == 0) - throw std::runtime_error("Write failed"); - - src.skip_front(nbytes); - } -} - -static void -FullWrite(FileDescriptor fd, ConstBuffer src) -{ - FullWrite(fd, ConstBuffer::FromVoid(src)); -} - static size_t ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) { @@ -166,14 +138,14 @@ try { break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - FullWrite(output_fd, dest); + output_fd.FullWrite(dest.data, dest.size); } while (true) { auto dest = filter->Flush(); if (dest.IsNull()) break; - FullWrite(output_fd, dest); + output_fd.FullWrite(dest.data, dest.size); } /* cleanup and exit */ -- cgit v1.2.3 From 962cf32ba7b956733cc1ddb6d9ab707cfc577c02 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 7 Sep 2020 20:04:47 +0200 Subject: test/run_input: pass FileDescriptor to dump_input_stream() --- test/run_input.cxx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/run_input.cxx b/test/run_input.cxx index 4c067fb45..63e5f2ab7 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -130,7 +130,7 @@ tag_save(FILE *file, const Tag &tag) } static int -dump_input_stream(InputStream &is) +dump_input_stream(InputStream &is, FileDescriptor out) { const std::lock_guard protect(is.mutex); @@ -155,9 +155,7 @@ dump_input_stream(InputStream &is) if (num_read == 0) break; - ssize_t num_written = write(1, buffer, num_read); - if (num_written <= 0) - break; + out.FullWrite(buffer, num_read); } is.Check(); @@ -234,7 +232,7 @@ try { Mutex mutex; auto is = InputStream::OpenReady(c.uri, mutex); - return dump_input_stream(*is); + return dump_input_stream(*is, FileDescriptor(STDOUT_FILENO)); } catch (...) { PrintException(std::current_exception()); return EXIT_FAILURE; -- cgit v1.2.3