]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
json-stream: add helper json_stream_has_buffered_output()
authorLennart Poettering <lennart@amutable.com>
Tue, 7 Jul 2026 08:45:08 +0000 (10:45 +0200)
committerLennart Poettering <lennart@amutable.com>
Sun, 12 Jul 2026 20:32:40 +0000 (22:32 +0200)
src/libsystemd/sd-json/json-stream.c
src/libsystemd/sd-json/json-stream.h

index 88473b81929a7bd5a46db344dd025905ddc98698..ed4b6ca5b1a6e0d1d8d7beef8cc2628b7b170372 100644 (file)
@@ -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)
index b502c98676e12a8c08b7c8745c45eaca383141d4..336ececc0f979f45969046aa1fbc5f564be5f50a 100644 (file)
@@ -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