diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-03-05 15:43:03 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-03-05 15:43:03 +0100 |
commit | 862f7b850d7155073b44afd85f8d6974fb500e4d (patch) | |
tree | 4c89a77769a8490415018b31e10884d109fa7f21 /lib | |
parent | 3e64b5677f10abf849c2da762421437b89d1e11e (diff) | |
parent | 532d9929c7e6eba8c35943f45dffc93926e34cb9 (diff) | |
download | android-node-v8-862f7b850d7155073b44afd85f8d6974fb500e4d.tar.gz android-node-v8-862f7b850d7155073b44afd85f8d6974fb500e4d.tar.bz2 android-node-v8-862f7b850d7155073b44afd85f8d6974fb500e4d.zip |
Merge remote-tracking branch 'origin/v0.8'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/net.js b/lib/net.js index ca0a53b3e1..4be6402d7f 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1029,14 +1029,26 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { function listen(self, address, port, addressType, backlog, fd) { if (!cluster) cluster = require('cluster'); - if (cluster.isWorker) { - cluster._getServer(self, address, port, addressType, fd, function(handle) { - self._handle = handle; - self._listen2(address, port, addressType, backlog, fd); - }); - } else { + if (cluster.isMaster) { self._listen2(address, port, addressType, backlog, fd); + return; } + + cluster._getServer(self, address, port, addressType, fd, function(handle) { + // Some operating systems (notably OS X and Solaris) don't report EADDRINUSE + // errors right away. libuv mimics that behavior for the sake of platform + // consistency but that means we have have a socket on our hands that is + // not actually bound. That's why we check if the actual port matches what + // we requested and if not, raise an error. The exception is when port == 0 + // because that means "any random port". + if (port && handle.getsockname && port != handle.getsockname().port) { + self.emit('error', errnoException('EADDRINUSE', 'bind')); + return; + } + + self._handle = handle; + self._listen2(address, port, addressType, backlog, fd); + }); } |