|
|
@ -56,7 +56,7 @@ if (process.env.NODE_DEBUG && /net/.test(process.env.NODE_DEBUG)) { |
|
|
|
|
|
|
|
|
|
|
|
function isPipeName(s) { |
|
|
|
return typeof s === 'string' && toPort(s) === false; |
|
|
|
return typeof s === 'string' && toNumber(s) === false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ exports.Stream = Socket; // Legacy naming. |
|
|
|
Socket.prototype.listen = function() { |
|
|
|
var self = this; |
|
|
|
self.on('connection', arguments[0]); |
|
|
|
listen(self, null, null); |
|
|
|
listen(self, null, null, null); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -747,7 +747,7 @@ util.inherits(Server, events.EventEmitter); |
|
|
|
exports.Server = Server; |
|
|
|
|
|
|
|
|
|
|
|
function toPort(x) { return (x = Number(x)) >= 0 ? x : false; } |
|
|
|
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; } |
|
|
|
|
|
|
|
|
|
|
|
var createServerHandle = exports._createServerHandle = |
|
|
@ -786,7 +786,7 @@ var createServerHandle = exports._createServerHandle = |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Server.prototype._listen2 = function(address, port, addressType) { |
|
|
|
Server.prototype._listen2 = function(address, port, addressType, backlog) { |
|
|
|
var self = this; |
|
|
|
var r = 0; |
|
|
|
|
|
|
@ -805,7 +805,10 @@ Server.prototype._listen2 = function(address, port, addressType) { |
|
|
|
self._handle.onconnection = onconnection; |
|
|
|
self._handle.socket = self; |
|
|
|
|
|
|
|
r = self._handle.listen(self._backlog || 128); |
|
|
|
// Use a backlog of 512 entries. We pass 511 to the listen() call because
|
|
|
|
// the kernel does: backlogsize = roundup_pow_of_two(backlogsize + 1);
|
|
|
|
// which will thus give us a backlog of 512 entries.
|
|
|
|
r = self._handle.listen(backlog || 511); |
|
|
|
|
|
|
|
if (r) { |
|
|
|
self._handle.close(); |
|
|
@ -822,15 +825,15 @@ Server.prototype._listen2 = function(address, port, addressType) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function listen(self, address, port, addressType) { |
|
|
|
function listen(self, address, port, addressType, backlog) { |
|
|
|
if (process.env.NODE_UNIQUE_ID) { |
|
|
|
var cluster = require('cluster'); |
|
|
|
cluster._getServer(self, address, port, addressType, function(handle) { |
|
|
|
self._handle = handle; |
|
|
|
self._listen2(address, port, addressType); |
|
|
|
self._listen2(address, port, addressType, backlog); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
self._listen2(address, port, addressType); |
|
|
|
self._listen2(address, port, addressType, backlog); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -843,36 +846,41 @@ Server.prototype.listen = function() { |
|
|
|
self.once('listening', lastArg); |
|
|
|
} |
|
|
|
|
|
|
|
var port = toPort(arguments[0]); |
|
|
|
var port = toNumber(arguments[0]); |
|
|
|
|
|
|
|
// The third optional argument is the backlog size.
|
|
|
|
// When the ip is omitted it can be the second argument.
|
|
|
|
var backlog = toNumber(arguments[1]) || toNumber(arguments[2]); |
|
|
|
|
|
|
|
var TCP = process.binding('tcp_wrap').TCP; |
|
|
|
|
|
|
|
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()
|
|
|
|
listen(self, null, null); |
|
|
|
listen(self, null, null, backlog); |
|
|
|
|
|
|
|
} else if (arguments[0] instanceof TCP) { |
|
|
|
self._handle = arguments[0]; |
|
|
|
listen(self, null, -1, -1); |
|
|
|
listen(self, null, -1, -1, backlog); |
|
|
|
|
|
|
|
} else if (isPipeName(arguments[0])) { |
|
|
|
// UNIX socket or Windows pipe.
|
|
|
|
var pipeName = self._pipeName = arguments[0]; |
|
|
|
listen(self, pipeName, -1, -1); |
|
|
|
listen(self, pipeName, -1, -1, backlog); |
|
|
|
|
|
|
|
} else if (typeof arguments[1] == 'undefined' || |
|
|
|
typeof arguments[1] == 'function') { |
|
|
|
typeof arguments[1] == 'function' || |
|
|
|
typeof arguments[1] == 'number') { |
|
|
|
// The first argument is the port, no IP given.
|
|
|
|
listen(self, '0.0.0.0', port, 4); |
|
|
|
listen(self, '0.0.0.0', port, 4, backlog); |
|
|
|
|
|
|
|
} else { |
|
|
|
// The first argument is the port, the second an IP
|
|
|
|
// The first argument is the port, the second an IP.
|
|
|
|
require('dns').lookup(arguments[1], function(err, ip, addressType) { |
|
|
|
if (err) { |
|
|
|
self.emit('error', err); |
|
|
|
} else { |
|
|
|
listen(self, ip || '0.0.0.0', port, ip ? addressType : 4); |
|
|
|
listen(self, ip || '0.0.0.0', port, ip ? addressType : 4, backlog); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|