[telepathy-gabble/master] Add a keepalive-interval connection parameter.

Will Thompson will.thompson at collabora.co.uk
Mon Jun 15 02:58:55 PDT 2009


This allows clients to specify the interval between TCP and/or
whitespace keepalives (at the whim of Loudmouth) rather than hardcoding
the interval to 30 seconds (which is still the default). This might be
useful in situations where reducing network activity is more important
than realising the network has gone away quickly.
---
 src/connection-manager.c |    9 +++++++++
 src/connection.c         |   19 +++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/connection-manager.c b/src/connection-manager.c
index f736e92..cd11d73 100644
--- a/src/connection-manager.c
+++ b/src/connection-manager.c
@@ -90,6 +90,7 @@ struct _GabbleParams {
   gboolean ignore_ssl_errors;
   gchar *alias;
   GStrv fallback_socks5_proxies;
+  guint keepalive_interval;
 };
 
 enum {
@@ -113,6 +114,8 @@ enum {
     JABBER_PARAM_IGNORE_SSL_ERRORS,
     JABBER_PARAM_ALIAS,
     JABBER_PARAM_FALLBACK_SOCKS5_PROXIES,
+    JABBER_PARAM_KEEPALIVE_INTERVAL,
+
     LAST_JABBER_PARAM
 };
 
@@ -212,6 +215,10 @@ static TpCMParamSpec jabber_params[] = {
     G_STRUCT_OFFSET (GabbleParams, fallback_socks5_proxies),
     NULL, NULL },
 
+  { "keepalive-interval", "u", G_TYPE_UINT,
+    TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER (30),
+    G_STRUCT_OFFSET (GabbleParams, keepalive_interval), NULL, NULL },
+
   { NULL, NULL, 0, 0, NULL, 0 }
 };
 
@@ -317,6 +324,8 @@ _gabble_connection_manager_new_connection (TpBaseConnectionManager *self,
   SET_PROPERTY_IF_PARAM_SET ("alias", JABBER_PARAM_ALIAS, params->alias);
   SET_PROPERTY_IF_PARAM_SET ("fallback-socks5-proxies",
       JABBER_PARAM_FALLBACK_SOCKS5_PROXIES, params->fallback_socks5_proxies);
+  SET_PROPERTY_IF_PARAM_SET ("keepalive-interval",
+      JABBER_PARAM_KEEPALIVE_INTERVAL, params->keepalive_interval);
 
   /* split up account into username, stream-server and resource */
   if (!_gabble_connection_set_properties_from_account (conn, params->account,
diff --git a/src/connection.c b/src/connection.c
index e0d3703..412bd6d 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -141,6 +141,7 @@ enum
     PROP_IGNORE_SSL_ERRORS,
     PROP_ALIAS,
     PROP_FALLBACK_SOCKS5_PROXIES,
+    PROP_KEEPALIVE_INTERVAL,
 
     LAST_PROPERTY
 };
@@ -169,6 +170,8 @@ struct _GabbleConnectionPrivate
 
   gboolean low_bandwidth;
 
+  guint keepalive_interval;
+
   gchar *https_proxy_server;
   guint16 https_proxy_port;
 
@@ -420,6 +423,9 @@ gabble_connection_get_property (GObject    *object,
     case PROP_FALLBACK_SOCKS5_PROXIES:
       g_value_set_boxed (value, priv->fallback_socks5_proxies);
       break;
+    case PROP_KEEPALIVE_INTERVAL:
+      g_value_set_uint (value, priv->keepalive_interval);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -509,6 +515,9 @@ gabble_connection_set_property (GObject      *object,
     case PROP_FALLBACK_SOCKS5_PROXIES:
       priv->fallback_socks5_proxies = g_value_dup_boxed (value);
       break;
+    case PROP_KEEPALIVE_INTERVAL:
+      priv->keepalive_interval = g_value_get_uint (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -800,6 +809,13 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class)
           G_TYPE_STRV,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_KEEPALIVE_INTERVAL,
+      g_param_spec_uint (
+          "keepalive-interval", "keepalive interval",
+          "Seconds between keepalive packets, or 0 to disable",
+          0, G_MAXUINT, 30,
+          G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gabble_connection_class->properties_class.interfaces = prop_interfaces;
   tp_dbus_properties_mixin_class_init (object_class,
       G_STRUCT_OFFSET (GabbleConnectionClass, properties_class));
@@ -1362,8 +1378,7 @@ _gabble_connection_connect (TpBaseConnection *base,
       lm_ssl_unref (ssl);
     }
 
-  /* send whitespace to the server every 30 seconds */
-  lm_connection_set_keep_alive_rate (conn->lmconn, 30);
+  lm_connection_set_keep_alive_rate (conn->lmconn, priv->keepalive_interval);
 
   lm_connection_set_disconnect_function (conn->lmconn,
                                          connection_disconnected_cb,
-- 
1.5.6.5




More information about the telepathy-commits mailing list