summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Grunt <pgrunt@redhat.com>2015-01-14 17:44:42 +0100
committerJeremy White <jwhite@codeweavers.com>2015-01-15 09:00:03 -0600
commit566e4acc393c791f825f04b0874a62456e6c8c1b (patch)
tree073656bc332a4c4f958cdd34ce37d6254a52d82a
parent50e279577199946e1058e60084a564fafc6f1a1f (diff)
Read file only when have agent tokens
Stop reading a file when there are no tokens, continue reading it when tokens arrive.
-rw-r--r--main.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/main.js b/main.js
index eba8599..24feb6d 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);
@@ -161,9 +162,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;
}
@@ -316,6 +325,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)
{