From 40238b00b61e509260e3093b0b353d5dcef6c413 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 3 Feb 2017 17:00:15 +0100 Subject: [PATCH] Don't delay flushing The native WebSocket is in a much better position to do queue management than us. Many callers also failed to notice this part of the API, causing stalls. --- include/websock.js | 18 ++++-------------- tests/latency.html | 18 ++---------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/include/websock.js b/include/websock.js index 6738bc6..d9343e8 100644 --- a/include/websock.js +++ b/include/websock.js @@ -37,8 +37,6 @@ this._sQlen = 0; this._sQ = null; // Send queue - this.maxBufferedAmount = 200; - this._eventHandlers = { 'message': function () {}, 'open': function () {}, @@ -179,24 +177,16 @@ Util.Debug("bufferedAmount: " + this._websocket.bufferedAmount); } - if (this._websocket.bufferedAmount < this.maxBufferedAmount) { - if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) { - this._websocket.send(this._encode_message()); - this._sQlen = 0; - } - - return true; - } else { - Util.Info("Delaying send, bufferedAmount: " + - this._websocket.bufferedAmount); - return false; + if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) { + this._websocket.send(this._encode_message()); + this._sQlen = 0; } }, send: function (arr) { this._sQ.set(arr, this._sQlen); this._sQlen += arr.length; - return this.flush(); + this.flush(); }, send_string: function (str) { diff --git a/tests/latency.html b/tests/latency.html index 1c42653..90136a3 100644 --- a/tests/latency.html +++ b/tests/latency.html @@ -56,7 +56,7 @@