[evolution-data-server] camel_folder_get_message_sync: Recover from dropped connection.



commit 6e66ea07cb15b9bea07f81fb137a7585b54222d0
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Jul 12 16:26:02 2013 -0400

    camel_folder_get_message_sync: Recover from dropped connection.
    
    If the requested message is not cached, and the service is online but
    disconnected, reconnect before requesting the message.  This is meant
    to help recover from dropped server connections.

 camel/camel-folder.c |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 51abe3d..d0e8cec 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -36,6 +36,7 @@
 #include "camel-folder.h"
 #include "camel-mempool.h"
 #include "camel-mime-message.h"
+#include "camel-offline-store.h"
 #include "camel-operation.h"
 #include "camel-session.h"
 #include "camel-store.h"
@@ -478,6 +479,42 @@ folder_transfer_message_to (CamelFolder *source,
        camel_message_info_free (info);
 }
 
+static gboolean
+folder_maybe_connect_sync (CamelFolder *folder,
+                           GCancellable *cancellable,
+                           GError **error)
+{
+       CamelService *service;
+       CamelStore *parent_store;
+       CamelServiceConnectionStatus status;
+       gboolean connect = FALSE;
+       gboolean success = TRUE;
+
+       /* This is meant to recover from dropped connections
+        * when the CamelService is online but disconnected. */
+
+       parent_store = camel_folder_get_parent_store (folder);
+
+       service = CAMEL_SERVICE (parent_store);
+       status = camel_service_get_connection_status (service);
+       connect = (status != CAMEL_SERVICE_CONNECTED);
+
+       if (CAMEL_IS_OFFLINE_STORE (parent_store)) {
+               CamelOfflineStore *offline_store;
+
+               offline_store = CAMEL_OFFLINE_STORE (parent_store);
+               if (!camel_offline_store_get_online (offline_store))
+                       connect = FALSE;
+       }
+
+       if (connect) {
+               success = camel_service_connect_sync (
+                       service, cancellable, error);
+       }
+
+       return success;
+}
+
 static void
 folder_set_parent_store (CamelFolder *folder,
                          CamelStore *parent_store)
@@ -3749,7 +3786,11 @@ camel_folder_get_message_sync (CamelFolder *folder,
                        folder, message_uid, cancellable);
        }
 
-       if (!message) {
+       if (message == NULL) {
+               /* Recover from a dropped connection, unless we're offline. */
+               if (!folder_maybe_connect_sync (folder, cancellable, error))
+                       return NULL;
+
                camel_folder_lock (folder, CAMEL_FOLDER_REC_LOCK);
 
                /* Check for cancellation after locking. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]