diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2014-01-23 23:48:14 -0500 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2014-01-31 01:49:00 -0500 |
commit | 83bcf954bf8a8e1091cb81c9b14afeef98655d39 (patch) | |
tree | 9dd20684037def50b1b5c4f8f97599fa22102478 | |
parent | eb150a032edd38104abef425b4f58f4e371a7aa5 (diff) | |
download | libnice-83bcf954bf8a8e1091cb81c9b14afeef98655d39.tar.gz |
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()
-rw-r--r-- | agent/agent.c | 31 | ||||
-rw-r--r-- | agent/component.h | 1 | ||||
-rw-r--r-- | agent/pseudotcp.c | 13 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | 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) |