Commit 92fb2835 authored by Olivier Crête's avatar Olivier Crête

component: Wake up GSources when adding socket

Wake up GSources to add a new socket when needed.
parent 3a25e367
......@@ -403,6 +403,9 @@ component_free (Component *cmp)
cmp->ctx = NULL;
}
g_slist_free (cmp->component_sources);
cmp->component_sources = NULL;
g_main_context_unref (cmp->own_ctx);
g_slice_free (Component, cmp);
......@@ -606,6 +609,25 @@ _find_socket_source (gconstpointer a, gconstpointer b)
return (source_a->socket == socket_b) ? 0 : 1;
}
static void
component_wakeup_contexts (Component *component)
{
GSList *item;
for (item = component->component_sources; item; item = item->next) {
GSource *src = item->data;
GMainContext *ctx;
if (g_source_is_destroyed (src))
continue;
ctx = g_source_get_context (src);
if (src)
g_main_context_wakeup (ctx);
}
}
/* This takes ownership of the socket.
* It creates and attaches a source to the component’s context. */
void
......@@ -638,6 +660,7 @@ component_attach_socket (Component *component, NiceSocket *nicesock)
g_slist_prepend (component->socket_sources, socket_source);
if (nicesock->fileno != NULL)
component->socket_sources_age++;
component_wakeup_contexts (component);
}
/* Create and attach a source */
......@@ -705,6 +728,7 @@ component_detach_socket (Component *component, NiceSocket *nicesock)
socket_source = l->data;
component->socket_sources = g_slist_delete_link (component->socket_sources, l);
component->socket_sources_age++;
component_wakeup_contexts (component);
socket_source_release (socket_source);
}
......@@ -738,6 +762,7 @@ component_free_socket_sources (Component *component)
(GDestroyNotify) socket_source_release);
component->socket_sources = NULL;
component->socket_sources_age++;
component_wakeup_contexts (component);
component_clear_selected_pair (component);
}
......@@ -1296,9 +1321,23 @@ static void
component_source_finalize (GSource *source)
{
ComponentSource *component_source = (ComponentSource *) source;
NiceAgent *agent;
Component *component;
g_slist_free_full (component_source->socket_sources, free_child_socket_source);
agent_lock ();
agent = g_weak_ref_get (&component_source->agent_ref);
if (agent != NULL) {
if (agent_find_component (agent, component_source->stream_id,
component_source->component_id, NULL, &component)) {
component->component_sources =
g_slist_remove (component->component_sources, component_source);
}
g_object_unref (agent);
}
agent_unlock ();
g_weak_ref_clear (&component_source->agent_ref);
g_clear_object (&component_source->datagram_based);
}
......@@ -1364,6 +1403,7 @@ component_source_new (NiceAgent *agent, guint stream_id,
GCancellable *cancellable)
{
ComponentSource *component_source;
Component *component;
g_assert (G_IS_DATAGRAM_BASED (datagram_based));
......@@ -1390,6 +1430,13 @@ component_source_new (NiceAgent *agent, guint stream_id,
g_source_unref (cancellable_source);
}
agent_lock ();
if (agent_find_component (agent, stream_id, component_id, NULL,
&component))
component->component_sources =
g_slist_prepend (component->component_sources, component_source);
agent_unlock ();
return (GSource *) component_source;
}
......
......@@ -196,6 +196,7 @@ struct _Component
GCancellable *stop_cancellable;
GSource *stop_cancellable_source; /* owned */
GSList *component_sources;
GDatagramBased *datagram_based; /* owned */
......
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