From 4384a1f4688968bcf621ddcaae58438374cad29d Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 23 Apr 2014 20:51:57 +0100 Subject: [PATCH] Tidied jabber_process_events --- src/xmpp/connection.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 785003e8..95c7fd82 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -205,22 +205,28 @@ _jabber_shutdown(void) static void _jabber_process_events(void) { - // run xmpp event loop if connected, connecting or disconnecting - if (jabber_conn.conn_status == JABBER_CONNECTED - || jabber_conn.conn_status == JABBER_CONNECTING - || jabber_conn.conn_status == JABBER_DISCONNECTING) { - xmpp_run_once(jabber_conn.ctx, 10); + int reconnect_sec; + int elapsed_sec; - // check timer and reconnect if disconnected and timer set - } else if (prefs_get_reconnect() != 0) { - if ((jabber_conn.conn_status == JABBER_DISCONNECTED) && - (reconnect_timer != NULL)) { - if (g_timer_elapsed(reconnect_timer, NULL) > prefs_get_reconnect()) { - _jabber_reconnect(); + switch (jabber_conn.conn_status) + { + case JABBER_CONNECTED: + case JABBER_CONNECTING: + case JABBER_DISCONNECTING: + xmpp_run_once(jabber_conn.ctx, 10); + break; + case JABBER_DISCONNECTED: + reconnect_sec = prefs_get_reconnect(); + if ((reconnect_sec != 0) && (reconnect_timer != NULL)) { + elapsed_sec = g_timer_elapsed(reconnect_timer, NULL); + if (elapsed_sec > reconnect_sec) { + _jabber_reconnect(); + } } - } + break; + default: + break; } - } static GList *