mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +00:00
net: bind to ::
TCP address by default
Try binding TCP socket to `::` first before falling back to `0.0.0.0`.
This commit is contained in:
parent
c61b0e9cbc
commit
2272052461
18
lib/net.js
18
lib/net.js
@ -1083,8 +1083,16 @@ var createServerHandle = exports._createServerHandle =
|
||||
}
|
||||
|
||||
if (address || port) {
|
||||
debug('bind to ' + address);
|
||||
if (addressType === 6) {
|
||||
debug('bind to ' + (address || 'anycast'));
|
||||
if (!address) {
|
||||
// Try binding to ipv6 first
|
||||
err = handle.bind6('::', port);
|
||||
if (err) {
|
||||
handle.close();
|
||||
// Fallback to ipv4
|
||||
return createServerHandle('0.0.0.0', port);
|
||||
}
|
||||
} else if (addressType === 6) {
|
||||
err = handle.bind6(address, port);
|
||||
} else {
|
||||
err = handle.bind(address, port);
|
||||
@ -1214,7 +1222,7 @@ Server.prototype.listen = function() {
|
||||
|
||||
if (arguments.length == 0 || util.isFunction(arguments[0])) {
|
||||
// Bind to a random port.
|
||||
listen(self, '0.0.0.0', 0, null, backlog);
|
||||
listen(self, null, 0, null, backlog);
|
||||
|
||||
} else if (arguments[0] && util.isObject(arguments[0])) {
|
||||
var h = arguments[0];
|
||||
@ -1240,7 +1248,7 @@ Server.prototype.listen = function() {
|
||||
util.isFunction(arguments[1]) ||
|
||||
util.isNumber(arguments[1])) {
|
||||
// The first argument is the port, no IP given.
|
||||
listen(self, '0.0.0.0', port, 4, backlog);
|
||||
listen(self, null, port, 4, backlog);
|
||||
|
||||
} else {
|
||||
// The first argument is the port, the second an IP.
|
||||
@ -1248,7 +1256,7 @@ Server.prototype.listen = function() {
|
||||
if (err) {
|
||||
self.emit('error', err);
|
||||
} else {
|
||||
listen(self, ip || '0.0.0.0', port, ip ? addressType : 4, backlog);
|
||||
listen(self, ip, port, ip ? addressType : 4, backlog);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user