dovecot-2.0: imap: IDLE now sends "Still here" notifications to ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 16 01:31:18 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/7f77bc5a866c
changeset: 10075:7f77bc5a866c
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 15 18:31:11 2009 -0400
description:
imap: IDLE now sends "Still here" notifications to same user's connections at the same time.
Perhaps this will save some battery power with mobile clients that open
multiple connections.

diffstat:

1 file changed, 22 insertions(+), 5 deletions(-)
src/imap/cmd-idle.c |   27 ++++++++++++++++++++++-----

diffs (72 lines):

diff -r 1d2d55d9779e -r 7f77bc5a866c src/imap/cmd-idle.c
--- a/src/imap/cmd-idle.c	Thu Oct 15 16:18:58 2009 -0400
+++ b/src/imap/cmd-idle.c	Thu Oct 15 18:31:11 2009 -0400
@@ -4,6 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
+#include "crc32.h"
 #include "mail-storage-settings.h"
 #include "imap-commands.h"
 #include "imap-sync.h"
@@ -21,6 +22,7 @@ struct cmd_idle_context {
 	unsigned int sync_pending:1;
 };
 
+static void idle_add_keepalive_timeout(struct cmd_idle_context *ctx);
 static bool cmd_idle_continue(struct client_command_context *cmd);
 
 static void
@@ -108,6 +110,8 @@ static void keepalive_timeout(struct cmd
 	   several clients that really want to IDLE forever and there's not
 	   much harm in letting them do so. */
 	timeout_reset(ctx->client->to_idle);
+	/* recalculate time for the next keepalive timeout */
+	idle_add_keepalive_timeout(ctx);
 }
 
 static void idle_sync_now(struct mailbox *box, struct cmd_idle_context *ctx)
@@ -127,6 +131,22 @@ static void idle_callback(struct mailbox
 		ctx->manual_cork = TRUE;
 		idle_sync_now(box, ctx);
 	}
+}
+
+static void idle_add_keepalive_timeout(struct cmd_idle_context *ctx)
+{
+	unsigned int interval = ctx->client->set->imap_idle_notify_interval;
+
+	if (interval == 0)
+		return;
+
+	interval -= (time(NULL) +
+		     crc32_str(ctx->client->user->username)) % interval;
+
+	if (ctx->keepalive_to != NULL)
+		timeout_remove(&ctx->keepalive_to);
+	ctx->keepalive_to = timeout_add(interval * 1000,
+					keepalive_timeout, ctx);
 }
 
 static bool cmd_idle_continue(struct client_command_context *cmd)
@@ -166,7 +186,7 @@ static bool cmd_idle_continue(struct cli
 	}
 	if (client->output->offset != orig_offset &&
 	    ctx->keepalive_to != NULL)
-		timeout_reset(ctx->keepalive_to);
+		idle_add_keepalive_timeout(ctx);
 
 	if (ctx->sync_pending) {
 		/* more changes occurred while we were sending changes to
@@ -204,10 +224,7 @@ bool cmd_idle(struct client_command_cont
 	ctx = p_new(cmd->pool, struct cmd_idle_context, 1);
 	ctx->cmd = cmd;
 	ctx->client = client;
-
-	ctx->keepalive_to = client->set->imap_idle_notify_interval == 0 ? NULL :
-		timeout_add(client->set->imap_idle_notify_interval * 1000,
-			    keepalive_timeout, ctx);
+	idle_add_keepalive_timeout(ctx);
 
 	if (client->mailbox != NULL) {
 		const struct mail_storage_settings *set;


More information about the dovecot-cvs mailing list