[rygel] core: Get rid of nested main-loop in HTTP Post
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Get rid of nested main-loop in HTTP Post
- Date: Mon, 19 Sep 2011 10:14:12 +0000 (UTC)
commit 1f1a912bc763e942c048b2ee81b443b2eadbee89
Author: Jens Georg <mail jensge org>
Date: Mon Sep 19 09:09:54 2011 +0200
core: Get rid of nested main-loop in HTTP Post
src/rygel/rygel-http-post.vala | 61 +++++++++++++++++++++++++--------------
1 files changed, 39 insertions(+), 22 deletions(-)
---
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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]