|
|
@ -28,7 +28,7 @@ var uv = process.binding('uv'); |
|
|
|
var isIp = net.isIP; |
|
|
|
|
|
|
|
|
|
|
|
function errnoException(err, syscall) { |
|
|
|
function errnoException(err, syscall, hostname) { |
|
|
|
// FIXME(bnoordhuis) Remove this backwards compatibility shite and pass
|
|
|
|
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
|
|
|
|
if (err === uv.UV_EAI_MEMORY || |
|
|
@ -36,14 +36,19 @@ function errnoException(err, syscall) { |
|
|
|
err === uv.UV_EAI_NONAME) { |
|
|
|
err = 'ENOTFOUND'; |
|
|
|
} |
|
|
|
var ex = null; |
|
|
|
if (typeof err === 'string') { // c-ares error code.
|
|
|
|
var ex = new Error(syscall + ' ' + err); |
|
|
|
ex = new Error(syscall + ' ' + err); |
|
|
|
ex.code = err; |
|
|
|
ex.errno = err; |
|
|
|
ex.syscall = syscall; |
|
|
|
return ex; |
|
|
|
} else { |
|
|
|
ex = util._errnoException(err, syscall); |
|
|
|
} |
|
|
|
if (hostname) { |
|
|
|
ex.hostname = hostname; |
|
|
|
} |
|
|
|
return util._errnoException(err, syscall); |
|
|
|
return ex; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -83,7 +88,7 @@ function makeAsync(callback) { |
|
|
|
|
|
|
|
function onlookup(err, addresses) { |
|
|
|
if (err) { |
|
|
|
return this.callback(errnoException(err, 'getaddrinfo')); |
|
|
|
return this.callback(errnoException(err, 'getaddrinfo', this.hostname)); |
|
|
|
} |
|
|
|
if (this.family) { |
|
|
|
this.callback(null, addresses[0], this.family); |
|
|
@ -133,10 +138,11 @@ exports.lookup = function(hostname, family, callback) { |
|
|
|
var req = { |
|
|
|
callback: callback, |
|
|
|
family: family, |
|
|
|
hostname: hostname, |
|
|
|
oncomplete: onlookup |
|
|
|
}; |
|
|
|
var err = cares.getaddrinfo(req, hostname, family); |
|
|
|
if (err) throw errnoException(err, 'getaddrinfo'); |
|
|
|
if (err) throw errnoException(err, 'getaddrinfo', hostname); |
|
|
|
|
|
|
|
callback.immediately = true; |
|
|
|
return req; |
|
|
@ -145,7 +151,7 @@ exports.lookup = function(hostname, family, callback) { |
|
|
|
|
|
|
|
function onresolve(err, result) { |
|
|
|
if (err) |
|
|
|
this.callback(errnoException(err, this.bindingName)); |
|
|
|
this.callback(errnoException(err, this.bindingName, this.hostname)); |
|
|
|
else |
|
|
|
this.callback(null, result); |
|
|
|
} |
|
|
@ -159,6 +165,7 @@ function resolver(bindingName) { |
|
|
|
var req = { |
|
|
|
bindingName: bindingName, |
|
|
|
callback: callback, |
|
|
|
hostname: name, |
|
|
|
oncomplete: onresolve |
|
|
|
}; |
|
|
|
var err = binding(req, name); |
|
|
|