[Pkg-telepathy-commits] [libnice] 103/265: agent: Only change pseudotcp clock if the new timeout is sooner
Simon McVittie
smcv at debian.org
Wed May 14 12:04:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository libnice.
commit 83bcf954bf8a8e1091cb81c9b14afeef98655d39
Author: Olivier Crête <olivier.crete at collabora.com>
Date: Thu Jan 23 23:48:14 2014 -0500
agent: Only change pseudotcp clock if the new timeout is sooner
Destroying and creating GSources is expensive, so also don't destroy and
re-create if possible, instead lets use the new g_source_set_ready_time()
---
agent/agent.c | 31 ++++++++++++++++++-------------
agent/component.h | 1 +
agent/pseudotcp.c | 13 ++++++++-----
configure.ac | 2 +-
tests/test-pseudotcp.c | 1 +
5 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/agent/agent.c b/agent/agent.c
index dfb49a6..0325a6b 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1184,33 +1184,38 @@ notify_pseudo_tcp_socket_clock (gpointer user_data)
agent_unlock ();
return FALSE;
}
- if (component->tcp_clock) {
- g_source_destroy (component->tcp_clock);
- g_source_unref (component->tcp_clock);
- component->tcp_clock = NULL;
- }
pseudo_tcp_socket_notify_clock (component->tcp);
adjust_tcp_clock (agent, stream, component);
agent_unlock();
- return FALSE;
+ return G_SOURCE_CONTINUE;
}
static void
adjust_tcp_clock (NiceAgent *agent, Stream *stream, Component *component)
{
- long timeout = 0;
if (component->tcp) {
+ long timeout = component->last_clock_timeout;
+
if (pseudo_tcp_socket_get_next_clock (component->tcp, &timeout)) {
- if (component->tcp_clock) {
- g_source_destroy (component->tcp_clock);
- g_source_unref (component->tcp_clock);
- component->tcp_clock = NULL;
+ if (timeout != component->last_clock_timeout) {
+ component->last_clock_timeout = timeout;
+ if (component->tcp_clock) {
+#if GLIB_CHECK_VERSION (2, 36, 0)
+ g_source_set_ready_time (component->tcp_clock, timeout * 1000);
+#else
+ g_source_destroy (component->tcp_clock);
+ g_source_unref (component->tcp_clock);
+ component->tcp_clock = NULL;
+#endif
+ }
+ if (!component->tcp_clock)
+ component->tcp_clock = agent_timeout_add_with_context (agent,
+ timeout - (g_get_monotonic_time () / 1000),
+ notify_pseudo_tcp_socket_clock, component);
}
- component->tcp_clock = agent_timeout_add_with_context (agent,
- timeout, notify_pseudo_tcp_socket_clock, component);
} else {
nice_debug ("Agent %p: component %d pseudo-TCP socket should be "
"destroyed. Calling priv_pseudo_tcp_error().",
diff --git a/agent/component.h b/agent/component.h
index e66aa0a..fedb23c 100644
--- a/agent/component.h
+++ b/agent/component.h
@@ -184,6 +184,7 @@ struct _Component
PseudoTcpSocket *tcp;
GSource* tcp_clock;
+ long last_clock_timeout;
gboolean tcp_readable;
guint min_port;
diff --git a/agent/pseudotcp.c b/agent/pseudotcp.c
index 8fc9947..3174946 100644
--- a/agent/pseudotcp.c
+++ b/agent/pseudotcp.c
@@ -906,21 +906,24 @@ pseudo_tcp_socket_get_next_clock(PseudoTcpSocket *self, long *timeout)
return FALSE;
}
+ if (*timeout == 0 || *timeout < now)
+ *timeout = now + CLOSED_TIMEOUT;
+
if (priv->state == TCP_CLOSED) {
- *timeout = CLOSED_TIMEOUT;
+ *timeout = min (*timeout, now + CLOSED_TIMEOUT);
return TRUE;
}
- *timeout = DEFAULT_TIMEOUT;
+ *timeout = min (*timeout, now + DEFAULT_TIMEOUT);
if (priv->t_ack) {
- *timeout = min(*timeout, time_diff(priv->t_ack + priv->ack_delay, now));
+ *timeout = min(*timeout, priv->t_ack + priv->ack_delay);
}
if (priv->rto_base) {
- *timeout = min(*timeout, time_diff(priv->rto_base + priv->rx_rto, now));
+ *timeout = min(*timeout, priv->rto_base + priv->rx_rto);
}
if (priv->snd_wnd == 0) {
- *timeout = min(*timeout, time_diff(priv->lastsend + priv->rx_rto, now));
+ *timeout = min(*timeout, priv->lastsend + priv->rx_rto);
}
return TRUE;
diff --git a/configure.ac b/configure.ac
index ae2d811..a92b181 100644
--- a/configure.ac
+++ b/configure.ac
@@ -96,7 +96,7 @@ AC_CHECK_HEADERS([ifaddrs.h], \
# Also put matching version in LIBNICE_CFLAGS
GLIB_REQ=2.30
-LIBNICE_CFLAGS="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_30 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
+LIBNICE_CFLAGS="-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_30 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36"
dnl Support different levels of compiler error reporting.
dnl This configure flag is designed to mimic one from gnome-common,
diff --git a/tests/test-pseudotcp.c b/tests/test-pseudotcp.c
index 0be1d3f..84f5c9b 100644
--- a/tests/test-pseudotcp.c
+++ b/tests/test-pseudotcp.c
@@ -222,6 +222,7 @@ static void adjust_clock (PseudoTcpSocket *sock)
{
long timeout = 0;
if (pseudo_tcp_socket_get_next_clock (sock, &timeout)) {
+ timeout -= g_get_monotonic_time () / 1000;
g_debug ("Socket %p: Adjuting clock to %ld ms", sock, timeout);
if (sock == left) {
if (left_clock != 0)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/libnice.git
More information about the Pkg-telepathy-commits
mailing list