From: Jens Georg Date: Mon, 19 Sep 2011 07:09:54 +0000 (+0200) Subject: core: Get rid of nested main-loop in HTTP Post X-Git-Tag: RYGEL_0_13_0~101 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f1a912bc763e942c048b2ee81b443b2eadbee89;p=profile%2Fivi%2Frygel.git core: Get rid of nested main-loop in HTTP Post --- diff --git a/src/rygel/rygel-http-post.vala b/src/rygel/rygel-http-post.vala index 87acd82..6e50782 100644 --- a/src/rygel/rygel-http-post.vala +++ b/src/rygel/rygel-http-post.vala @@ -91,38 +91,55 @@ internal class Rygel.HTTPPost : HTTPRequest { return; } + this.finalize_post (); + } + + private async void finalize_post () { try { this.stream.close (this.cancellable); + } catch (Error error) { + this.end (KnownStatusCode.INTERNAL_SERVER_ERROR); + this.handle_continue (); - var main_loop = new MainLoop (); - - this.item.parent.container_updated.connect ((container) => { - main_loop.quit (); - }); + return; + } - var timeout_id = Timeout.add_seconds (30, () => { - debug ("Timeout while waiting for 'updated' signal on '%s'.", - this.item.parent.id); - main_loop.quit (); + this.server.pause_message (this.msg); - return false; - }); + debug ("Waiting for update signal from container '%s' after pushing" + + " content to its child item '%s'..", + this.item.parent.id, + this.item.id); - debug ("Waiting for update signal from container '%s' after pushing" + - " content to its child item '%s'..", - this.item.parent.id, - this.item.id); - main_loop.run (); - Source.remove (timeout_id); + var id = this.item.parent.container_updated.connect ((container) => { debug ("Finished waiting for update signal from container '%s'", this.item.parent.id); - this.end (KnownStatusCode.OK); - } catch (Error error) { - this.end (KnownStatusCode.INTERNAL_SERVER_ERROR); - } finally { - this.handle_continue (); + finalize_post.callback (); + }); + + uint timeout_id = 0; + timeout_id = Timeout.add_seconds (30, () => { + debug ("Timeout while waiting for 'updated' signal on '%s'.", + this.item.parent.id); + this.item.parent.disconnect (id); + timeout_id = 0; + + finalize_post.callback (); + + return false; + }); + + yield; + + this.item.parent.disconnect (id); + if (timeout_id != 0) { + Source.remove (timeout_id); } + + this.server.unpause_message (this.msg); + this.end (KnownStatusCode.OK); + this.handle_continue (); } private void on_got_chunk (Message msg, Buffer chunk) {