dovecot-2.2: ostream: Don't mark the stream closed too early aft...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 22 13:47:53 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/e3a87c25e0b2
changeset: 16998:e3a87c25e0b2
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 22 13:47:36 2013 +0200
description:
ostream: Don't mark the stream closed too early after all.
Use another flag instead to avoid losing the last data written to the stream
before closing.

diffstat:

 src/lib/ostream-private.h |  1 +
 src/lib/ostream.c         |  9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diffs (31 lines):

diff -r af96719b5d9c -r e3a87c25e0b2 src/lib/ostream-private.h
--- a/src/lib/ostream-private.h	Thu Nov 21 23:02:33 2013 +0200
+++ b/src/lib/ostream-private.h	Fri Nov 22 13:47:36 2013 +0200
@@ -37,6 +37,7 @@
 	void *context;
 
 	unsigned int corked:1;
+	unsigned int closing:1;
 	unsigned int last_errors_not_checked:1;
 	unsigned int error_handling_disabled:1;
 };
diff -r af96719b5d9c -r e3a87c25e0b2 src/lib/ostream.c
--- a/src/lib/ostream.c	Thu Nov 21 23:02:33 2013 +0200
+++ b/src/lib/ostream.c	Fri Nov 22 13:47:36 2013 +0200
@@ -45,9 +45,14 @@
 
 static void o_stream_close_full(struct ostream *stream, bool close_parents)
 {
-	if (!stream->closed) {
+	if (!stream->closed && !stream->real_stream->closing) {
+		/* first mark the stream as being closed so the
+		   o_stream_copy_error_from_parent() won't recurse us back
+		   here. but don't immediately mark the stream closed, because
+		   we may still want to write something to it. */
+		stream->real_stream->closing = TRUE;
+		io_stream_close(&stream->real_stream->iostream, close_parents);
 		stream->closed = TRUE;
-		io_stream_close(&stream->real_stream->iostream, close_parents);
 	}
 
 	if (stream->stream_errno == 0)


More information about the dovecot-cvs mailing list