[PATCH spice-html5 7/7] Read file only when have agent tokens

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stop reading a file when there are no tokens,
continue reading it when tokens arrive.
---
 main.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/main.js b/main.js
index 54e6963..d9dced9 100644
--- a/main.js
+++ b/main.js
@@ -58,6 +58,7 @@ function SpiceMainConn()
     this.agent_msg_queue = [];
     this.file_xfer_tasks = {};
     this.file_xfer_task_id = 0;
+    this.file_xfer_read_queue = [];
 }
 
 SpiceMainConn.prototype = Object.create(SpiceConn.prototype);
@@ -162,9 +163,17 @@ SpiceMainConn.prototype.process_channel_message = function(msg)
 
     if (msg.type == SPICE_MSG_MAIN_AGENT_TOKEN)
     {
-        var tokens = new SpiceMsgMainAgentTokens(msg.data);
+        var remaining_tokens, tokens = new SpiceMsgMainAgentTokens(msg.data);
         this.agent_tokens += tokens.num_tokens;
         this.send_agent_message_queue();
+
+        remaining_tokens = this.agent_tokens;
+        while (remaining_tokens > 0 && this.file_xfer_read_queue.length > 0)
+        {
+            var xfer_task = this.file_xfer_read_queue.shift();
+            this.file_xfer_read(xfer_task, xfer_task.read_bytes);
+            remaining_tokens--;
+        }
         return true;
     }
 
@@ -317,6 +326,13 @@ SpiceMainConn.prototype.file_xfer_read = function(file_xfer_task, start_byte)
     sb = start_byte || 0,
     eb = Math.min(sb + FILE_XFER_CHUNK_SIZE, file_xfer_task.file.size);
 
+    if (!this.agent_tokens)
+    {
+        file_xfer_task.read_bytes = sb;
+        this.file_xfer_read_queue.push(file_xfer_task);
+        return;
+    }
+
     reader = new FileReader();
     reader.onload = function(e)
     {
-- 
1.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]