@ -78,6 +78,18 @@ function makeAsync(callback) {
}
function onlookup ( err , addresses ) {
if ( err ) {
return this . callback ( errnoException ( err , 'getaddrinfo' ) ) ;
}
if ( this . family ) {
this . callback ( null , addresses [ 0 ] , this . family ) ;
} else {
this . callback ( null , addresses [ 0 ] , addresses [ 0 ] . indexOf ( ':' ) >= 0 ? 6 : 4 ) ;
}
}
// Easy DNS A/AAAA look up
// lookup(domain, [family,] callback)
exports . lookup = function ( domain , family , callback ) {
@ -115,49 +127,39 @@ exports.lookup = function(domain, family, callback) {
return { } ;
}
function onanswer ( err , addresses ) {
if ( err ) {
return callback ( errnoException ( err , 'getaddrinfo' ) ) ;
}
if ( family ) {
callback ( null , addresses [ 0 ] , family ) ;
} else {
callback ( null , addresses [ 0 ] , addresses [ 0 ] . indexOf ( ':' ) >= 0 ? 6 : 4 ) ;
}
}
var req = { } ;
var req = {
callback : callback ,
family : family ,
oncomplete : onlookup
} ;
var err = cares . getaddrinfo ( req , domain , family ) ;
if ( err ) {
throw errnoException ( err , 'getaddrinfo' ) ;
}
req . oncomplete = onanswer ;
if ( err ) throw errnoException ( err , 'getaddrinfo' ) ;
callback . immediately = true ;
return req ;
} ;
function resolver ( bindingName ) {
var binding = cares [ bindingName ] ;
return function query ( name , callback ) {
function onanswer ( err , result ) {
function onresolve ( err , result ) {
if ( err )
callback ( errnoException ( err , bindingName ) ) ;
this . callback ( errnoException ( err , this . bindingName ) ) ;
else
callback ( null , result ) ;
this . callback ( null , result ) ;
}
callback = makeAsync ( callback ) ;
var req = { } ;
var err = binding ( req , name , onanswer ) ;
if ( err ) {
throw errnoException ( err , bindingName ) ;
}
function resolver ( bindingName ) {
var binding = cares [ bindingName ] ;
return function query ( name , callback ) {
callback = makeAsync ( callback ) ;
var req = {
bindingName : bindingName ,
callback : callback ,
oncomplete : onresolve
} ;
var err = binding ( req , name ) ;
if ( err ) throw errnoException ( err , bindingName ) ;
callback . immediately = true ;
return req ;
}