From be1b55289fdd0e654c660eca9bd1eb8a517f804c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 29 Jun 2011 18:04:55 +0200 Subject: [PATCH] net_uv: Fix server.listen argument parsing --- lib/net_uv.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/net_uv.js b/lib/net_uv.js index 9b3750a517..82619f5645 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -399,7 +399,13 @@ function toPort(x) { return (x = Number(x)) >= 0 ? x : false; } function listenip(self, ip, port) { - var r = self._handle.bind(ip, port); + var r = 0; + + if (ip && port) { + debug("bind to " + ip); + r = self._handle.bind(ip, port); + } + if (r) { self.emit('error', errnoException(errno, 'listen')); } else { @@ -423,12 +429,10 @@ Server.prototype.listen = function() { if (arguments.length == 0 || typeof arguments[0] == 'function') { // Don't bind(). OS will assign a port with INADDR_ANY. // The port can be found with server.address() - this._handle.listen(self._backlog || 128); - process.nextTick(function() { - self.emit('listening'); - }); + listenip(self, null, null); - } else if (typeof arguments[1] == 'undefined') { + } else if (typeof arguments[1] == 'undefined' || + typeof arguments[1] == 'function') { // The first argument is the port, no IP given. listenip(self, '0.0.0.0', port);