From e7d6adb435d30041cb586158b52fd4fdd71cd088 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 28 Sep 2013 00:56:40 -0400 Subject: [PATCH] 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(). --- js/tcp-client.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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'); -- 2.39.2