diff --git a/bin/dig.js b/bin/dig.js index 4b3e750..9d9b35c 100755 --- a/bin/dig.js +++ b/bin/dig.js @@ -264,10 +264,13 @@ cli.main(function (args, cli) { console.log(";; connection timed out; no servers could be reached"); console.log(";; [timed out after " + res.timeout + "ms and 1 tries]"); } + , onClose: function () { + console.log(''); + } , mdns: cli.mdns , nameserver: cli.nameserver , port: cli.port , timeout: cli.timeout }; - dig.request(queryAb, opts); + dig.resolve(queryAb, opts); }); diff --git a/dns-request.js b/dns-request.js index 636e2f3..bb49454 100644 --- a/dns-request.js +++ b/dns-request.js @@ -24,7 +24,7 @@ function request(queryAb, opts) { server.nameserver = nameserver; handlers.onError = function (err) { - if (opts.onError) { opts.onError(err); } + if (opts.onError) { opts.onError(err); } else { throw err; } server.close(); }; handlers.onMessage = function (bin) { @@ -51,10 +51,14 @@ function request(queryAb, opts) { if (opts.onSent) { opts.onSent({ port: opts.port, nameserver: server.nameserver }); } }); }; + handlers.onClose = function () { + if (opts.onClose) { opts.onClose(); } + }; server.on('error', handlers.onError); server.on('message', handlers.onMessage); server.on('listening', handlers.onListening); + server.on('close', handlers.onClose); // 0 dns request // 53 dns server @@ -92,5 +96,6 @@ function requestJson(query, opts) { return request(queryAb, options); } +module.exports.resolve = request; module.exports.request = request; module.exports.requestJson = requestJson;