[evolution-data-server] [CamelOfflineStore] Count with host reachability update delay



commit 13d7c86c2cc75bbcda06210c94bbb31454f6dbee
Author: Milan Crha <mcrha redhat com>
Date:   Fri Oct 24 13:36:18 2014 +0200

    [CamelOfflineStore] Count with host reachability update delay
    
    Since the change for bug 712392 the cached host_reachable value
    can be stale in certain operations, like when going online or
    offline due to the connection change. Due to that the CamelOfflineStore
    should rather ask for an up-to-date value, instead of the cached.

 camel/camel-network-service.c |   13 ++++++++++++-
 camel/camel-offline-store.c   |   22 +++++++++++++++++-----
 2 files changed, 29 insertions(+), 6 deletions(-)
---
diff --git a/camel/camel-network-service.c b/camel/camel-network-service.c
index 97db15d..188b2bb 100644
--- a/camel/camel-network-service.c
+++ b/camel/camel-network-service.c
@@ -1037,8 +1037,19 @@ camel_network_service_can_reach_sync (CamelNetworkService *service,
                G_IS_IO_ERROR (local_error, G_IO_ERROR_HOST_UNREACHABLE) ||
                G_IS_RESOLVER_ERROR (local_error, G_RESOLVER_ERROR_NOT_FOUND);
 
-       if (update_property)
+       if (update_property) {
+               g_mutex_lock (&priv->update_host_reachable_lock);
+
+               if (priv->update_host_reachable) {
+                       g_source_destroy (priv->update_host_reachable);
+                       g_source_unref (priv->update_host_reachable);
+                       priv->update_host_reachable = NULL;
+               }
+
+               g_mutex_unlock (&priv->update_host_reachable_lock);
+
                network_service_set_host_reachable (service, can_reach);
+       }
 
        g_clear_object (&connectable);
 
diff --git a/camel/camel-offline-store.c b/camel/camel-offline-store.c
index 2ef00b0..764278c 100644
--- a/camel/camel-offline-store.c
+++ b/camel/camel-offline-store.c
@@ -187,9 +187,18 @@ camel_offline_store_set_online_sync (CamelOfflineStore *store,
        status = camel_service_get_connection_status (service);
 
        if (CAMEL_IS_NETWORK_SERVICE (store)) {
-               host_reachable =
-                       camel_network_service_get_host_reachable (
-                       CAMEL_NETWORK_SERVICE (store));
+               /* When going to set the 'online' state, then check with up-to-date
+                  value, otherwise use the cached value. The cached value is
+                  updated with few seconds timeout, thus it can be stale here. */
+               if (online)
+                       host_reachable =
+                               camel_network_service_can_reach_sync (
+                               CAMEL_NETWORK_SERVICE (store),
+                               cancellable, NULL);
+               else
+                       host_reachable =
+                               camel_network_service_get_host_reachable (
+                               CAMEL_NETWORK_SERVICE (store));
        }
 
        store_is_online = camel_offline_store_get_online (store);
@@ -287,9 +296,12 @@ camel_offline_store_prepare_for_offline_sync (CamelOfflineStore *store,
        session = camel_service_ref_session (service);
 
        if (CAMEL_IS_NETWORK_SERVICE (store)) {
+               /* Check with up-to-date value. The cached value is updated with
+                  few seconds timeout, thus it can be stale here. */
                host_reachable =
-                       camel_network_service_get_host_reachable (
-                       CAMEL_NETWORK_SERVICE (store));
+                       camel_network_service_can_reach_sync (
+                       CAMEL_NETWORK_SERVICE (store),
+                       cancellable, NULL);
        }
 
        store_is_online = camel_offline_store_get_online (store);


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