changeset 3727:de92177c8113 HEAD

If DONE was sent while output was still being sent to clients, we didn't deinitialize syncing properly. That output mustn't get lost anyway, so now DONE isn't accepted until all output is sent.
author Timo Sirainen <tss@iki.fi>
date Tue, 06 Dec 2005 16:32:50 +0200
parents ad1e6b8a5109
children 64ed35c97678
files src/imap/cmd-idle.c
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-idle.c	Tue Dec 06 14:54:42 2005 +0200
+++ b/src/imap/cmd-idle.c	Tue Dec 06 16:32:50 2005 +0200
@@ -34,6 +34,11 @@
 		ctx->to = NULL;
 	}
 
+	if (ctx->sync_ctx != NULL) {
+		/* we're here only in connection failure cases */
+		(void)imap_sync_deinit(ctx->sync_ctx);
+	}
+
 	o_stream_cork(client->output);
 
 	if (ctx->dummy_seq != 0) {
@@ -78,6 +83,14 @@
 		return;
 	}
 
+	if (ctx->sync_ctx != NULL) {
+		/* we're still sending output to client. wait until it's all
+		   sent so we don't lose any changes. */
+		io_remove(client->io);
+		client->io = NULL;
+		return;
+	}
+
 	while ((line = i_stream_next_line(client->input)) != NULL) {
 		if (client->input_skip_line)
 			client->input_skip_line = FALSE;
@@ -163,8 +176,14 @@
 		   client */
                 idle_callback(client->mailbox, client);
 	}
+        client->output_pending = FALSE;
 
-        client->output_pending = FALSE;
+	if (client->io == NULL) {
+		/* input is pending */
+		client->io = io_add(i_stream_get_fd(client->input),
+				    IO_READ, idle_client_input, ctx);
+		idle_client_input(ctx);
+	}
 	return FALSE;
 }