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



commit 5f05f85de57377fcd81cabfa7c6ddd2daef4eafa
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 5016562..13bcb7d 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 e6d02d7..7241a9f 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -1210,6 +1210,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,
@@ -3668,6 +3687,7 @@ camel_imapx_server_idle (CamelIMAPXServer *is,
                          GError **error)
 {
        CamelIMAPXJob *job;
+       gint previous_connection_timeout;
        gboolean success;
 
        job = camel_imapx_job_new (cancellable);
@@ -3676,8 +3696,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]