dovecot-2.2: imapc: Avoid sending unnecessary IDLEs that are imm...

dovecot at dovecot.org dovecot at dovecot.org
Sun Nov 17 15:16:43 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/ef649e2a980e
changeset: 16972:ef649e2a980e
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Nov 17 15:13:58 2013 +0200
description:
imapc: Avoid sending unnecessary IDLEs that are immediately aborted.

diffstat:

 src/lib-imap-client/imapc-client-private.h |   3 +++
 src/lib-imap-client/imapc-client.c         |  18 ++++++++++++++++--
 src/lib-storage/index/imapc/imapc-sync.c   |  10 +++++++---
 3 files changed, 26 insertions(+), 5 deletions(-)

diffs (77 lines):

diff -r fa4c87b510ea -r ef649e2a980e src/lib-imap-client/imapc-client-private.h
--- a/src/lib-imap-client/imapc-client-private.h	Sun Nov 17 15:03:31 2013 +0200
+++ b/src/lib-imap-client/imapc-client-private.h	Sun Nov 17 15:13:58 2013 +0200
@@ -3,6 +3,8 @@
 
 #include "imapc-client.h"
 
+#define IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS 100
+
 struct imapc_client_connection {
 	struct imapc_connection *conn;
 	struct imapc_client_mailbox *box;
@@ -27,6 +29,7 @@
 	struct imapc_client *client;
 	struct imapc_connection *conn;
 	struct imapc_msgmap *msgmap;
+	struct timeout *to_send_idle;
 
 	void (*reopen_callback)(void *context);
 	void *reopen_context;
diff -r fa4c87b510ea -r ef649e2a980e src/lib-imap-client/imapc-client.c
--- a/src/lib-imap-client/imapc-client.c	Sun Nov 17 15:03:31 2013 +0200
+++ b/src/lib-imap-client/imapc-client.c	Sun Nov 17 15:13:58 2013 +0200
@@ -337,6 +337,8 @@
 	}
 
 	imapc_msgmap_deinit(&box->msgmap);
+	if (box->to_send_idle != NULL)
+		timeout_remove(&box->to_send_idle);
 	i_free(box);
 }
 
@@ -359,10 +361,22 @@
 	return box->msgmap;
 }
 
+static void imapc_client_mailbox_idle_send(struct imapc_client_mailbox *box)
+{
+	timeout_remove(&box->to_send_idle);
+	if (imapc_client_mailbox_is_opened(box))
+		imapc_connection_idle(box->conn);
+}
+
 void imapc_client_mailbox_idle(struct imapc_client_mailbox *box)
 {
-	if (imapc_client_mailbox_is_opened(box))
-		imapc_connection_idle(box->conn);
+	/* send the IDLE with a delay to avoid unnecessary IDLEs that are
+	   immediately aborted */
+	if (box->to_send_idle == NULL && imapc_client_mailbox_is_opened(box)) {
+		box->to_send_idle =
+			timeout_add_short(IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS,
+					  imapc_client_mailbox_idle_send, box);
+	}
 	box->reconnect_ok = TRUE;
 }
 
diff -r fa4c87b510ea -r ef649e2a980e src/lib-storage/index/imapc/imapc-sync.c
--- a/src/lib-storage/index/imapc/imapc-sync.c	Sun Nov 17 15:03:31 2013 +0200
+++ b/src/lib-storage/index/imapc/imapc-sync.c	Sun Nov 17 15:13:58 2013 +0200
@@ -458,9 +458,13 @@
 	}
 
 	capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
-	if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0) {
-		/* IDLE not supported. do NOOP to get latest changes
-		   before starting sync. */
+	if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
+	    (flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0) {
+		/* do NOOP to make sure we have the latest changes before
+		   starting sync. this is necessary either because se don't
+		   support IDLE at all, or because we want to be sure that we
+		   have the latest changes (IDLE is started with a small delay,
+		   so we might not actually even be in IDLE right not) */
 		imapc_mailbox_noop(mbox);
 	}
 


More information about the dovecot-cvs mailing list