Permalink
Browse files

Fixed issue #223 where flashblock exposed a bug in our connection tim…

…eout code
  • Loading branch information...
1 parent ad92038 commit 7cf47f9f3abb2576e381885ad055fa433b31ea26 @3rd-Eden 3rd-Eden committed Jul 10, 2011
Showing with 26 additions and 30 deletions.
  1. +26 −30 lib/socket.js
View
@@ -191,6 +191,7 @@
*/
Socket.prototype.connect = function (fn) {
+ console.log('connect called')
if (this.connecting) {
return this;
}
@@ -205,47 +206,42 @@
transports.split(',')
, self.options.transports
);
- self.transport = self.getTransport();
- if (!self.transport) {
- return;
- }
+ function connect (transports){
+ self.transport = self.getTransport(transports);
+ if (!self.transport) return self.publish('connect_failed');
- self.connecting = true;
- self.publish('connecting', self.transport.name);
+ self.connecting = true;
+ self.publish('connecting', self.transport.name);
+ self.transport.open();
- self.transport.open();
+ if (self.options['connect timeout']) {
+ self.connectTimeoutTimer = setTimeout(function () {
+ if (!self.connected) {
+ self.connecting = false;
- if (self.options.connectTimeout) {
- self.connectTimeoutTimer = setTimeout(function () {
- if (!self.connected) {
- if (self.options['try multiple transports']) {
- if (!self.remainingTransports) {
- self.remainingTransports = self.transports.slice(0);
- }
+ if (self.options['try multiple transports']) {
+ if (!self.remainingTransports) {
+ self.remainingTransports = self.transports.slice(0);
+ }
- var transports = self.remainingTransports;
+ var remaining = self.remainingTransports;
- while (transports.length > 0 && transports.splice(0,1)[0] !=
- self.transport.name) {}
+ while (remaining.length > 0 && remaining.splice(0,1)[0] !=
+ self.transport.name) {}
- if (transports.length) {
- self.transport = self.getTransport(transports);
- self.connect();
+ if (remaining.length){
+ connect(remaining);
+ } else {
+ self.publish('connect_failed');
+ }
}
}
-
- if (!self.remainingTransports || self.remainingTransports.length == 0) {
- self.publish('connect_failed');
- }
- }
-
- if(self.remainingTransports && self.remainingTransports.length == 0) {
- delete self.remainingTransports;
- }
- }, self.options['connect timeout']);
+ }, self.options['connect timeout']);
+ }
}
+ connect();
if (fn && typeof fn == 'function') {
self.once('connect', fn);
}

0 comments on commit 7cf47f9

Please sign in to comment.