|
@ -1126,8 +1126,7 @@ Server.prototype.listen = function () { |
|
|
fs.stat(path, function (err, r) { |
|
|
fs.stat(path, function (err, r) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
if (err.errno == ENOENT) { |
|
|
if (err.errno == ENOENT) { |
|
|
bind(self.fd, path); |
|
|
self._doListen(path); |
|
|
self._doListen(); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
throw r; |
|
|
throw r; |
|
|
} |
|
|
} |
|
@ -1136,12 +1135,8 @@ Server.prototype.listen = function () { |
|
|
throw new Error("Non-socket exists at " + path); |
|
|
throw new Error("Non-socket exists at " + path); |
|
|
} else { |
|
|
} else { |
|
|
fs.unlink(path, function (err) { |
|
|
fs.unlink(path, function (err) { |
|
|
if (err) { |
|
|
if (err) throw err; |
|
|
throw err; |
|
|
self._doListen(path); |
|
|
} else { |
|
|
|
|
|
bind(self.fd, path); |
|
|
|
|
|
self._doListen(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -1151,10 +1146,7 @@ Server.prototype.listen = function () { |
|
|
// The port can be found with server.address()
|
|
|
// The port can be found with server.address()
|
|
|
self.type = 'tcp4'; |
|
|
self.type = 'tcp4'; |
|
|
self.fd = socket(self.type); |
|
|
self.fd = socket(self.type); |
|
|
bind(self.fd, port); |
|
|
self._doListen(port); |
|
|
process.nextTick(function () { |
|
|
|
|
|
self._doListen(); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// the first argument is the port, the second an IP
|
|
|
// the first argument is the port, the second an IP
|
|
|
dns.lookup(arguments[1], function (err, ip, addressType) { |
|
|
dns.lookup(arguments[1], function (err, ip, addressType) { |
|
@ -1163,8 +1155,7 @@ Server.prototype.listen = function () { |
|
|
} else { |
|
|
} else { |
|
|
self.type = addressType == 4 ? 'tcp4' : 'tcp6'; |
|
|
self.type = addressType == 4 ? 'tcp4' : 'tcp6'; |
|
|
self.fd = socket(self.type); |
|
|
self.fd = socket(self.type); |
|
|
bind(self.fd, port, ip); |
|
|
self._doListen(port, ip); |
|
|
self._doListen(); |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -1187,12 +1178,32 @@ Server.prototype._startWatcher = function () { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Server.prototype._doListen = function () { |
|
|
Server.prototype._doListen = function () { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
listen(this.fd, this._backlog || 128); |
|
|
bind(self.fd, arguments[0], arguments[1]); |
|
|
this._startWatcher(); |
|
|
|
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
this.emit('error', err); |
|
|
self.emit('error', err); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Need to the listening in the nextTick so that people potentially have
|
|
|
|
|
|
// time to register 'listening' listeners.
|
|
|
|
|
|
process.nextTick(function () { |
|
|
|
|
|
// It could be that server.close() was called between the time the
|
|
|
|
|
|
// original listen command was issued and this. Bail if that's the case.
|
|
|
|
|
|
// See test/simple/test-net-eaddrinuse.js
|
|
|
|
|
|
if (typeof self.fd != 'number') return; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
listen(self.fd, self._backlog || 128); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
self.emit('error', err); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self._startWatcher(); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|