summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-03-05 15:43:03 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2013-03-05 15:43:03 +0100
commit862f7b850d7155073b44afd85f8d6974fb500e4d (patch)
tree4c89a77769a8490415018b31e10884d109fa7f21 /lib
parent3e64b5677f10abf849c2da762421437b89d1e11e (diff)
parent532d9929c7e6eba8c35943f45dffc93926e34cb9 (diff)
downloadandroid-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.js24
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);
+ });
}