aboutsummaryrefslogtreecommitdiffstats
path: root/test/run_encoder.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-05-05 22:51:22 +0200
committerMax Kellermann <max@duempel.org>2009-05-05 22:51:22 +0200
commitfeae8b8f6840edbefe28aa81f472230c1f0ed599 (patch)
treee743cb9d530c817f50ec0f3094a48a5e184f2173 /test/run_encoder.c
parent4818d386771cfda8a0d2a876468c114778d6f4c2 (diff)
downloadmpd-feae8b8f6840edbefe28aa81f472230c1f0ed599.tar.gz
mpd-feae8b8f6840edbefe28aa81f472230c1f0ed599.tar.xz
mpd-feae8b8f6840edbefe28aa81f472230c1f0ed599.zip
test/run_encoder: flush the encoder before exiting
Diffstat (limited to 'test/run_encoder.c')
-rw-r--r--test/run_encoder.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/run_encoder.c b/test/run_encoder.c
index faae9ecde..6b519d130 100644
--- a/test/run_encoder.c
+++ b/test/run_encoder.c
@@ -28,6 +28,16 @@
#include <stddef.h>
#include <unistd.h>
+static void
+encoder_to_stdout(struct encoder *encoder)
+{
+ size_t length;
+ static char buffer[32768];
+
+ while ((length = encoder_read(encoder, buffer, sizeof(buffer))) > 0)
+ write(1, buffer, length);
+}
+
int main(int argc, char **argv)
{
GError *error = NULL;
@@ -98,8 +108,6 @@ int main(int argc, char **argv)
/* do it */
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
- size_t length;
-
ret = encoder_write(encoder, buffer, nbytes, &error);
if (!ret) {
g_printerr("encoder_write() failed: %s\n",
@@ -108,8 +116,16 @@ int main(int argc, char **argv)
return 1;
}
- length = encoder_read(encoder, buffer, sizeof(buffer));
- if (length > 0)
- write(1, buffer, length);
+ encoder_to_stdout(encoder);
}
+
+ ret = encoder_flush(encoder, &error);
+ if (!ret) {
+ g_printerr("encoder_flush() failed: %s\n",
+ error->message);
+ g_error_free(error);
+ return 1;
+ }
+
+ encoder_to_stdout(encoder);
}