imapx_connect_sync: Use connection manager to connect to the server
authorMilan Crha <mcrha@redhat.com>
Fri, 25 Apr 2014 06:11:03 +0000 (08:11 +0200)
committerMilan Crha <mcrha@redhat.com>
Fri, 25 Apr 2014 06:16:33 +0000 (08:16 +0200)
This function opened a new connection to the server, but immediately
dropped it, which, apart of waste of resources, can cause trouble
when other parts asked for the connection to the server, but those
using the connection manager, which is the correct way of dealing
with connections to the server now. The previous behaviour can cause
a race condition on the imapx_store->priv->connecting_server, which
led later to runtime warnings and misbehaviour in general.

camel/providers/imapx/camel-imapx-store.c

index 526a5a3..8bd0c9d 100644 (file)
@@ -769,37 +769,14 @@ imapx_connect_sync (CamelService *service,
                     GCancellable *cancellable,
                     GError **error)
 {
-       CamelIMAPXStorePrivate *priv;
+       CamelIMAPXStore *imapx_store;
        CamelIMAPXServer *imapx_server;
        gboolean success;
 
-       priv = CAMEL_IMAPX_STORE_GET_PRIVATE (service);
-
-       imapx_server = camel_imapx_server_new (CAMEL_IMAPX_STORE (service));
-
-       g_mutex_lock (&priv->server_lock);
-
-       /* We need to share the CamelIMAPXServer instance with the
-        * authenticate_sync() method, but we don't want other parts
-        * getting at it just yet.  So stash it in a special private
-        * variable while connecting to the IMAP server. */
-       g_warn_if_fail (priv->connecting_server == NULL);
-       priv->connecting_server = g_object_ref (imapx_server);
-
-       g_mutex_unlock (&priv->server_lock);
-
-       success = camel_imapx_server_connect (
-               imapx_server, cancellable, error);
-
-       g_mutex_lock (&priv->server_lock);
-
-       g_warn_if_fail (
-               priv->connecting_server == NULL ||
-               priv->connecting_server == imapx_server);
+       imapx_store = CAMEL_IMAPX_STORE (service);
 
-       g_clear_object (&priv->connecting_server);
-
-       g_mutex_unlock (&priv->server_lock);
+       imapx_server = camel_imapx_store_ref_server (imapx_store, NULL, FALSE, cancellable, error);
+       success = imapx_server != NULL;
 
        g_clear_object (&imapx_server);