[rygel] core: Cancel HTTPResponse SoupServer goes away



commit f4b13f8a55bb3ac2113f2c387575524fcee6b391
Author: Jens Georg <mail jensge org>
Date:   Mon Sep 19 12:11:46 2011 +0200

    core: Cancel HTTPResponse SoupServer goes away
    
    Adding a week reference to cancel the HTTPGstSink in case the
    SoupServer is gone. Otherwise the sink is stuck on the wait
    condition forever, leaking the HTTPResponse.

 src/rygel/rygel-http-response.vala |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/rygel-http-response.vala b/src/rygel/rygel-http-response.vala
index ecc75fa..a6309c6 100644
--- a/src/rygel/rygel-http-response.vala
+++ b/src/rygel/rygel-http-response.vala
@@ -59,6 +59,7 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
 
     private Pipeline pipeline;
     private uint bus_watch_id;
+    private bool unref_soup_server;
 
     public HTTPResponse (HTTPGet        request,
                          HTTPGetHandler request_handler,
@@ -87,6 +88,14 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.msg.response_body.set_accumulate (false);
 
         this.prepare_pipeline ("RygelHTTPGstResponse", src);
+        this.server.weak_ref (this.on_server_weak_ref);
+        this.unref_soup_server = true;
+    }
+
+    ~HTTPResponse () {
+        if (this.unref_soup_server) {
+            this.server.weak_unref (this.on_server_weak_ref);
+        }
     }
 
     public async void run () {
@@ -137,6 +146,11 @@ internal class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.end (true, Soup.KnownStatusCode.CANCELLED);
     }
 
+    private void on_server_weak_ref (GLib.Object object) {
+        this.needs_weak_unref = false;
+        this.cancellable.cancel ();
+    }
+
     private void prepare_pipeline (string name, Element src) throws Error {
         var sink = new HTTPGstSink (this);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]