core: More reliable way to wait for idle handlers
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 17 Mar 2010 14:19:45 +0000 (16:19 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 17 Mar 2010 15:45:30 +0000 (17:45 +0200)
Instead of keeping the ID of the last installed idle handler and then
removing it at the end, just add a new idle hander to end the response so
the response is ended after all the idle handlers have been called. This
fixes the issue of LiveResponse not sending all the bytes to the client
before closing the socket on EOS.

src/rygel/rygel-live-response.vala

index c331656..e764fcb 100644 (file)
@@ -33,7 +33,6 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
 
     private HTTPSeek time_range;
 
-    private uint idle_id;
     private SourceFunc run_continue;
 
     public LiveResponse (Soup.Server  server,
@@ -66,11 +65,6 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
     public override void end (bool aborted, uint status) {
         this.pipeline.set_state (State.NULL);
 
-        if (this.idle_id != 0) {
-           Source.remove (this.idle_id);
-           this.idle_id = 0;
-        }
-
         if (!aborted) {
             this.msg.response_body.complete ();
         }
@@ -153,12 +147,10 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
     private void on_new_buffer (Element sink,
                                 Buffer  buffer,
                                 Pad     pad) {
-        this.idle_id = Idle.add_full (Priority.HIGH_IDLE,
-                                      () => {
+        Idle.add_full (Priority.HIGH_IDLE,
+                       () => {
             this.push_data (buffer.data, buffer.size);
 
-            this.idle_id = 0;
-
             return false;
         });
     }
@@ -208,7 +200,12 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
         }
 
         if (!ret) {
-            this.end (false, Soup.KnownStatusCode.NONE);
+                Idle.add_full (Priority.HIGH_IDLE,
+                               () => {
+                    this.end (false, Soup.KnownStatusCode.NONE);
+
+                    return false;
+                });
         }
 
         return ret;