From: Mike Frysinger Date: Sat, 28 Sep 2013 04:56:40 +0000 (-0400) Subject: tcp-client: do not create multiple read pollers X-Git-Tag: v3.2~3 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=e7d6adb435d30041cb586158b52fd4fdd71cd088;p=chrome-ext%2Fmusic-player-client.git tcp-client: do not create multiple read pollers If we have connect() called multiple times, don't leave the previous read poller running. This can happen when someone does connect(); connect();. Along those lines, also kill the poller when we disconnect(). --- diff --git a/js/tcp-client.js b/js/tcp-client.js index ed3b598..55bdaaf 100644 --- a/js/tcp-client.js +++ b/js/tcp-client.js @@ -42,6 +42,7 @@ Author: Boris Smus (smus@chromium.org) // Socket. this.socketId = null; this.isConnected = false; + this.pollerId = null; log('initialized tcp client'); } @@ -92,6 +93,8 @@ Author: Boris Smus (smus@chromium.org) */ TcpClient.prototype.disconnect = function() { socket.disconnect(this.socketId); + clearInterval(this.pollerId); + this.pollerId = null; this.isConnected = false; }; @@ -124,7 +127,8 @@ Author: Boris Smus (smus@chromium.org) */ TcpClient.prototype._onConnectComplete = function(resultCode) { // Start polling for reads. - setInterval(this.poll.bind(this), 500); + clearInterval(this.pollerId); + this.pollerId = setInterval(this.poll.bind(this), 500); if (this.callbacks.connect) { log('connect complete');