From 16d1493fcece81b6257ddc88143587e5931858b2 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Mon, 15 Nov 2010 13:43:26 -0500 Subject: [PATCH] rfb.js: avoid multiple b64 sequences per frame. Only call encode_message when the WebSockets object is actually ready to send. Otherwise multiple base64 encode sequences can be encoded into the same WebSockets frame. This causes the C version of wsproxy to crash and the python version to ignore the subsequent base64 sequence(s). Thanks to Colin Dean (xvpsource.org) for finding this and helping track it down. --- include/rfb.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/rfb.js b/include/rfb.js index 41c111b..a460f1c 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -73,7 +73,7 @@ var that = {}, // Public API interface rQ = [], // Receive Queue rQi = 0, // Receive Queue Index rQmax = 100000, // Max size before compacting - sQ = "", // Send Queue + sQ = [], // Send Queue // Frame buffer update state FBU = { @@ -319,7 +319,7 @@ init_vars = function() { /* Reset state */ rQ = []; rQi = 0; - sQ = ""; + sQ = []; FBU.rects = 0; FBU.subrects = 0; // RRE and HEXTILE FBU.lines = 0; // RAW @@ -525,9 +525,9 @@ function fail(msg) { return false; } -function encode_message(arr) { +function encode_message() { /* base64 encode */ - sQ = sQ + Base64.encode(arr); + return Base64.encode(sQ); } function decode_message(data) { @@ -605,12 +605,12 @@ recv_message = function(e) { // overridable for testing send_array = function(arr) { //Util.Debug(">> send_array: " + arr); - encode_message(arr); + sQ = sQ.concat(arr); if (ws.bufferedAmount === 0) { //Util.Debug("arr: " + arr); //Util.Debug("sQ: " + sQ); - ws.send(sQ); - sQ = ""; + ws.send(encode_message(sQ)); + sQ = []; } else { Util.Debug("Delaying send"); } @@ -723,8 +723,8 @@ init_msg = function() { // can handle. if (ws.bufferedAmount === 0) { if (sQ) { - ws.send(sQ); - sQ = ""; + ws.send(encode_message(sQ)); + sQ = []; } } else { Util.Debug("Delaying send");