Commit 83bcf954 authored by Olivier Crête's avatar Olivier Crête

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()
parent eb150a03
......@@ -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 (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, notify_pseudo_tcp_socket_clock, component);
timeout - (g_get_monotonic_time () / 1000),
notify_pseudo_tcp_socket_clock, component);
}
} else {
nice_debug ("Agent %p: component %d pseudo-TCP socket should be "
"destroyed. Calling priv_pseudo_tcp_error().",
......
......@@ -184,6 +184,7 @@ struct _Component
PseudoTcpSocket *tcp;
GSource* tcp_clock;
long last_clock_timeout;
gboolean tcp_readable;
guint min_port;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment