From 586a438bdc4372eef720547a7aa551feefbf7933 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 11 Jan 2010 18:57:57 +0200 Subject: [PATCH] core: Handle message abortion in HTTPServer 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 | 10 ---------- src/rygel/rygel-http-server.vala | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/rygel/rygel-http-response.vala b/src/rygel/rygel-http-response.vala index 5160222..6b5477f 100644 --- a/src/rygel/rygel-http-response.vala +++ b/src/rygel/rygel-http-response.vala @@ -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, diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala index d44982a..86276c8 100644 --- a/src/rygel/rygel-http-server.vala +++ b/src/rygel/rygel-http-server.vala @@ -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; + } + } + } } -- 2.7.4