Permalink
Browse files

Merge pull request #231 from 3rd-Eden/flashblock

Fixed issue #223 where flashblock exposed a bug in our connection timeout
  • Loading branch information...
2 parents ad92038 + 7c88d3f commit 7f6382d97340dc3fd681411998e45fc6938e359a @rauchg rauchg committed Jul 10, 2011
Showing with 25 additions and 30 deletions.
  1. +25 −30 lib/socket.js
View
@@ -205,47 +205,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 7f6382d

Please sign in to comment.