@@ -29,11 +29,16 @@ const internalNet = require('internal/net');
29
29
const { customPromisifyArgs } = require ( 'internal/util' ) ;
30
30
const errors = require ( 'internal/errors' ) ;
31
31
32
- const GetAddrInfoReqWrap = cares . GetAddrInfoReqWrap ;
33
- const GetNameInfoReqWrap = cares . GetNameInfoReqWrap ;
34
- const QueryReqWrap = cares . QueryReqWrap ;
32
+ const {
33
+ GetAddrInfoReqWrap,
34
+ GetNameInfoReqWrap,
35
+ QueryReqWrap,
36
+ ChannelWrap,
37
+ isIP
38
+ } = cares ;
39
+
40
+ const defaultChannel = new ChannelWrap ( ) ;
35
41
36
- const isIP = cares . isIP ;
37
42
const isLegalPort = internalNet . isLegalPort ;
38
43
39
44
@@ -241,8 +246,6 @@ function onresolve(err, result, ttls) {
241
246
242
247
243
248
function resolver ( bindingName ) {
244
- var binding = cares [ bindingName ] ;
245
-
246
249
return function query ( name , /* options, */ callback ) {
247
250
var options ;
248
251
if ( arguments . length > 2 ) {
@@ -263,7 +266,7 @@ function resolver(bindingName) {
263
266
req . hostname = name ;
264
267
req . oncomplete = onresolve ;
265
268
req . ttl = ! ! ( options && options . ttl ) ;
266
- var err = binding ( req , name ) ;
269
+ var err = defaultChannel [ bindingName ] ( req , name ) ;
267
270
if ( err ) throw errnoException ( err , bindingName ) ;
268
271
return req ;
269
272
} ;
@@ -305,7 +308,7 @@ function resolve(hostname, rrtype, callback) {
305
308
306
309
307
310
function getServers ( ) {
308
- const ret = cares . getServers ( ) ;
311
+ const ret = defaultChannel . getServers ( ) ;
309
312
return ret . map ( ( val ) => {
310
313
if ( ! val [ 1 ] || val [ 1 ] === IANA_DNS_PORT ) return val [ 0 ] ;
311
314
@@ -318,7 +321,7 @@ function getServers() {
318
321
function setServers ( servers ) {
319
322
// cache the original servers because in the event of an error setting the
320
323
// servers cares won't have any servers available for resolution
321
- const orig = cares . getServers ( ) ;
324
+ const orig = defaultChannel . getServers ( ) ;
322
325
const newSet = [ ] ;
323
326
const IPv6RE = / \[ ( .* ) \] / ;
324
327
const addrSplitRE = / ( ^ .+ ?) (?: : ( \d + ) ) ? $ / ;
@@ -350,11 +353,11 @@ function setServers(servers) {
350
353
throw new errors . Error ( 'ERR_INVALID_IP_ADDRESS' , serv ) ;
351
354
} ) ;
352
355
353
- const errorNumber = cares . setServers ( newSet ) ;
356
+ const errorNumber = defaultChannel . setServers ( newSet ) ;
354
357
355
358
if ( errorNumber !== 0 ) {
356
359
// reset the servers to the old servers, because ares probably unset them
357
- cares . setServers ( orig . join ( ',' ) ) ;
360
+ defaultChannel . setServers ( orig . join ( ',' ) ) ;
358
361
359
362
var err = cares . strerror ( errorNumber ) ;
360
363
throw new errors . Error ( 'ERR_DNS_SET_SERVERS_FAILED' , err , servers ) ;
0 commit comments