[rygel] core: Don't send out more bytes than requested
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Don't send out more bytes than requested
- Date: Fri, 1 Apr 2011 15:58:09 +0000 (UTC)
commit 593f2a2efd10890514c06db69648f61ef6ad7af2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Apr 1 17:07:20 2011 +0300
core: Don't send out more bytes than requested
src/rygel/rygel-http-gst-sink.vala | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/rygel/rygel-http-gst-sink.vala b/src/rygel/rygel-http-gst-sink.vala
index d275aec..6705014 100644
--- a/src/rygel/rygel-http-gst-sink.vala
+++ b/src/rygel/rygel-http-gst-sink.vala
@@ -36,6 +36,8 @@ internal class Rygel.HTTPGstSink : BaseSink {
private int priority;
private int64 chunks_buffered;
+ private int64 bytes_sent;
+ private int64 max_bytes;
private Mutex buffer_mutex;
private Cond buffer_condition;
@@ -51,6 +53,7 @@ internal class Rygel.HTTPGstSink : BaseSink {
public HTTPGstSink (HTTPGstResponse response) {
this.chunks_buffered = 0;
+ this.bytes_sent = 0;
this.buffer_mutex = new Mutex ();
this.buffer_condition = new Cond ();
@@ -61,6 +64,12 @@ internal class Rygel.HTTPGstSink : BaseSink {
this.sync = false;
this.name = NAME;
+ if (response.seek != null && response.seek is HTTPByteSeek) {
+ this.max_bytes = response.seek.length;
+ } else {
+ this.max_bytes = int64.MAX;
+ }
+
this.cancellable.cancelled.connect (this.on_cancelled);
response.msg.wrote_chunk.connect (this.on_wrote_chunk);
}
@@ -95,12 +104,17 @@ internal class Rygel.HTTPGstSink : BaseSink {
// Runs in application thread
public bool push_data (Buffer buffer) {
- if (this.cancellable.is_cancelled ()) {
+ var left = this.max_bytes - this.bytes_sent;
+
+ if (this.cancellable.is_cancelled () || left <= 0) {
return false;
}
- this.response.push_data (buffer.data);
+ var to_send = int64.min (buffer.size, left);
+
+ this.response.push_data (buffer.data[0:to_send]);
this.chunks_buffered++;
+ this.bytes_sent += to_send;
return false;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]