From: Darren Date: Wed, 25 Jun 2014 09:14:35 +0000 (+0100) Subject: Proxy checker module: 5s timeout X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=102223cebcfa852c2eba61ee5eea4d342e310e8a;p=KiwiIRC.git Proxy checker module: 5s timeout --- 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