From 307dda1ad033181b56b7b51ba0e5f986c1beaf10 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Sun, 23 Jan 2011 19:23:28 -0600 Subject: [PATCH] Tolerate some bufferedAmount and send() return value. - Only delay sending data if bufferedAmount is greater than 1000. This seems to match the intention of the spec better. bufferedAmount does not mean that we can't send, it's just an indication that the network is becoming saturated. But Opera 11 native WebSockets seems to have a bug that bufferedAmount isn't set back to zero correctly so - websock.send returns true/false. If all send data was flushed from the send queue then return true, otherwise false. This doesn't mean the data won't be sent, just that it wasn't sent this time and is queued. --- include/websock.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/websock.js b/include/websock.js index 825e453..4901faf 100644 --- a/include/websock.js +++ b/include/websock.js @@ -166,7 +166,10 @@ function decode_message(data) { // function flush() { - if (websocket.bufferedAmount === 0) { + if (websocket.bufferedAmount !== 0) { + Util.Debug("bufferedAmount: " + websocket.bufferedAmount); + } + if (websocket.bufferedAmount < 1000) { //Util.Debug("arr: " + arr); //Util.Debug("sQ: " + sQ); if (sQ) { @@ -175,7 +178,8 @@ function flush() { } return true; } else { - Util.Debug("Delaying send"); + Util.Info("Delaying send, bufferedAmount: " + + websocket.bufferedAmount); return false; } } @@ -184,7 +188,7 @@ function flush() { function send(arr) { //Util.Debug(">> send_array: " + arr); sQ = sQ.concat(arr); - flush(); + return flush(); }; function send_string(str) {