[dovecot-cvs] dovecot/src/imap cmd-idle.c,1.24,1.25

cras at dovecot.org cras at dovecot.org
Sat Jan 7 02:53:16 EET 2006


Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv22336

Modified Files:
	cmd-idle.c 
Log Message:
When idling, send an OK message every two minutes to break NAT/firewall timeouts.



Index: cmd-idle.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-idle.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- cmd-idle.c	6 Jan 2006 18:22:36 -0000	1.24
+++ cmd-idle.c	7 Jan 2006 00:53:14 -0000	1.25
@@ -10,13 +10,16 @@
 #include <stdlib.h>
 
 #define DEFAULT_IDLE_CHECK_INTERVAL 30
+/* Send some noice to client every few minutes to avoid NATs and stateful
+   firewalls from closing the connection */
+#define KEEPALIVE_TIMEOUT (2*60)
 
 struct cmd_idle_context {
 	struct client *client;
 	struct client_command_context *cmd;
 
 	struct imap_sync_context *sync_ctx;
-	struct timeout *to;
+	struct timeout *idle_to, *keepalive_to;
 	uint32_t dummy_seq;
 
 	unsigned int idle_timeout:1;
@@ -29,9 +32,13 @@
 {
 	struct client *client = ctx->client;
 
-	if (ctx->to != NULL) {
-		timeout_remove(ctx->to);
-		ctx->to = NULL;
+	if (ctx->idle_to != NULL) {
+		timeout_remove(ctx->idle_to);
+		ctx->idle_to = NULL;
+	}
+	if (ctx->keepalive_to != NULL) {
+		timeout_remove(ctx->keepalive_to);
+		ctx->keepalive_to = NULL;
 	}
 
 	if (ctx->sync_ctx != NULL) {
@@ -123,8 +130,8 @@
 	   we're about to disconnect unless it does something. send a fake
 	   EXISTS to see if it responds. it's expunged later. */
 
-	timeout_remove(ctx->to);
-	ctx->to = NULL;
+	timeout_remove(ctx->idle_to);
+	ctx->idle_to = NULL;
 
 	if (ctx->sync_ctx != NULL) {
 		/* we're already syncing.. do this after it's finished */
@@ -135,6 +142,18 @@
 	idle_send_expunge(ctx);
 }
 
+static void keepalive_timeout(void *context)
+{
+	struct cmd_idle_context *ctx = context;
+
+	if (ctx->client->output_pending) {
+		/* it's busy sending output */
+		return;
+	}
+
+	client_send_line(ctx->client, "* OK Still here");
+}
+
 static void idle_sync_now(struct mailbox *box, struct cmd_idle_context *ctx)
 {
 	i_assert(ctx->sync_ctx == NULL);
@@ -210,9 +229,11 @@
 
 	if ((client_workarounds & WORKAROUND_OUTLOOK_IDLE) != 0 &&
 	    client->mailbox != NULL) {
-		ctx->to = timeout_add((CLIENT_IDLE_TIMEOUT - 60) * 1000,
-				      idle_timeout, ctx);
+		ctx->idle_to = timeout_add((CLIENT_IDLE_TIMEOUT - 60) * 1000,
+					   idle_timeout, ctx);
 	}
+	ctx->keepalive_to = timeout_add(KEEPALIVE_TIMEOUT * 1000,
+					keepalive_timeout, ctx);
 
 	str = getenv("MAILBOX_IDLE_CHECK_INTERVAL");
 	interval = str == NULL ? 0 : (unsigned int)strtoul(str, NULL, 10);



More information about the dovecot-cvs mailing list