core: Handle message abortion in HTTPServer
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 11 Jan 2010 16:57:57 +0000 (18:57 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 12 Jan 2010 14:21:35 +0000 (16:21 +0200)
Handle message abortion in HTTPServer rather than HTTPResponse so that
requests could be aborted even early in their life-cycle and to simplify
the code by maximizing the use of GIO.Cancellable. This also fixes the
strange critical when aborting LiveResponse.

src/rygel/rygel-http-response.vala
src/rygel/rygel-http-server.vala

index 5160222..6b5477f 100644 (file)
@@ -45,8 +45,6 @@ internal abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
 
         this.msg.response_body.set_accumulate (false);
 
-        this.server.request_aborted += on_request_aborted;
-
         if (this.cancellable != null) {
             this.cancellable.cancelled += this.on_cancelled;
         }
@@ -58,14 +56,6 @@ internal abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.end (true, Soup.KnownStatusCode.CANCELLED);
     }
 
-    private void on_request_aborted (Soup.Server        server,
-                                     Soup.Message       msg,
-                                     Soup.ClientContext client) {
-        // Ignore if message isn't ours
-        if (msg == this.msg)
-            this.end (true, Soup.KnownStatusCode.NONE);
-    }
-
     public void push_data (void *data, size_t length) {
         this.msg.response_body.append (Soup.MemoryUse.COPY,
                                        data,
index d44982a..86276c8 100644 (file)
@@ -50,6 +50,7 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
 
     public async void run () {
         context.server.add_handler (this.path_root, server_handler);
+        context.server.request_aborted.connect (this.on_request_aborted);
 
         if (this.cancellable != null) {
             this.cancellable.cancelled += this.on_cancelled;
@@ -179,5 +180,20 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
 
         request.run.begin ();
     }
+
+    private void on_request_aborted (Soup.Server        server,
+                                     Soup.Message       message,
+                                     Soup.ClientContext client) {
+        foreach (var request in this.requests) {
+            if (request.msg == message) {
+                request.cancellable.cancel ();
+                debug ("HTTP client aborted %s request for URI '%s'.",
+                       request.msg.method,
+                       request.msg.get_uri ().to_string (false));
+
+                break;
+            }
+        }
+    }
 }