From: Timo Sirainen Date: Fri, 27 Oct 2017 20:31:56 +0000 (+0300) Subject: lib: o_stream_uncork() - call o_stream_nflush() instead of o_stream_flush() X-Git-Tag: 2.3.0.rc1~714 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23c8c511f98924acfc7048e9dc4ccc982c34e320;p=thirdparty%2Fdovecot%2Fcore.git lib: o_stream_uncork() - call o_stream_nflush() instead of o_stream_flush() Otherwise flush errors may be unintentionally ignored. This change requires that all the o_stream_uncork() callers must call o_stream_nfinish() afterwards, unless the ostream is set to ignore errors. --- diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index 8b0fe8d364..aeea71530f 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -344,6 +344,7 @@ static void o_stream_file_cork(struct ostream_private *stream, bool set) else if (!set) { /* buffer flushing might close the stream */ ret = buffer_flush(fstream); + stream->last_errors_not_checked = TRUE; if (fstream->io == NULL && (ret == 0 || fstream->flush_pending) && !stream->ostream.closed) { diff --git a/src/lib/ostream.c b/src/lib/ostream.c index cf4f28d0e1..d9004eb11b 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -502,7 +502,7 @@ static void o_stream_default_cork(struct ostream_private *_stream, bool set) if (_stream->parent != NULL) o_stream_cork(_stream->parent); } else { - (void)o_stream_flush(&_stream->ostream); + o_stream_nflush(&_stream->ostream); if (_stream->parent != NULL) o_stream_uncork(_stream->parent); } diff --git a/src/lib/ostream.h b/src/lib/ostream.h index 32f95d229b..248add86b5 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -121,6 +121,9 @@ size_t o_stream_get_max_buffer_size(struct ostream *stream); /* Delays sending as far as possible, writing only full buffers. Also sets TCP_CORK on if supported. */ void o_stream_cork(struct ostream *stream); +/* Try to flush the buffer by calling o_stream_nflush() and remove TCP_CORK. + Note that after this o_stream_nfinish() must be called, unless the stream + ignores errors. */ void o_stream_uncork(struct ostream *stream); bool o_stream_is_corked(struct ostream *stream); /* Try to flush the output stream. Returns 1 if all sent, 0 if not,