Skip to content

Commit

Permalink
#1424 use timers as-needed only
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@15188 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 28, 2017
1 parent 251eefe commit a327892
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions src/html5/js/Protocol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2016 Antoine Martin <[email protected]>
* Copyright (c) 2013-2017 Antoine Martin <[email protected]>
* Copyright (c) 2016 David Brushinski <[email protected]>
* Copyright (c) 2014 Joshua Higgins <[email protected]>
* Copyright (c) 2015 Spikes, Inc.
Expand All @@ -13,6 +13,7 @@
* requires:
* bencode.js
* inflate.js
* lz4.js
*/


Expand Down Expand Up @@ -96,9 +97,6 @@ function XpraProtocol() {

//Queue processing via intervals
this.process_interval = 0; //milliseconds
this.rQ_interval_id = null;
this.sQ_interval_id = null;
this.mQ_interval_id = null;
}

XpraProtocol.prototype.open = function(uri) {
Expand All @@ -122,6 +120,9 @@ XpraProtocol.prototype.open = function(uri) {
this.websocket.onmessage = function (e) {
// push arraybuffer values onto the end
me.rQ.push(new Uint8Array(e.data));
setTimeout(function() {
me.process_receive_queue();
}, this.process_interval);
};
this.start_processing();
}
Expand All @@ -139,40 +140,8 @@ XpraProtocol.prototype.terminate = function() {
}

XpraProtocol.prototype.start_processing = function() {
var me = this;
if(this.rQ_interval_id === null){
this.rQ_interval_id = setInterval(function(){
if (me.rQ.length > 0) {
me.process_receive_queue();
}
}, this.process_interval);
}

if(this.sQ_interval_id === null){
this.sQ_interval_id = setInterval(function(){
if(me.sQ.length > 0){
me.process_send_queue();
}
}, this.process_interval);
}

if(this.mQ_interval_id === null){
this.mQ_interval_id = setInterval(function(){
if(me.mQ.length > 0){
me.process_message_queue();
}
}, this.process_interval);
}
}
XpraProtocol.prototype.stop_processing = function() {
clearInterval(this.rQ_interval_id);
this.rQ_interval_id = null;

clearInterval(this.sQ_interval_id);
this.sQ_interval_id = null;

clearInterval(this.mQ_interval_id);
this.mQ_interval_id = null;
}


Expand Down Expand Up @@ -349,6 +318,10 @@ XpraProtocol.prototype.process_receive_queue = function() {
}
if (this.is_worker){
this.mQ[this.mQ.length] = packet;
var me = this;
setTimeout(function() {
me.process_message_queue();
}, this.process_interval);
} else {
this.packet_handler(packet, this.packet_ctx);
}
Expand All @@ -358,11 +331,6 @@ XpraProtocol.prototype.process_receive_queue = function() {
//console.error("packet_data="+packet_data);
}
}

// see if buffer still has unread packets
if (this.rQ.length > 0) {
this.process_receive_queue();
}
}

XpraProtocol.prototype.process_send_queue = function() {
Expand Down Expand Up @@ -426,6 +394,10 @@ XpraProtocol.prototype.process_message_queue = function() {

XpraProtocol.prototype.send = function(packet) {
this.sQ[this.sQ.length] = packet;
var me = this;
setTimeout(function() {
me.process_send_queue();
}, this.process_interval);
}

XpraProtocol.prototype.set_packet_handler = function(callback, ctx) {
Expand Down

0 comments on commit a327892

Please sign in to comment.