]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add o_stream_abort()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 15 Nov 2017 10:49:48 +0000 (12:49 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 15 Nov 2017 20:35:37 +0000 (22:35 +0200)
src/lib/ostream.c
src/lib/ostream.h

index ca2c506e13932a929051f5c0ed16a8323dff7631..da3f135f88a18d62f2db0f90a8979b27a6485fd2 100644 (file)
@@ -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;
index 4f7d550ca1a2f9be3315c8f98a6c387ca85f0337..67416423f0106e52b0676066686a7af94b44147c 100644 (file)
@@ -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