From 6d220c28a4b7edc65f6397018dcc5aee7be8f8db Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Wed, 15 Jun 2011 12:26:26 +0100 Subject: [PATCH] Check for the specific error codes when reconnecting The NetworkError connection status maps to several TpErrors, so first check the error codes to decide whether we should automatically reconnect, and fallback to the connection status if we don't recognize the error. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37844 --- src/mcd-connection.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/mcd-connection.c b/src/mcd-connection.c index 3aaf37c..8cb0248 100644 --- a/src/mcd-connection.c +++ b/src/mcd-connection.c @@ -1190,6 +1190,68 @@ on_connection_status_changed (TpConnection *tp_conn, GParamSpec *pspec, } } +static gboolean +connection_should_reconnect (TpConnection *tp_conn, + guint domain, + gint code) +{ + TpConnectionStatusReason reason; + + if (domain == TP_ERROR) + { + switch (code) + { + case TP_ERROR_CONNECTION_FAILED: + case TP_ERROR_CONNECTION_LOST: + case TP_ERROR_DISCONNECTED: + case TP_ERROR_NETWORK_ERROR: + DEBUG ("error code %s, reconnecting", + tp_error_get_dbus_name (code)); + return TRUE; + + case TP_ERROR_SOFTWARE_UPGRADE_REQUIRED: + case TP_ERROR_SERVICE_BUSY: + case TP_ERROR_CONNECTION_REPLACED: + case TP_ERROR_ALREADY_CONNECTED: + case TP_ERROR_CONNECTION_REFUSED: + /* possibly a few others (notably, all the encryption + * things), but the others are hopefully not + * generically mapped to NETWORK_ERROR anyway */ + DEBUG ("error code %s, not reconnecting", + tp_error_get_dbus_name (code)); + return FALSE; + } + } + else if (domain == TP_DBUS_ERRORS) + { + switch (code) + { + case TP_DBUS_ERROR_NAME_OWNER_LOST: + /* CM crashed */ + DEBUG ("dbus error code: OWNER_LOST, reconnecting", code); + return TRUE; + } + } + + /* not sure what the GError meant, so check the generic + * status code */ + tp_connection_get_status (tp_conn, &reason); + + switch (reason) + { + case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR: + case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED: + DEBUG ("StatusReason %d, reconnecting", reason); + return TRUE; + default: + break; + } + + DEBUG ("not reconnecting"); + + return FALSE; +} + static void mcd_connection_invalidated_cb (TpConnection *tp_conn, guint domain, @@ -1219,8 +1281,7 @@ mcd_connection_invalidated_cb (TpConnection *tp_conn, priv->connected = FALSE; - if ((priv->abort_reason == TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED || - priv->abort_reason == TP_CONNECTION_STATUS_REASON_NETWORK_ERROR) && + if (connection_should_reconnect (tp_conn, domain, code) && priv->probation_drop_count <= PROBATION_MAX_DROPPED) { /* we were disconnected by a network error or by a connection manager -- 1.7.5.4