Skip to content
Snippets Groups Projects
Commit 8e3a8aa7 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Only the async query needs the timeout now, so move it back in.

Also, have handle_response() return errors.
parent d52a4c5c
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -108,18 +108,6 @@ DNS.classes = { ...@@ -108,18 +108,6 @@ DNS.classes = {
'HS':4 'HS':4
}; };
DNS.prototype.handle_timeout = function(os) {
os.failed++;
delete this.outstanding[os.id];
if (os.failed > os.failures)
os.callback.call(os);
else
os.obj.query(os.query, os.callback, os.thisObj, os.recursive,
os.timeout, os.failures, os.failed);
};
DNS.prototype.generate_query = function(queries, recursive) { DNS.prototype.generate_query = function(queries, recursive) {
var id; var id;
var namebits = {}; var namebits = {};
...@@ -418,8 +406,6 @@ DNS.prototype.handle_response = function(sock) { ...@@ -418,8 +406,6 @@ DNS.prototype.handle_response = function(sock) {
answers = string_to_int16(resp.substr(6, 2)); answers = string_to_int16(resp.substr(6, 2));
nameservers = string_to_int16(resp.substr(8, 2)); nameservers = string_to_int16(resp.substr(8, 2));
arecords = string_to_int16(resp.substr(10, 2)); arecords = string_to_int16(resp.substr(10, 2));
if (answers === 0)
return null;
if (q.timeoutid !== undefined) if (q.timeoutid !== undefined)
js.clearTimeout(q.timeoutid); js.clearTimeout(q.timeoutid);
offset = 12; offset = 12;
...@@ -508,6 +494,16 @@ DNS.prototype.asynchronous_query = function(queries, /* queryStr, type, class, * ...@@ -508,6 +494,16 @@ DNS.prototype.asynchronous_query = function(queries, /* queryStr, type, class, *
if (failed === undefined) if (failed === undefined)
failed = 0; failed = 0;
function handle_timeout() {
this.failed++;
delete this.obj.outstanding[this.id];
if (this.failed >= this.failures)
this.callback.call(this);
else
this.obj.query(this.query, this.callback, this.thisObj, this.recursive, this.timeout, this.failures,
this.failed);
}
queries.forEach(function(q) { queries.forEach(function(q) {
query = this.generate_query([q], recursive); query = this.generate_query([q], recursive);
...@@ -517,8 +513,7 @@ DNS.prototype.asynchronous_query = function(queries, /* queryStr, type, class, * ...@@ -517,8 +513,7 @@ DNS.prototype.asynchronous_query = function(queries, /* queryStr, type, class, *
this.outstanding[query.id].timeout = timeout; this.outstanding[query.id].timeout = timeout;
this.outstanding[query.id].failures = failures; this.outstanding[query.id].failures = failures;
this.outstanding[query.id].failed = failed; this.outstanding[query.id].failed = failed;
this.outstanding[query.id].timeoutid = js.setTimeout(this.handle_timeout, timeout, this.outstanding[query.id].timeoutid = js.setTimeout(handle_timeout, timeout, this.outstanding[query.id]);
this.outstanding[query.id]);
this.sockets.forEach(function(sock) { this.sockets.forEach(function(sock) {
sock.write(query.buf); sock.write(query.buf);
...@@ -657,6 +652,7 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -657,6 +652,7 @@ DNS.prototype.resolve = function(host, callback, thisObj)
function handle_response(resp) { function handle_response(resp) {
var rectype; var rectype;
if (resp !== undefined) {
switch(resp.queries[0].type) { switch(resp.queries[0].type) {
case DNS.types.A: case DNS.types.A:
rectype = 'A'; rectype = 'A';
...@@ -665,16 +661,19 @@ DNS.prototype.resolve = function(host, callback, thisObj) ...@@ -665,16 +661,19 @@ DNS.prototype.resolve = function(host, callback, thisObj)
rectype = 'AAAA'; rectype = 'AAAA';
break; break;
}; };
}
if (rectype === undefined) if (rectype === undefined)
return; return;
this[rectype].addrs = []; this[rectype].addrs = [];
if (resp !== undefined && resp.answers !== undefined) {
resp.answers.forEach(function(ans) { resp.answers.forEach(function(ans) {
if (resp.queries[0].type != ans.type || resp.queries[0].class != ans.class) if (resp.queries[0].type != ans.type || resp.queries[0].class != ans.class)
return; return;
this[rectype].addrs.push(ans.rdata); this[rectype].addrs.push(ans.rdata);
}, this); }, this);
}
if (this.callback !== undefined) if (this.callback !== undefined)
js.dispatchEvent(this.unique_id + '.resp'+rectype, this); js.dispatchEvent(this.unique_id + '.resp'+rectype, this);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment