Commit f535a142 authored by Olivier Crête's avatar Olivier Crête

turn: Put timeouts on the specific main context

parent dd0e5574
...@@ -67,7 +67,7 @@ typedef struct { ...@@ -67,7 +67,7 @@ typedef struct {
NiceAddress peer; NiceAddress peer;
uint16_t channel; uint16_t channel;
gboolean renew; gboolean renew;
guint timeout_source; GSource *timeout_source;
} ChannelBinding; } ChannelBinding;
typedef struct { typedef struct {
...@@ -96,7 +96,7 @@ typedef struct { ...@@ -96,7 +96,7 @@ typedef struct {
there is an installed permission */ there is an installed permission */
GList *sent_permissions; /* ongoing permission installed */ GList *sent_permissions; /* ongoing permission installed */
GHashTable *send_data_queues; /* stores a send data queue for per peer */ GHashTable *send_data_queues; /* stores a send data queue for per peer */
guint permission_timeout_source; /* timer used to invalidate GSource *permission_timeout_source; /* timer used to invalidate
permissions */ permissions */
} TurnPriv; } TurnPriv;
...@@ -247,8 +247,10 @@ socket_close (NiceSocket *sock) ...@@ -247,8 +247,10 @@ socket_close (NiceSocket *sock)
for (i = priv->channels; i; i = i->next) { for (i = priv->channels; i; i = i->next) {
ChannelBinding *b = i->data; ChannelBinding *b = i->data;
if (b->timeout_source) if (b->timeout_source) {
g_source_remove (b->timeout_source); g_source_destroy (b->timeout_source);
g_source_unref (b->timeout_source);
}
g_free (b); g_free (b);
} }
g_list_free (priv->channels); g_list_free (priv->channels);
...@@ -288,8 +290,11 @@ socket_close (NiceSocket *sock) ...@@ -288,8 +290,11 @@ socket_close (NiceSocket *sock)
g_list_free (priv->sent_permissions); g_list_free (priv->sent_permissions);
g_hash_table_destroy (priv->send_data_queues); g_hash_table_destroy (priv->send_data_queues);
if (priv->permission_timeout_source) if (priv->permission_timeout_source) {
g_source_remove (priv->permission_timeout_source); g_source_destroy (priv->permission_timeout_source);
g_source_unref (priv->permission_timeout_source);
priv->permission_timeout_source = NULL;
}
if (priv->ctx) if (priv->ctx)
g_main_context_unref (priv->ctx); g_main_context_unref (priv->ctx);
...@@ -394,13 +399,16 @@ socket_recv_messages (NiceSocket *sock, ...@@ -394,13 +399,16 @@ socket_recv_messages (NiceSocket *sock,
static GSource * static GSource *
priv_timeout_add_with_context (TurnPriv *priv, guint interval, priv_timeout_add_with_context (TurnPriv *priv, guint interval,
GSourceFunc function, gpointer data) gboolean seconds, GSourceFunc function, gpointer data)
{ {
GSource *source; GSource *source;
g_return_val_if_fail (function != NULL, NULL); g_return_val_if_fail (function != NULL, NULL);
source = g_timeout_source_new (interval); if (seconds)
source = g_timeout_source_new_seconds (interval);
else
source = g_timeout_source_new (interval);
g_source_set_callback (source, function, data, NULL); g_source_set_callback (source, function, data, NULL);
g_source_attach (source, priv->ctx); g_source_attach (source, priv->ctx);
...@@ -690,7 +698,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to, ...@@ -690,7 +698,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
req->priv = priv; req->priv = priv;
stun_message_id (&msg, req->id); stun_message_id (&msg, req->id);
req->source = priv_timeout_add_with_context (priv, req->source = priv_timeout_add_with_context (priv,
STUN_END_TIMEOUT, priv_forget_send_request, req); STUN_END_TIMEOUT, FALSE, priv_forget_send_request, req);
g_queue_push_tail (priv->send_requests, req); g_queue_push_tail (priv->send_requests, req);
} }
} }
...@@ -825,7 +833,7 @@ priv_binding_expired_timeout (gpointer data) ...@@ -825,7 +833,7 @@ priv_binding_expired_timeout (gpointer data)
/* find current binding and destroy it */ /* find current binding and destroy it */
for (i = priv->channels ; i; i = i->next) { for (i = priv->channels ; i; i = i->next) {
ChannelBinding *b = i->data; ChannelBinding *b = i->data;
if (b->timeout_source == g_source_get_id (source)) { if (b->timeout_source == source) {
priv->channels = g_list_remove (priv->channels, b); priv->channels = g_list_remove (priv->channels, b);
/* Make sure we don't free a currently being-refreshed binding */ /* Make sure we don't free a currently being-refreshed binding */
if (priv->current_binding_msg && !priv->current_binding) { if (priv->current_binding_msg && !priv->current_binding) {
...@@ -885,11 +893,12 @@ priv_binding_timeout (gpointer data) ...@@ -885,11 +893,12 @@ priv_binding_timeout (gpointer data)
/* find current binding and mark it for renewal */ /* find current binding and mark it for renewal */
for (i = priv->channels ; i; i = i->next) { for (i = priv->channels ; i; i = i->next) {
ChannelBinding *b = i->data; ChannelBinding *b = i->data;
if (b->timeout_source == g_source_get_id (source)) { if (b->timeout_source == source) {
b->renew = TRUE; b->renew = TRUE;
/* Install timer to expire the permission */ /* Install timer to expire the permission */
b->timeout_source = g_timeout_add_seconds (STUN_EXPIRE_TIMEOUT, b->timeout_source = priv_timeout_add_with_context (priv,
priv_binding_expired_timeout, priv); STUN_EXPIRE_TIMEOUT, TRUE, priv_binding_expired_timeout, priv);
/* Send renewal */ /* Send renewal */
if (!priv->current_binding_msg) if (!priv->current_binding_msg)
priv_send_channel_bind (priv, NULL, b->channel, &b->peer); priv_send_channel_bind (priv, NULL, b->channel, &b->peer);
...@@ -1121,12 +1130,14 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -1121,12 +1130,14 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
binding->renew = FALSE; binding->renew = FALSE;
/* Remove any existing timer */ /* Remove any existing timer */
if (binding->timeout_source) if (binding->timeout_source) {
g_source_remove (binding->timeout_source); g_source_destroy (binding->timeout_source);
g_source_unref (binding->timeout_source);
}
/* Install timer to schedule refresh of the permission */ /* Install timer to schedule refresh of the permission */
binding->timeout_source = binding->timeout_source =
g_timeout_add_seconds (STUN_BINDING_TIMEOUT, priv_timeout_add_with_context (priv, STUN_BINDING_TIMEOUT,
priv_binding_timeout, priv); TRUE, priv_binding_timeout, priv);
} }
priv_process_pending_bindings (priv); priv_process_pending_bindings (priv);
} }
...@@ -1209,8 +1220,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -1209,8 +1220,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (stun_message_get_class (&msg) == STUN_RESPONSE && if (stun_message_get_class (&msg) == STUN_RESPONSE &&
!priv->permission_timeout_source) { !priv->permission_timeout_source) {
priv->permission_timeout_source = priv->permission_timeout_source =
g_timeout_add_seconds (STUN_PERMISSION_TIMEOUT, priv_timeout_add_with_context (priv, STUN_PERMISSION_TIMEOUT,
priv_permission_timeout, priv); TRUE, priv_permission_timeout, priv);
} }
/* send enqued data */ /* send enqued data */
...@@ -1535,7 +1546,7 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1535,7 +1546,7 @@ priv_schedule_tick (TurnPriv *priv)
guint timeout = stun_timer_remainder (&priv->current_binding_msg->timer); guint timeout = stun_timer_remainder (&priv->current_binding_msg->timer);
if (timeout > 0) { if (timeout > 0) {
priv->tick_source_channel_bind = priv->tick_source_channel_bind =
priv_timeout_add_with_context (priv, timeout, priv_timeout_add_with_context (priv, timeout, FALSE,
priv_retransmissions_tick, priv); priv_retransmissions_tick, priv);
} else { } else {
priv_retransmissions_tick_unlocked (priv); priv_retransmissions_tick_unlocked (priv);
...@@ -1552,7 +1563,7 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1552,7 +1563,7 @@ priv_schedule_tick (TurnPriv *priv)
if (timeout > 0) { if (timeout > 0) {
priv->tick_source_create_permission = priv->tick_source_create_permission =
priv_timeout_add_with_context (priv, priv_timeout_add_with_context (priv, FALSE,
timeout, timeout,
priv_retransmissions_create_permission_tick, priv_retransmissions_create_permission_tick,
priv); priv);
......
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