From 102223cebcfa852c2eba61ee5eea4d342e310e8a Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 25 Jun 2014 10:14:35 +0100 Subject: [PATCH] Proxy checker module: 5s timeout --- server_modules/proxychecker.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server_modules/proxychecker.js b/server_modules/proxychecker.js index f16eccf..abbb1e1 100644 --- a/server_modules/proxychecker.js +++ b/server_modules/proxychecker.js @@ -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 -- 2.25.1