From 5df4dbc38d7b7d54cba35a2c258366e1d4bac3c8 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 31 Oct 2017 15:00:51 +0200 Subject: [PATCH] lib: Add o_stream_flush_parent() --- src/lib/ostream-private.h | 6 ++++++ src/lib/ostream.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/lib/ostream-private.h b/src/lib/ostream-private.h index d9d4fa5f7c..609ba80b4d 100644 --- a/src/lib/ostream-private.h +++ b/src/lib/ostream-private.h @@ -58,4 +58,10 @@ void o_stream_copy_error_from_parent(struct ostream_private *_stream); Returns 1 if more data can be safely added, 0 if not, -1 if error. */ int o_stream_flush_parent_if_needed(struct ostream_private *_stream); +/* Call this in flush() handler to flush the parent stream. It will call + either o_stream_flush() or o_stream_finish() depending on whether this + stream is already finished. If the parent fails, its error will be also + copied to this stream. */ +int o_stream_flush_parent(struct ostream_private *_stream); + #endif diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 04effd05ec..2f6379a5cd 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -544,6 +544,21 @@ int o_stream_flush_parent_if_needed(struct ostream_private *_stream) return 1; } +int o_stream_flush_parent(struct ostream_private *_stream) +{ + int ret; + + i_assert(_stream->parent != NULL); + + if (!_stream->finished) + ret = o_stream_flush(_stream->parent); + else + ret = o_stream_finish(_stream->parent); + if (ret < 0) + o_stream_copy_error_from_parent(_stream); + return ret; +} + static int o_stream_default_flush(struct ostream_private *_stream) { int ret; -- 2.47.3