]> git.wh0rd.org Git - chrome-ext/music-player-client.git/commitdiff
tcp-client: do not create multiple read pollers
authorMike Frysinger <vapier@gentoo.org>
Sat, 28 Sep 2013 04:56:40 +0000 (00:56 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 28 Sep 2013 05:01:23 +0000 (01:01 -0400)
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

index ed3b598126db85ed7b51d930337771921bc58fe1..55bdaafa658d55ed7e798076542fdb8dfb45a206 100644 (file)
@@ -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');