summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Zabaluev <mikhail.zabaluev@nokia.com>2011-05-26 19:10:28 +0300
committerMikhail Zabaluev <mikhail.zabaluev@nokia.com>2011-05-26 19:10:28 +0300
commit409ba314750ff236b1cac4f000846046d66b6305 (patch)
treeddfa2237d5270a6454721dfcffd78012e53d0594
parent923b867371c502a8228b749e03c9476edd730d5c (diff)
parent2f3116dff3ac88c79c4de43470de558ef0a72456 (diff)
Merge branch 'iphb-system-sync' into master
Conflicts: src/sip-connection-helpers.c
-rw-r--r--configure.ac7
-rw-r--r--src/sip-connection-helpers.c73
-rw-r--r--src/sip-connection-private.h2
3 files changed, 53 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac
index 1ac6f48..b990522 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,13 +96,10 @@ AC_ARG_WITH(iphb,
[with_iphb=no]
)
if test "x$with_iphb" != xno; then
- AC_CHECK_LIB(iphb, [iphb_open],
+ PKG_CHECK_MODULES(IPHB, [libiphb >= 0.61.31],
[
AC_DEFINE([HAVE_LIBIPHB], [], [IP heartbeat library is available])
- IPHB_CFLAGS='-I$(includedir)/iphbd'
- IPHB_LIBS=-liphb
- ],
- [AC_MSG_ERROR([IP heartbeat library not found])]
+ ]
)
else
IPHB_CFLAGS=
diff --git a/src/sip-connection-helpers.c b/src/sip-connection-helpers.c
index d85fc38..592b540 100644
--- a/src/sip-connection-helpers.c
+++ b/src/sip-connection-helpers.c
@@ -703,6 +703,54 @@ rakia_handle_normalize (TpHandleRepoIface *repo,
#ifdef HAVE_LIBIPHB
+static gushort
+recommended_intervals[] = {
+ IPHB_GS_WAIT_10_HOURS,
+ IPHB_GS_WAIT_2_HOURS,
+ IPHB_GS_WAIT_1_HOUR,
+ IPHB_GS_WAIT_30_MINS,
+ IPHB_GS_WAIT_10_MINS * 2, /* It aligns with the 1 hour slot. */
+ IPHB_GS_WAIT_10_MINS,
+ IPHB_GS_WAIT_5_MINS,
+ IPHB_GS_WAIT_2_5_MINS,
+ IPHB_GS_WAIT_30_SEC};
+
+static gushort
+get_system_sync_interval (guint max_interval)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (recommended_intervals); i++)
+ {
+ if (recommended_intervals[i] <= max_interval)
+ return recommended_intervals[i];
+ }
+
+ return (gushort) MIN (max_interval, G_MAXUSHORT);
+}
+
+static void
+heartbeat_schedule_wait (RakiaConnection *self)
+{
+ RakiaConnectionPrivate *priv = TPSIP_CONNECTION_GET_PRIVATE (self);
+ gushort interval;
+
+ /* Passing the same minimum and maximum interval to iphb_wait() means
+ * that the iphb daemon will wake us up when its internal time is a
+ * multiple of the interval.
+ * By using recommended intervals across the platform we can get
+ * multiple processes waken up at the same time. */
+ interval = get_system_sync_interval (priv->keepalive_interval);
+ DEBUG ("requested %hd as maximum interval; using the recommended %hu "
+ "interval", priv->keepalive_interval, interval);
+
+ if (iphb_wait (priv->heartbeat, interval, interval, 0) < 0)
+ {
+ WARNING ("iphb_wait failed");
+ rakia_conn_heartbeat_shutdown (self);
+ }
+}
+
static int
heartbeat_wakeup (su_root_magic_t *foo,
su_wait_t *wait,
@@ -710,7 +758,6 @@ heartbeat_wakeup (su_root_magic_t *foo,
{
RakiaConnection *self = (RakiaConnection *) user_data;
RakiaConnectionPrivate *priv = TPSIP_CONNECTION_GET_PRIVATE (self);
- gint keepalive_earliest;
DEBUG("tick");
@@ -723,19 +770,7 @@ heartbeat_wakeup (su_root_magic_t *foo,
return 0;
}
- keepalive_earliest = (int) priv->keepalive_interval - TPSIP_DEFER_TIMEOUT;
- if (keepalive_earliest < 0)
- keepalive_earliest = 0;
-
- if (iphb_wait (priv->heartbeat,
- (gushort) keepalive_earliest,
- (gushort) MIN(priv->keepalive_interval, G_MAXUSHORT),
- 0) < 0)
- {
- WARNING ("iphb_wait failed");
- rakia_conn_heartbeat_shutdown (self);
- return 0;
- }
+ heartbeat_schedule_wait (self);
return 0;
}
@@ -778,15 +813,7 @@ rakia_conn_heartbeat_init (RakiaConnection *self)
g_return_if_fail (wait_id > 0);
priv->heartbeat_wait_id = wait_id;
- /* Prime the heartbeat for the first time.
- * The minimum wakeup timeout is 0 to fall in step with other
- * clients using the same interval */
- if (iphb_wait (priv->heartbeat,
- 0, (gushort) MIN(priv->keepalive_interval, G_MAXUSHORT), 0) < 0)
- {
- WARNING ("iphb_wait failed");
- rakia_conn_heartbeat_shutdown (self);
- }
+ heartbeat_schedule_wait (self);
#endif /* HAVE_LIBIPHB */
}
diff --git a/src/sip-connection-private.h b/src/sip-connection-private.h
index 4457e61..4d25d51 100644
--- a/src/sip-connection-private.h
+++ b/src/sip-connection-private.h
@@ -30,7 +30,7 @@
#include <telepathy-glib/simple-password-manager.h>
#ifdef HAVE_LIBIPHB
-#include <libiphb.h>
+#include <iphbd/libiphb.h>
#endif
struct _RakiaConnectionPrivate