From 8d91892ace2093a799e7748265a6a123902310d0 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Fri, 26 Dec 2014 11:04:03 -0800 Subject: [PATCH] listen after connecting error handler --- proxy.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/proxy.js b/proxy.js index 0dac166..3d9db14 100644 --- a/proxy.js +++ b/proxy.js @@ -21,17 +21,6 @@ var Proxy = function(opt, cb) { // new tcp server to service requests for this client var client_server = net.createServer(); - client_server.listen(function() { - var port = client_server.address().port; - debug('tcp server listening on port: %d', port); - - cb(null, { - // port for lt client tcp connections - port: port, - // maximum number of tcp connections allowed by lt client - max_conn_count: max_tcp_sockets - }); - }); client_server.on('error', function(err) { if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') { @@ -79,7 +68,6 @@ var Proxy = function(opt, cb) { // new tcp connection from lt client client_server.on('connection', function(socket) { - // no more socket connections allowed if (self.sockets.length >= max_tcp_sockets) { return socket.end(); @@ -126,6 +114,18 @@ var Proxy = function(opt, cb) { self.next_socket(wait_cb); } }); + + client_server.listen(function() { + var port = client_server.address().port; + debug('tcp server listening on port: %d', port); + + cb(null, { + // port for lt client tcp connections + port: port, + // maximum number of tcp connections allowed by lt client + max_conn_count: max_tcp_sockets + }); + }); }; Proxy.prototype.__proto__ = EventEmitter.prototype;