dovecot-2.2: lib-imap-client: Connect and command timeouts are n...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 31 17:05:25 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/a6b0a45319ab
changeset: 16433:a6b0a45319ab
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 31 17:05:13 2013 +0300
description:
lib-imap-client: Connect and command timeouts are now configurable.
Also use the same connect timeout for the DNS lookup's timeout.

diffstat:

 src/lib-imap-client/imapc-client.c     |   5 +++++
 src/lib-imap-client/imapc-client.h     |   9 +++++++++
 src/lib-imap-client/imapc-connection.c |  13 +++++--------
 3 files changed, 19 insertions(+), 8 deletions(-)

diffs (95 lines):

diff -r a3b5b762639a -r a6b0a45319ab src/lib-imap-client/imapc-client.c
--- a/src/lib-imap-client/imapc-client.c	Fri May 31 02:29:49 2013 +0300
+++ b/src/lib-imap-client/imapc-client.c	Fri May 31 17:05:13 2013 +0300
@@ -59,6 +59,11 @@
 		p_strdup(pool, set->temp_path_prefix);
 	client->set.rawlog_dir = p_strdup(pool, set->rawlog_dir);
 	client->set.max_idle_time = set->max_idle_time;
+	client->set.connect_timeout_msecs = set->connect_timeout_msecs != 0 ?
+		set->connect_timeout_msecs :
+		IMAPC_DEFAULT_CONNECT_TIMEOUT_MSECS;
+	client->set.cmd_timeout_msecs = set->cmd_timeout_msecs != 0 ?
+		set->cmd_timeout_msecs : IMAPC_DEFAULT_COMMAND_TIMEOUT_MSECS;
 
 	if (set->ssl_mode != IMAPC_CLIENT_SSL_MODE_NONE) {
 		client->set.ssl_mode = set->ssl_mode;
diff -r a3b5b762639a -r a6b0a45319ab src/lib-imap-client/imapc-client.h
--- a/src/lib-imap-client/imapc-client.h	Fri May 31 02:29:49 2013 +0300
+++ b/src/lib-imap-client/imapc-client.h	Fri May 31 17:05:13 2013 +0300
@@ -49,6 +49,9 @@
 	IMAPC_CLIENT_SSL_MODE_STARTTLS
 };
 
+#define IMAPC_DEFAULT_CONNECT_TIMEOUT_MSECS (1000*30)
+#define IMAPC_DEFAULT_COMMAND_TIMEOUT_MSECS (1000*60*5)
+
 struct imapc_client_settings {
 	const char *host;
 	unsigned int port;
@@ -68,6 +71,12 @@
 	const char *rawlog_dir;
 	const char *ssl_crypto_device;
 	bool debug;
+
+	/* Timeout for logging in. 0 = default. */
+	unsigned int connect_timeout_msecs;
+	/* Timeout for IMAP commands. Reset every time more data is being
+	   sent or received. 0 = default. */
+	unsigned int cmd_timeout_msecs;
 };
 
 struct imapc_command_reply {
diff -r a3b5b762639a -r a6b0a45319ab src/lib-imap-client/imapc-connection.c
--- a/src/lib-imap-client/imapc-connection.c	Fri May 31 02:29:49 2013 +0300
+++ b/src/lib-imap-client/imapc-connection.c	Fri May 31 17:05:13 2013 +0300
@@ -20,9 +20,6 @@
 #include <unistd.h>
 #include <ctype.h>
 
-#define IMAPC_DNS_LOOKUP_TIMEOUT_MSECS (1000*30)
-#define IMAPC_CONNECT_TIMEOUT_MSECS (1000*30)
-#define IMAPC_COMMAND_TIMEOUT_MSECS (1000*60*5)
 #define IMAPC_MAX_INLINE_LITERAL_SIZE (1024*32)
 
 enum imapc_input_state {
@@ -1238,11 +1235,11 @@
 	case IMAPC_CONNECTION_STATE_CONNECTING:
 		i_error("imapc(%s): connect(%s, %u) timed out after %u seconds",
 			conn->name, net_ip2addr(ip), conn->client->set.port,
-			IMAPC_CONNECT_TIMEOUT_MSECS/1000);
+			conn->client->set.connect_timeout_msecs/1000);
 		break;
 	case IMAPC_CONNECTION_STATE_AUTHENTICATING:
 		i_error("imapc(%s): Authentication timed out after %u seconds",
-			conn->name, IMAPC_CONNECT_TIMEOUT_MSECS/1000);
+			conn->name, conn->client->set.connect_timeout_msecs/1000);
 		break;
 	default:
 		i_unreached();
@@ -1307,7 +1304,7 @@
 				    conn);
 	conn->io = io_add(fd, IO_WRITE, imapc_connection_connected, conn);
 	conn->parser = imap_parser_create(conn->input, NULL, (size_t)-1);
-	conn->to = timeout_add(IMAPC_CONNECT_TIMEOUT_MSECS,
+	conn->to = timeout_add(conn->client->set.connect_timeout_msecs,
 			       imapc_connection_timeout, conn);
 	conn->to_output = timeout_add(conn->client->set.max_idle_time*1000,
 				      imapc_connection_reset_idle, conn);
@@ -1364,7 +1361,7 @@
 	memset(&dns_set, 0, sizeof(dns_set));
 	dns_set.dns_client_socket_path =
 		conn->client->set.dns_client_socket_path;
-	dns_set.timeout_msecs = IMAPC_DNS_LOOKUP_TIMEOUT_MSECS;
+	dns_set.timeout_msecs = conn->client->set.connect_timeout_msecs;
 
 	imapc_connection_set_state(conn, IMAPC_CONNECTION_STATE_CONNECTING);
 	if (conn->ips_count == 0 &&
@@ -1679,7 +1676,7 @@
 		/* add timeout for commands if there's not one yet
 		   (pre-login has its own timeout) */
 		if (conn->to == NULL) {
-			conn->to = timeout_add(IMAPC_COMMAND_TIMEOUT_MSECS,
+			conn->to = timeout_add(conn->client->set.cmd_timeout_msecs,
 					       imapc_command_timeout, conn);
 		}
 	}


More information about the dovecot-cvs mailing list