From 52de5f025f9841dbd82c3da1f4eac958f3540695 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 15 Apr 2017 20:16:51 +0200 Subject: [PATCH] pipe: accept partial vectors on stdin --- src/pipe.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/pipe.c b/src/pipe.c index 3403397d1..fcb1f0382 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -27,7 +27,7 @@ #include "config.h" -static struct super_node sn = { .state = STATE_DESTROYED }; /**< The global configuration */ +static struct super_node sn = { .state = STATE_DESTROYED }; /**< The global configuration */ struct dir { struct pool pool; @@ -103,17 +103,16 @@ static void * send_loop(void *ctx) if (ret < 0) error("Failed to get %u samples out of send pool (%d).", node->vectorize, ret); - for (;;) { - for (int i = 0; i < node->vectorize; i++) { - struct sample *s = smps[i]; + while (!feof(stdin)) { + int len; + for (len = 0; len < node->vectorize; len++) { + struct sample *s = smps[len]; int reason; retry: reason = sample_io_villas_fscan(stdin, s, NULL); if (reason < 0) { - if (feof(stdin)) { - info("Reached end-of-file. Terminating..."); - goto killme; - } + if (feof(stdin)) + break; else { warn("Skipped invalid message message: reason=%d", reason); goto retry; @@ -121,11 +120,13 @@ retry: reason = sample_io_villas_fscan(stdin, s, NULL); } } - node_write(node, smps, node->vectorize); + node_write(node, smps, len); pthread_testcancel(); } -killme: pthread_kill(ptid, SIGINT); + /* We reached EOF on stdin here. Lets kill the process */ + info("Reached end-of-file. Terminating..."); + pthread_kill(ptid, SIGINT); return NULL; }