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



commit cdbe6fd1af4d352f3c1b69ac73b619e785d68c9b
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 13bcb7d..3e6462d 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 c56ed94..d55ee32 100644
--- a/camel/camel-offline-store.c
+++ b/camel/camel-offline-store.c
@@ -188,9 +188,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);
@@ -288,9 +297,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]