From f666b0e6f9325f6addddc42be96bb120fc59c372 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 17 Mar 2014 16:09:07 +0000 Subject: [PATCH] TCP Node port in use not caught properly --- nodes/core/io/31-tcpin.js | 46 ++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 100f41fbc..22e1bd296 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -154,13 +154,23 @@ function TcpIn(n) { node.log(err); }); }); - server.listen(node.port); - node.log('listening on port '+node.port); - - this.on('close', function() { - this.closing = true; - server.close(); - node.log('stopped listening on port '+node.port); + server.on('error', function(err) { + if (err) { + node.error('unable to listen on port '+node.port+' : '+err); + } + }); + server.listen(node.port, function(err) { + if (err) { + node.error('unable to listen on port '+node.port+' : '+err); + } else { + node.log('listening on port '+node.port); + + node.on('close', function() { + node.closing = true; + server.close(); + node.log('stopped listening on port '+node.port); + }); + } }); } @@ -272,13 +282,23 @@ function TcpOut(n) { } } }); + + server.on('error', function(err) { + if (err) { + node.error('unable to listen on port '+node.port+' : '+err); + } + }); - server.listen(node.port); - node.log('listening on port '+node.port); - - node.on('close', function() { - server.close(); - node.log('stopped listening on port '+node.port); + server.listen(node.port, function(err) { + if (err) { + node.error('unable to listen on port '+node.port+' : '+err); + } else { + node.log('listening on port '+node.port); + node.on('close', function() { + server.close(); + node.log('stopped listening on port '+node.port); + }); + } }); } }