[rygel] core: Fix SeekableResponse wrt latest async changes
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: Fix SeekableResponse wrt latest async changes
- Date: Fri, 23 Oct 2009 17:15:55 +0000 (UTC)
commit 0bd633e888980d18f8bb55cc15d08fd24c23bac4
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Oct 23 20:07:29 2009 +0300
core: Fix SeekableResponse wrt latest async changes
We were returning from an async call when waiting for signal
'wrote-chunk' from soup message and this was unrefing both request
and response too early.
src/rygel/rygel-seekable-response.vala | 46 +++++++++++++++++++------------
1 files changed, 28 insertions(+), 18 deletions(-)
---
diff --git a/src/rygel/rygel-seekable-response.vala b/src/rygel/rygel-seekable-response.vala
index 29c4c4e..c1088ab 100644
--- a/src/rygel/rygel-seekable-response.vala
+++ b/src/rygel/rygel-seekable-response.vala
@@ -54,8 +54,6 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
this.total_length = file_length;
}
- msg.wrote_chunk += on_wrote_chunk;
-
this.buffer = new char[SeekableResponse.BUFFER_LENGTH];
this.file = File.new_for_uri (uri);
}
@@ -94,18 +92,12 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
}
}
- yield this.read_contents ();
+ yield this.start_reading ();
}
- private async void read_contents () {
- ssize_t bytes_read;
-
+ private async void start_reading () {
try {
- bytes_read = yield this.input_stream.read_async (
- this.buffer,
- SeekableResponse.BUFFER_LENGTH,
- this.priority,
- this.cancellable);
+ yield this.read_contents ();
} catch (Error err) {
warning ("Failed to read contents from URI: %s: %s\n",
this.file.get_uri (),
@@ -115,10 +107,32 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
return;
}
- if (bytes_read > 0) {
+ yield this.close_stream ();
+ }
+
+ private async void read_contents () throws Error {
+ var bytes_read = yield this.input_stream.read_async (
+ this.buffer,
+ SeekableResponse.BUFFER_LENGTH,
+ this.priority,
+ this.cancellable);
+ SourceFunc cb = read_contents.callback;
+ this.msg.wrote_chunk.connect ((msg) => {
+ cb ();
+ });
+
+ while (bytes_read > 0) {
this.push_data (this.buffer, bytes_read);
- } else {
- yield this.close_stream ();
+
+ // We return from this call when wrote_chunk signal is emitted
+ // and the handler we installed before the loop is called for it.
+ yield;
+
+ bytes_read = yield this.input_stream.read_async (
+ this.buffer,
+ SeekableResponse.BUFFER_LENGTH,
+ this.priority,
+ this.cancellable);
}
}
@@ -135,10 +149,6 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
this.end (false, Soup.KnownStatusCode.NONE);
}
- private void on_wrote_chunk (Soup.Message msg) {
- this.read_contents.begin ();
- }
-
private int get_requested_priority () {
var mode = this.msg.request_headers.get ("transferMode.dlna.org");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]