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) ...@@ -1184,33 +1184,38 @@ notify_pseudo_tcp_socket_clock (gpointer user_data)
agent_unlock (); agent_unlock ();
return FALSE; 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); pseudo_tcp_socket_notify_clock (component->tcp);
adjust_tcp_clock (agent, stream, component); adjust_tcp_clock (agent, stream, component);
agent_unlock(); agent_unlock();
return FALSE; return G_SOURCE_CONTINUE;
} }
static void static void
adjust_tcp_clock (NiceAgent *agent, Stream *stream, Component *component) adjust_tcp_clock (NiceAgent *agent, Stream *stream, Component *component)
{ {
long timeout = 0;
if (component->tcp) { if (component->tcp) {
long timeout = component->last_clock_timeout;
if (pseudo_tcp_socket_get_next_clock (component->tcp, &timeout)) { if (pseudo_tcp_socket_get_next_clock (component->tcp, &timeout)) {
if (component->tcp_clock) { if (timeout != component->last_clock_timeout) {
g_source_destroy (component->tcp_clock); component->last_clock_timeout = timeout;
g_source_unref (component->tcp_clock); if (component->tcp_clock) {
component->tcp_clock = NULL; #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 { } else {
nice_debug ("Agent %p: component %d pseudo-TCP socket should be " nice_debug ("Agent %p: component %d pseudo-TCP socket should be "
"destroyed. Calling priv_pseudo_tcp_error().", "destroyed. Calling priv_pseudo_tcp_error().",
......
...@@ -184,6 +184,7 @@ struct _Component ...@@ -184,6 +184,7 @@ struct _Component
PseudoTcpSocket *tcp; PseudoTcpSocket *tcp;
GSource* tcp_clock; GSource* tcp_clock;
long last_clock_timeout;
gboolean tcp_readable; gboolean tcp_readable;
guint min_port; guint min_port;
......
...@@ -906,21 +906,24 @@ pseudo_tcp_socket_get_next_clock(PseudoTcpSocket *self, long *timeout) ...@@ -906,21 +906,24 @@ pseudo_tcp_socket_get_next_clock(PseudoTcpSocket *self, long *timeout)
return FALSE; return FALSE;
} }
if (*timeout == 0 || *timeout < now)
*timeout = now + CLOSED_TIMEOUT;
if (priv->state == TCP_CLOSED) { if (priv->state == TCP_CLOSED) {
*timeout = CLOSED_TIMEOUT; *timeout = min (*timeout, now + CLOSED_TIMEOUT);
return TRUE; return TRUE;
} }
*timeout = DEFAULT_TIMEOUT; *timeout = min (*timeout, now + DEFAULT_TIMEOUT);
if (priv->t_ack) { 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) { 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) { 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; return TRUE;
......
...@@ -96,7 +96,7 @@ AC_CHECK_HEADERS([ifaddrs.h], \ ...@@ -96,7 +96,7 @@ AC_CHECK_HEADERS([ifaddrs.h], \
# Also put matching version in LIBNICE_CFLAGS # Also put matching version in LIBNICE_CFLAGS
GLIB_REQ=2.30 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 Support different levels of compiler error reporting.
dnl This configure flag is designed to mimic one from gnome-common, dnl This configure flag is designed to mimic one from gnome-common,
......
...@@ -222,6 +222,7 @@ static void adjust_clock (PseudoTcpSocket *sock) ...@@ -222,6 +222,7 @@ static void adjust_clock (PseudoTcpSocket *sock)
{ {
long timeout = 0; long timeout = 0;
if (pseudo_tcp_socket_get_next_clock (sock, &timeout)) { 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); g_debug ("Socket %p: Adjuting clock to %ld ms", sock, timeout);
if (sock == left) { if (sock == left) {
if (left_clock != 0) 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