json-stream: add helper json_stream_has_buffered_output()

This commit is contained in:
Lennart Poettering
2026-07-12 22:32:40 +02:00
parent 9a09141cae
commit 755f1cff89
2 changed files with 17 additions and 3 deletions
+16 -3
View 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)
+1
View 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