dovecot-2.0: director: Send PINGs every 15 seconds for idling di...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 18 22:00:28 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/e75dab14bb2f
changeset: 11586:e75dab14bb2f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 18 20:00:24 2010 +0100
description:
director: Send PINGs every 15 seconds for idling director connections.

diffstat:

 src/director/director-connection.c |  31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

diffs (82 lines):

diff -r f0fb8151c6b4 -r e75dab14bb2f src/director/director-connection.c
--- a/src/director/director-connection.c	Fri Jun 18 19:21:50 2010 +0100
+++ b/src/director/director-connection.c	Fri Jun 18 20:00:24 2010 +0100
@@ -25,7 +25,10 @@
 #define MAX_INBUF_SIZE 1024
 #define MAX_OUTBUF_SIZE (1024*1024*10)
 #define OUTBUF_FLUSH_THRESHOLD (1024*128)
+/* How long to wait for PONG after PING request */
 #define DIRECTOR_CONNECTION_PING_TIMEOUT_MSECS (2*1000)
+/* How long to wait to send PING when connection is idle */
+#define DIRECTOR_CONNECTION_PING_INTERVAL_MSECS (15*1000)
 
 struct director_connection {
 	struct director *dir;
@@ -50,6 +53,7 @@
 	unsigned int handshake_received:1;
 	unsigned int ignore_host_events:1;
 	unsigned int handshake_sending_hosts:1;
+	unsigned int ping_waiting:1;
 };
 
 static void director_connection_ping(struct director_connection *conn);
@@ -382,6 +386,10 @@
 					net_ip2addr(&dir->self_ip),
 					dir->self_port, dir->sync_seq));
 	}
+	if (conn->to_ping == NULL) {
+		conn->to_ping = timeout_add(DIRECTOR_CONNECTION_PING_INTERVAL_MSECS,
+					    director_connection_ping, conn);
+	}
 }
 
 static bool
@@ -597,6 +605,18 @@
 	return TRUE;
 }
 
+static bool director_cmd_pong(struct director_connection *conn)
+{
+	if (!conn->ping_waiting)
+		return TRUE;
+
+	conn->ping_waiting = FALSE;
+	timeout_remove(&conn->to_ping);
+	conn->to_ping = timeout_add(DIRECTOR_CONNECTION_PING_INTERVAL_MSECS,
+				    director_connection_ping, conn);
+	return TRUE;
+}
+
 static bool
 director_connection_handle_line(struct director_connection *conn,
 				const char *line)
@@ -639,11 +659,8 @@
 		director_connection_send(conn, "PONG\n");
 		return TRUE;
 	}
-	if (strcmp(cmd, "PONG") == 0) {
-		if (conn->to_ping != NULL)
-			timeout_remove(&conn->to_ping);
-		return TRUE;
-	}
+	if (strcmp(cmd, "PONG") == 0)
+		return director_cmd_pong(conn);
 	i_error("director(%s): Unknown command (in this state): %s",
 		conn->name, cmd);
 	return FALSE;
@@ -907,12 +924,14 @@
 
 static void director_connection_ping(struct director_connection *conn)
 {
-	if (conn->to_ping != NULL)
+	if (conn->ping_waiting)
 		return;
 
+	timeout_remove(&conn->to_ping);
 	conn->to_ping = timeout_add(DIRECTOR_CONNECTION_PING_TIMEOUT_MSECS,
 				    director_connection_ping_timeout, conn);
 	director_connection_send(conn, "PING\n");
+	conn->ping_waiting = TRUE;
 }
 
 const char *director_connection_get_name(struct director_connection *conn)


More information about the dovecot-cvs mailing list