|
|
@ -1,6 +1,7 @@ |
|
|
|
var sys = require("sys"); |
|
|
|
var fs = require("fs"); |
|
|
|
var events = require("events"); |
|
|
|
var dns = require('dns_cares'); |
|
|
|
|
|
|
|
var kMinPoolSpace = 128; |
|
|
|
var kPoolSize = 40*1024; |
|
|
@ -38,8 +39,6 @@ var toRead = binding.toRead; |
|
|
|
var setNoDelay = binding.setNoDelay; |
|
|
|
var socketError = binding.socketError; |
|
|
|
var getsockname = binding.getsockname; |
|
|
|
var getaddrinfo = binding.getaddrinfo; |
|
|
|
var isIP = binding.isIP; |
|
|
|
var errnoException = binding.errnoException; |
|
|
|
var EINPROGRESS = binding.EINPROGRESS; |
|
|
|
var ENOENT = binding.ENOENT; |
|
|
@ -615,11 +614,11 @@ Stream.prototype.connect = function () { |
|
|
|
// TODO dns resolution on arguments[1]
|
|
|
|
var port = arguments[0]; |
|
|
|
self._resolving = true; |
|
|
|
lookupDomainName(arguments[1], function (err, ip, isV4) { |
|
|
|
dns.lookup(arguments[1], function (err, ip, addressType) { |
|
|
|
if (err) { |
|
|
|
self.emit('error', err); |
|
|
|
} else { |
|
|
|
self.type = isV4 ? 'tcp4' : 'tcp6'; |
|
|
|
self.type = addressType == 4 ? 'tcp4' : 'tcp6'; |
|
|
|
self.fd = socket(self.type); |
|
|
|
self._resolving = false; |
|
|
|
doConnect(self, port, ip); |
|
|
@ -759,46 +758,6 @@ exports.createServer = function (listener) { |
|
|
|
return new Server(listener); |
|
|
|
}; |
|
|
|
|
|
|
|
// This function does both an ipv4 and ipv6 look up.
|
|
|
|
// It first tries the ipv4 look up, if that fails, then it does the ipv6.
|
|
|
|
// callback(dn, isV4
|
|
|
|
function lookupDomainName (dn, callback) { |
|
|
|
var kind = isIP(dn); |
|
|
|
if (kind) { |
|
|
|
// Always wait until the next tick this is so people can do
|
|
|
|
//
|
|
|
|
// server.listen(8000);
|
|
|
|
// server.addListener('listening', fn);
|
|
|
|
//
|
|
|
|
// Marginally slower, but a lot fewer WTFs.
|
|
|
|
process.nextTick(function () { |
|
|
|
callback(null, dn, kind == 4 ? true : false); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
debug("getaddrinfo 4 " + dn); |
|
|
|
getaddrinfo(dn, 4, function (err, r4) { |
|
|
|
if (err) { |
|
|
|
callback(err); |
|
|
|
} else if (r4.length > 0) { |
|
|
|
debug("getaddrinfo 4 found " + r4); |
|
|
|
callback(null, r4[0], true); |
|
|
|
} else { |
|
|
|
debug("getaddrinfo 6 " + dn); |
|
|
|
getaddrinfo(dn, 6, function (err, r6) { |
|
|
|
if (err) { |
|
|
|
callback(err); |
|
|
|
} else if (r6.length == 0) { |
|
|
|
callback(new Error("No address associated with hostname " + dn)); |
|
|
|
} else { |
|
|
|
debug("getaddrinfo 6 found " + r6); |
|
|
|
callback(null, r6[0], false); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Listen on a UNIX socket
|
|
|
|
// server.listen("/tmp/socket");
|
|
|
@ -854,11 +813,11 @@ Server.prototype.listen = function () { |
|
|
|
} else { |
|
|
|
// the first argument is the port, the second an IP
|
|
|
|
var port = arguments[0]; |
|
|
|
lookupDomainName(arguments[1], function (err, ip, isV4) { |
|
|
|
dns.lookup(arguments[1], function (err, ip, addressType) { |
|
|
|
if (err) { |
|
|
|
self.emit('error', err); |
|
|
|
} else { |
|
|
|
self.type = isV4 ? 'tcp4' : 'tcp6'; |
|
|
|
self.type = addressType == 4 ? 'tcp4' : 'tcp6'; |
|
|
|
self.fd = socket(self.type); |
|
|
|
bind(self.fd, port, ip); |
|
|
|
self._doListen(); |
|
|
|