[evolution-data-server] Use 90 seconds timeout for Camel connections



commit ece2bc46ce8ef2a554ca88b105dd66c3369dcf42
Author: Milan Crha <mcrha redhat com>
Date:   Fri Oct 24 12:17:23 2014 +0200

    Use 90 seconds timeout for Camel connections
    
    The Camel connections used to use timeouts, but they were unset
    for IMAPx's IDLE. The outcome was that all other connections, not
    only the IDLE, could wait for ever. A better way to deal with it
    is to unset timeout on the connection only when necessary, aka only
    during the IDLE being issued on the connection, and let all the other
    connections timeout when they do not get a response within the limit.

 camel/camel-network-service.c              |    8 ++++++++
 camel/providers/imapx/camel-imapx-server.c |   25 +++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-network-service.c b/camel/camel-network-service.c
index 6f2948b..97db15d 100644
--- a/camel/camel-network-service.c
+++ b/camel/camel-network-service.c
@@ -655,6 +655,14 @@ network_service_connect_sync (CamelNetworkService *service,
 
        g_object_unref (settings);
 
+       if (connection) {
+               GSocket *socket;
+
+               socket = g_socket_connection_get_socket (connection);
+               if (socket)
+                       g_socket_set_timeout (socket, 90);
+       }
+
        return (connection != NULL) ? G_IO_STREAM (connection) : NULL;
 }
 
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 5db4157..d92ddeb 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1202,6 +1202,25 @@ imapx_server_reset_inactivity_timer (CamelIMAPXServer *is)
        g_mutex_unlock (&is->priv->inactivity_timeout_lock);
 }
 
+static gint
+imapx_server_set_connection_timeout (GIOStream *connection,
+                                    gint timeout_seconds)
+{
+       GSocket *socket;
+       gint previous_timeout = -1;
+
+       if (!G_IS_SOCKET_CONNECTION (connection))
+               return previous_timeout;
+
+       socket = g_socket_connection_get_socket (connection);
+       if (socket) {
+               previous_timeout = g_socket_get_timeout (socket);
+               g_socket_set_timeout (socket, timeout_seconds);
+       }
+
+       return previous_timeout;
+}
+
 /* Must hold QUEUE_LOCK */
 static void
 imapx_command_start (CamelIMAPXServer *is,
@@ -3660,6 +3679,7 @@ camel_imapx_server_idle (CamelIMAPXServer *is,
                          GError **error)
 {
        CamelIMAPXJob *job;
+       gint previous_connection_timeout;
        gboolean success;
 
        job = camel_imapx_job_new (cancellable);
@@ -3668,8 +3688,13 @@ camel_imapx_server_idle (CamelIMAPXServer *is,
 
        camel_imapx_job_set_mailbox (job, mailbox);
 
+       previous_connection_timeout = imapx_server_set_connection_timeout (is->priv->connection, 0);
+
        success = imapx_submit_job (is, job, error);
 
+       if (previous_connection_timeout >= 0)
+               imapx_server_set_connection_timeout (is->priv->connection, previous_connection_timeout);
+
        camel_imapx_job_unref (job);
 
        return success;


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