add onClose event

This commit is contained in:
AJ ONeal 2017-09-20 12:50:32 -06:00
parent f979638090
commit 57ced95c0d
2 changed files with 10 additions and 2 deletions

View File

@ -264,10 +264,13 @@ cli.main(function (args, cli) {
console.log(";; connection timed out; no servers could be reached"); console.log(";; connection timed out; no servers could be reached");
console.log(";; [timed out after " + res.timeout + "ms and 1 tries]"); console.log(";; [timed out after " + res.timeout + "ms and 1 tries]");
} }
, onClose: function () {
console.log('');
}
, mdns: cli.mdns , mdns: cli.mdns
, nameserver: cli.nameserver , nameserver: cli.nameserver
, port: cli.port , port: cli.port
, timeout: cli.timeout , timeout: cli.timeout
}; };
dig.request(queryAb, opts); dig.resolve(queryAb, opts);
}); });

View File

@ -24,7 +24,7 @@ function request(queryAb, opts) {
server.nameserver = nameserver; server.nameserver = nameserver;
handlers.onError = function (err) { handlers.onError = function (err) {
if (opts.onError) { opts.onError(err); } if (opts.onError) { opts.onError(err); } else { throw err; }
server.close(); server.close();
}; };
handlers.onMessage = function (bin) { handlers.onMessage = function (bin) {
@ -51,10 +51,14 @@ function request(queryAb, opts) {
if (opts.onSent) { opts.onSent({ port: opts.port, nameserver: server.nameserver }); } 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('error', handlers.onError);
server.on('message', handlers.onMessage); server.on('message', handlers.onMessage);
server.on('listening', handlers.onListening); server.on('listening', handlers.onListening);
server.on('close', handlers.onClose);
// 0 dns request // 0 dns request
// 53 dns server // 53 dns server
@ -92,5 +96,6 @@ function requestJson(query, opts) {
return request(queryAb, options); return request(queryAb, options);
} }
module.exports.resolve = request;
module.exports.request = request; module.exports.request = request;
module.exports.requestJson = requestJson; module.exports.requestJson = requestJson;