dovecot-2.2: lib-imap-client: If we get disconnected and reconne...

dovecot at dovecot.org dovecot at dovecot.org
Fri Mar 13 14:29:18 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/cf60180695ac
changeset: 18348:cf60180695ac
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 13 16:28:31 2015 +0200
description:
lib-imap-client: If we get disconnected and reconnect, log it as warning instead of as error.

diffstat:

 src/lib-imap-client/imapc-client.c     |   7 ++++++-
 src/lib-imap-client/imapc-client.h     |   1 +
 src/lib-imap-client/imapc-connection.c |  26 ++++++++++++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)

diffs (91 lines):

diff -r c82e9e5832a0 -r cf60180695ac src/lib-imap-client/imapc-client.c
--- a/src/lib-imap-client/imapc-client.c	Fri Mar 13 16:12:37 2015 +0200
+++ b/src/lib-imap-client/imapc-client.c	Fri Mar 13 16:28:31 2015 +0200
@@ -303,9 +303,14 @@
 	}
 }
 
+bool imapc_client_mailbox_can_reconnect(struct imapc_client_mailbox *box)
+{
+	return box->reopen_callback != NULL && box->reconnect_ok;
+}
+
 void imapc_client_mailbox_reconnect(struct imapc_client_mailbox *box)
 {
-	bool reconnect = box->reopen_callback != NULL && box->reconnect_ok;
+	bool reconnect = imapc_client_mailbox_can_reconnect(box);
 
 	if (reconnect) {
 		i_assert(!box->reconnecting);
diff -r c82e9e5832a0 -r cf60180695ac src/lib-imap-client/imapc-client.h
--- a/src/lib-imap-client/imapc-client.h	Fri Mar 13 16:12:37 2015 +0200
+++ b/src/lib-imap-client/imapc-client.h	Fri Mar 13 16:28:31 2015 +0200
@@ -182,6 +182,7 @@
 					void (*callback)(void *context),
 					void *context);
 void imapc_client_mailbox_close(struct imapc_client_mailbox **box);
+bool imapc_client_mailbox_can_reconnect(struct imapc_client_mailbox *box);
 void imapc_client_mailbox_reconnect(struct imapc_client_mailbox *box);
 struct imapc_command *
 imapc_client_mailbox_cmd(struct imapc_client_mailbox *box,
diff -r c82e9e5832a0 -r cf60180695ac src/lib-imap-client/imapc-connection.c
--- a/src/lib-imap-client/imapc-connection.c	Fri Mar 13 16:12:37 2015 +0200
+++ b/src/lib-imap-client/imapc-connection.c	Fri Mar 13 16:28:31 2015 +0200
@@ -421,6 +421,14 @@
 	imapc_connection_abort_commands(conn, NULL, FALSE);
 }
 
+static bool imapc_connection_can_reconnect(struct imapc_connection *conn)
+{
+	if (conn->selected_box != NULL)
+		return imapc_client_mailbox_can_reconnect(conn->selected_box);
+	else
+		return FALSE;
+}
+
 static void imapc_connection_reconnect(struct imapc_connection *conn)
 {
 	if (conn->selected_box != NULL)
@@ -1351,6 +1359,7 @@
 static void imapc_connection_input(struct imapc_connection *conn)
 {
 	const char *errstr;
+	string_t *str;
 	ssize_t ret = 0;
 
 	/* we need to read as much as we can with SSL streams to avoid
@@ -1361,23 +1370,28 @@
 
 	if (ret < 0) {
 		/* disconnected */
+		str = t_str_new(128);
 		if (conn->disconnect_reason != NULL) {
-			i_error("imapc(%s): Server disconnected with message: %s",
-				conn->name, conn->disconnect_reason);
+			str_printfa(str, "Server disconnected with message: %s",
+				    conn->disconnect_reason);
 		} else if (conn->ssl_iostream == NULL) {
 			errstr = conn->input->stream_errno == 0 ? "EOF" :
 				i_stream_get_error(conn->input);
-			i_error("imapc(%s): Server disconnected unexpectedly: %s",
-				conn->name, errstr);
+			str_printfa(str, "Server disconnected unexpectedly: %s",
+				    errstr);
 		} else {
 			errstr = ssl_iostream_get_last_error(conn->ssl_iostream);
 			if (errstr == NULL) {
 				errstr = conn->input->stream_errno == 0 ? "EOF" :
 					i_stream_get_error(conn->input);
 			}
-			i_error("imapc(%s): Server disconnected unexpectedly: %s",
-				conn->name, errstr);
+			str_printfa(str, "Server disconnected unexpectedly: %s",
+				    errstr);
 		}
+		if (!imapc_connection_can_reconnect(conn))
+			i_error("imapc(%s): %s", conn->name, str_c(str));
+		else
+			i_warning("imapc(%s): %s - reconnecting", conn->name, str_c(str));
 		imapc_connection_reconnect(conn);
 	}
 	imapc_connection_unref(&conn);


More information about the dovecot-cvs mailing list