dovecot-2.2: lib-imap-client: Allow reconnecting to IMAP server ...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Aug 25 13:59:05 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/feef967b10fe
changeset: 19005:feef967b10fe
user: Timo Sirainen <tss at iki.fi>
date: Tue Aug 25 16:57:57 2015 +0300
description:
lib-imap-client: Allow reconnecting to IMAP server even if there had been no idle moments.
diffstat:
src/lib-imap-client/imapc-client.c | 8 ++++++++
src/lib-imap-client/imapc-connection.c | 17 +++++++++++++++++
src/lib-imap-client/imapc-connection.h | 1 +
3 files changed, 26 insertions(+), 0 deletions(-)
diffs (87 lines):
diff -r e5bc6d90649b -r feef967b10fe src/lib-imap-client/imapc-client.c
--- a/src/lib-imap-client/imapc-client.c Tue Aug 25 16:55:00 2015 +0300
+++ b/src/lib-imap-client/imapc-client.c Tue Aug 25 16:57:57 2015 +0300
@@ -299,6 +299,7 @@
if (reply->state == IMAPC_COMMAND_STATE_OK) {
/* reopen the mailbox */
box->reopen_callback(box->reopen_context);
+ imapc_connection_set_reconnected(box->conn);
} else {
imapc_connection_abort_commands(box->conn, NULL, FALSE);
}
@@ -306,6 +307,9 @@
bool imapc_client_mailbox_can_reconnect(struct imapc_client_mailbox *box)
{
+ /* the reconnect_ok flag attempts to avoid infinite reconnection loops
+ to a server that keeps disconnecting us (e.g. some of the commands
+ we send keeps crashing it always) */
return box->reopen_callback != NULL && box->reconnect_ok;
}
@@ -322,6 +326,9 @@
imapc_connection_connect(box->conn,
imapc_client_reconnect_cb, box);
}
+ /* if we fail again, avoid reconnecting immediately. if the server is
+ broken we could just get into an infinitely failing reconnection
+ loop. */
box->reconnect_ok = FALSE;
}
@@ -393,6 +400,7 @@
timeout_add_short(IMAPC_CLIENT_IDLE_SEND_DELAY_MSECS,
imapc_client_mailbox_idle_send, box);
}
+ /* we're done with all work at this point. */
box->reconnect_ok = TRUE;
}
diff -r e5bc6d90649b -r feef967b10fe src/lib-imap-client/imapc-connection.c
--- a/src/lib-imap-client/imapc-connection.c Tue Aug 25 16:55:00 2015 +0300
+++ b/src/lib-imap-client/imapc-connection.c Tue Aug 25 16:57:57 2015 +0300
@@ -110,6 +110,7 @@
ARRAY_TYPE(imapc_command) cmd_send_queue;
/* commands that have been sent, waiting for their tagged reply */
ARRAY_TYPE(imapc_command) cmd_wait_list;
+ unsigned int reconnect_command_count;
unsigned int ips_count, prev_connect_idx;
struct ip_addr *ips;
@@ -1303,6 +1304,16 @@
imapc_connection_unselect(conn->selected_box);
}
+ if (conn->reconnect_command_count > 0) {
+ if (--conn->reconnect_command_count == 0) {
+ /* we've received replies for all the commands started
+ before reconnection. if we get disconnected now, we
+ can safely reconnect without worrying about infinite
+ reconnect loops. */
+ if (conn->selected_box != NULL)
+ conn->selected_box->reconnect_ok = TRUE;
+ }
+ }
imapc_connection_input_reset(conn);
imapc_command_reply_free(cmd, &reply);
imapc_command_send_more(conn);
@@ -2216,3 +2227,9 @@
cmd->idle = TRUE;
imapc_command_send(cmd, "IDLE");
}
+
+void imapc_connection_set_reconnected(struct imapc_connection *conn)
+{
+ conn->reconnect_command_count = array_count(&conn->cmd_wait_list) +
+ array_count(&conn->cmd_send_queue);
+}
diff -r e5bc6d90649b -r feef967b10fe src/lib-imap-client/imapc-connection.h
--- a/src/lib-imap-client/imapc-connection.h Tue Aug 25 16:55:00 2015 +0300
+++ b/src/lib-imap-client/imapc-connection.h Tue Aug 25 16:57:57 2015 +0300
@@ -52,5 +52,6 @@
imapc_connection_get_mailbox(struct imapc_connection *conn);
void imapc_connection_idle(struct imapc_connection *conn);
+void imapc_connection_set_reconnected(struct imapc_connection *conn);
#endif
More information about the dovecot-cvs
mailing list