component: Add a GCancellable to get of out blocking nice_agent_recv()
authorOlivier Crête <olivier.crete@collabora.com>
Tue, 25 Feb 2014 04:02:04 +0000 (23:02 -0500)
committerOlivier Crête <olivier.crete@collabora.com>
Tue, 25 Feb 2014 05:51:31 +0000 (00:51 -0500)
Otherwise, it may be stuck iterating the context forever if all of the
other sources are gone.

agent/component.c
agent/component.h

index d22816e..3bee9b4 100644 (file)
@@ -112,6 +112,7 @@ Component *
 component_new (guint id, NiceAgent *agent, Stream *stream)
 {
   Component *component;
+  GSource *src;
 
   component = g_slice_new0 (Component);
   component->id = id;
@@ -126,6 +127,10 @@ component_new (guint id, NiceAgent *agent, Stream *stream)
   component->io_callback_id = 0;
 
   component->own_ctx = g_main_context_new ();
+  component->stop_cancellable = g_cancellable_new ();
+  src = g_cancellable_source_new (component->stop_cancellable);
+  g_source_attach (src, component->own_ctx);
+  g_source_unref (src);
   component->ctx = g_main_context_ref (component->own_ctx);
 
   /* Start off with a fresh main context and all I/O paused. This
@@ -205,6 +210,9 @@ component_free (Component *cmp)
 
   component_deschedule_io_callback (cmp);
 
+  g_cancellable_cancel (cmp->stop_cancellable);
+  g_clear_object (&cmp->stop_cancellable);
+
   if (cmp->ctx != NULL) {
     g_main_context_unref (cmp->ctx);
     cmp->ctx = NULL;
index 6433a85..143c212 100644 (file)
@@ -186,6 +186,8 @@ struct _Component
   Stream *stream;  /* unowned, immutable: can be accessed without holding the
                     * agent lock */
 
+  GCancellable *stop_cancellable;
+
   PseudoTcpSocket *tcp;
   GSource* tcp_clock;
   long last_clock_timeout;