From: Vincent Bernat Date: Wed, 22 Jun 2016 16:06:08 +0000 (+0200) Subject: client: flush output after each block X-Git-Tag: 0.9.5~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3166f616161f7b9408dff60b1825c6eb8c555019;p=thirdparty%2Flldpd.git client: flush output after each block This enables to get realtime output from "lldpcli watch". See #187. --- diff --git a/src/client/jansson_writer.c b/src/client/jansson_writer.c index 0fb179d9..6181518c 100644 --- a/src/client/jansson_writer.c +++ b/src/client/jansson_writer.c @@ -169,6 +169,7 @@ jansson_end(struct writer *w) JSON_INDENT(2) | JSON_PRESERVE_ORDER) == -1) log_warnx("lldpctl", "unable to output JSON"); fprintf(p->fh,"\n"); + fflush(p->fh); json_decref(export); json_decref(root->el); root->el = json_object(); diff --git a/src/client/jsonc_writer.c b/src/client/jsonc_writer.c index 332712e7..2e83f0251 100644 --- a/src/client/jsonc_writer.c +++ b/src/client/jsonc_writer.c @@ -163,6 +163,7 @@ jsonc_end(struct writer *w) int json_flags = (JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED); const char *s = json_object_to_json_string_ext(export, json_flags); fprintf(p->fh, "%s\n", s?s:"{}"); + fflush(p->fh); json_object_put(export); json_object_put(root->el); root->el = json_object_new_object(); diff --git a/src/client/kv_writer.c b/src/client/kv_writer.c index 9df3c903..68a50adf 100644 --- a/src/client/kv_writer.c +++ b/src/client/kv_writer.c @@ -76,9 +76,10 @@ kv_end(struct writer *w) struct kv_writer_private *p = w->priv; char *dot; - if ((dot = strrchr(p->prefix, '\1')) == NULL) + if ((dot = strrchr(p->prefix, '\1')) == NULL) { p->prefix[0] = '\0'; - else + fflush(p->fh); + } else *dot = '\0'; } diff --git a/src/client/text_writer.c b/src/client/text_writer.c index 02dbdf9a..7552c63f 100644 --- a/src/client/text_writer.c +++ b/src/client/text_writer.c @@ -102,8 +102,10 @@ txt_end(struct writer *w) { struct txt_writer_private *p = w->priv; p->level--; - if (p->level == 1) + if (p->level == 1) { fprintf(p->fh, "\n%s", sep); + fflush(p->fh); + } } static void diff --git a/src/client/xml_writer.c b/src/client/xml_writer.c index 3441866b..15638845 100644 --- a/src/client/xml_writer.c +++ b/src/client/xml_writer.c @@ -96,8 +96,10 @@ void xml_end(struct writer *w) { } xmlFreeTextWriter(p->xw); - if (!failed) + if (!failed) { xmlDocDump(p->fh, p->doc); + fflush(p->fh); + } xmlFreeDoc(p->doc); } }