From: Timo Sirainen Date: Wed, 15 Nov 2017 10:49:48 +0000 (+0200) Subject: lib: Add o_stream_abort() X-Git-Tag: 2.3.0.rc1~446 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7660a5183e89459d255dc5873894ff08806711d5;p=thirdparty%2Fdovecot%2Fcore.git lib: Add o_stream_abort() --- diff --git a/src/lib/ostream.c b/src/lib/ostream.c index ca2c506e13..da3f135f88 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -361,6 +361,15 @@ void o_stream_ignore_last_errors(struct ostream *stream) } } +void o_stream_abort(struct ostream *stream) +{ + o_stream_ignore_last_errors(stream); + if (stream->stream_errno != 0) + return; + io_stream_set_error(&stream->real_stream->iostream, "aborted writing"); + stream->stream_errno = EPIPE; +} + void o_stream_set_no_error_handling(struct ostream *stream, bool set) { stream->real_stream->error_handling_disabled = set; diff --git a/src/lib/ostream.h b/src/lib/ostream.h index 4f7d550ca1..67416423f0 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -175,6 +175,10 @@ void o_stream_set_finish_via_child(struct ostream *stream, bool set); /* Marks the stream's error handling as completed to avoid i_panic() on destroy. */ void o_stream_ignore_last_errors(struct ostream *stream); +/* Abort writing to the ostream, also marking any previous error handling as + completed. If the stream hasn't already failed, sets the stream_errno=EPIPE. + This is necessary when aborting write to streams that require finishing. */ +void o_stream_abort(struct ostream *stream); /* If error handling is disabled, the i_panic() on destroy is never called. This function can be called immediately after the stream is created. When creating wrapper streams, they copy this behavior from the parent