json: add new flag for forcing a flush after dumping json data to file
This is particularly useful when no trailing \n is generated, i.e. stdio doesn't flush the output on its own.
This commit is contained in:
parent
0ac0787e30
commit
0b1f2e8a06
|
@ -1767,6 +1767,9 @@ void json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const cha
|
||||||
fputc('\n', f);
|
fputc('\n', f);
|
||||||
if (flags & JSON_FORMAT_SSE)
|
if (flags & JSON_FORMAT_SSE)
|
||||||
fputc('\n', f); /* In case of SSE add a second newline */
|
fputc('\n', f); /* In case of SSE add a second newline */
|
||||||
|
|
||||||
|
if (flags & JSON_FORMAT_FLUSH)
|
||||||
|
fflush(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
int json_variant_filter(JsonVariant **v, char **to_remove) {
|
int json_variant_filter(JsonVariant **v, char **to_remove) {
|
||||||
|
|
|
@ -168,6 +168,7 @@ typedef enum JsonFormatFlags {
|
||||||
JSON_FORMAT_SOURCE = 1 << 4, /* prefix with source filename/line/column */
|
JSON_FORMAT_SOURCE = 1 << 4, /* prefix with source filename/line/column */
|
||||||
JSON_FORMAT_SSE = 1 << 5, /* prefix/suffix with W3C server-sent events */
|
JSON_FORMAT_SSE = 1 << 5, /* prefix/suffix with W3C server-sent events */
|
||||||
JSON_FORMAT_SEQ = 1 << 6, /* prefix/suffix with RFC 7464 application/json-seq */
|
JSON_FORMAT_SEQ = 1 << 6, /* prefix/suffix with RFC 7464 application/json-seq */
|
||||||
|
JSON_FORMAT_FLUSH = 1 << 7, /* call fflush() after dumping JSON */
|
||||||
} JsonFormatFlags;
|
} JsonFormatFlags;
|
||||||
|
|
||||||
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);
|
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);
|
||||||
|
|
Loading…
Reference in a new issue