From: Lennart Poettering Date: Tue, 7 Jul 2026 08:45:08 +0000 (+0200) Subject: json-stream: add helper json_stream_has_buffered_output() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=755f1cff89acaa1b28667f2b7cc0d6f4ee47c44d;p=thirdparty%2Fsystemd.git json-stream: add helper json_stream_has_buffered_output() --- diff --git a/src/libsystemd/sd-json/json-stream.c b/src/libsystemd/sd-json/json-stream.c index 88473b81929..ed4b6ca5b1a 100644 --- a/src/libsystemd/sd-json/json-stream.c +++ b/src/libsystemd/sd-json/json-stream.c @@ -844,16 +844,29 @@ fail: return r; } +int json_stream_has_buffered_output(const JsonStream *s) { + assert(s); + + if (s->output_buffer_size == 0 && !s->output_queue) + return false; + + if (FLAGS_SET(s->flags, JSON_STREAM_WRITE_DISCONNECTED)) + return -ECONNRESET; + + return true; +} + int json_stream_flush(JsonStream *s) { int ret = 0, r; assert(s); for (;;) { - if (s->output_buffer_size == 0 && !s->output_queue) + r = json_stream_has_buffered_output(s); + if (r < 0) + return r; + if (r == 0) break; - if (FLAGS_SET(s->flags, JSON_STREAM_WRITE_DISCONNECTED)) - return -ECONNRESET; r = json_stream_write(s); if (r < 0) diff --git a/src/libsystemd/sd-json/json-stream.h b/src/libsystemd/sd-json/json-stream.h index b502c98676e..336ececc0f9 100644 --- a/src/libsystemd/sd-json/json-stream.h +++ b/src/libsystemd/sd-json/json-stream.h @@ -206,6 +206,7 @@ int json_stream_parse(JsonStream *s, sd_json_variant **ret); /* Status accessors used by the consumer's state machine. */ bool json_stream_has_buffered_input(const JsonStream *s); +int json_stream_has_buffered_output(const JsonStream *s); /* Compute the poll events the consumer should wait for. The stream queries the consumer's * phase via the registered get_phase callback. In JSON_STREAM_PHASE_READING the stream asks