Proxy checker module: 5s timeout
authorDarren <darren@darrenwhitlen.com>
Wed, 25 Jun 2014 09:14:35 +0000 (10:14 +0100)
committerDarren <darren@darrenwhitlen.com>
Wed, 25 Jun 2014 09:14:35 +0000 (10:14 +0100)
server_modules/proxychecker.js

index f16eccfb5c97599ef9cad44882a04b674b3ea883..abbb1e16df0afc036dc74fadff80031bb565de7e 100644 (file)
@@ -58,10 +58,23 @@ function checkForOpenProxies(host, callback) {
         }
     };
 
+    var portTimeout = function() {
+        ports_completed++;
+        this.removeAllListeners();
+        this.destroy();
+
+        if (!callback_called && ports_completed >= ports.length) {
+            callback_called = true;
+            callback(false);
+        }
+    };
+
     for (var idx=0; idx< ports.length; idx++) {
         net.connect({port: ports[idx], host: host})
             .on('connect', portConnected)
             .on('error', portFailed)
-            .on('close', portFailed);
+            .on('close', portFailed)
+            .on('timeout', portTimeout)
+            .setTimeout(5000);
     }
 }
\ No newline at end of file