[Spice-devel] [PATCH spice-html5 4/7] Split agent data message into smaller chunks

Pavel Grunt pgrunt at redhat.com
Wed Jan 14 08:44:39 PST 2015


Allowed size for SPICE_MSGC_MAIN_AGENT_DATA message is 2048 Bytes,
larger messages have to be splitted.
---
 enums.js |  1 +
 main.js  | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/enums.js b/enums.js
index fcf27e6..4b678df 100644
--- a/enums.js
+++ b/enums.js
@@ -312,6 +312,7 @@ var SPICE_CURSOR_TYPE_ALPHA     = 0,
 var SPICE_VIDEO_CODEC_TYPE_MJPEG = 1;
 
 var VD_AGENT_PROTOCOL = 1;
+var VD_AGENT_MAX_DATA_SIZE = 2048;
 
 var VD_AGENT_MOUSE_STATE            = 1,
     VD_AGENT_MONITORS_CONFIG        = 2,
diff --git a/main.js b/main.js
index d10b594..ca81c60 100644
--- a/main.js
+++ b/main.js
@@ -225,9 +225,19 @@ SpiceMainConn.prototype.send_agent_message_queue = function(message)
 SpiceMainConn.prototype.send_agent_message = function(type, message)
 {
     var agent_data = new SpiceMsgcMainAgentData(type, message);
-    var mr = new SpiceMiniData();
-    mr.build_msg(SPICE_MSGC_MAIN_AGENT_DATA, agent_data);
-    this.send_agent_message_queue(mr);
+    var sb = 0, maxsize = VD_AGENT_MAX_DATA_SIZE - SpiceMiniData.prototype.buffer_size();
+    var data = new ArrayBuffer(agent_data.buffer_size());
+    agent_data.to_buffer(data);
+    while (sb < agent_data.buffer_size())
+    {
+        var eb = Math.min(sb + maxsize, agent_data.buffer_size());
+        var mr = new SpiceMiniData();
+        mr.type = SPICE_MSGC_MAIN_AGENT_DATA;
+        mr.size = eb - sb;
+        mr.data = data.slice(sb, eb);
+        this.send_agent_message_queue(mr);
+        sb = eb;
+    }
 }
 
 SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y)
-- 
1.9.3



More information about the Spice-devel mailing list