abla/dns/async
Generated from source.
Import with import "abla/dns/async".
Source: abla/dns/async/entry.ab
DnsAsyncOptions (class)
class DnsAsyncOptions(
val timeoutMilliseconds: int = 3000,
// The query is sent again this long after the last send.
val resendMilliseconds: int = 1000,
// Empty reads /etc/resolv.conf once, at the first query.
val nameserver: string = "",
val nameserverPort: int = 53,
val configurationPath: string = "/etc/resolv.conf",
val hostsPath: string = "/etc/hosts"
)
Sets query timeout, resend interval, and nameserver address and port. An empty nameserver uses configurationPath, and hostsPath supplies local name mappings.
DnsAsyncResult (class)
class DnsAsyncResult(
val id: int,
val host: string,
val recordType: int,
val resolution: DnsResolution,
val error: string
)
error is "" on success, otherwise "dns name not found", "dns timeout", "dns socket failed", "dns send failed" or "dns invalid host".
DnsAsyncResult.succeeded (method)
fun succeeded(): bool
Returns true when this completed lookup has no error.
DnsAsyncResolver (class)
resource class DnsAsyncResolver(
val options: DnsAsyncOptions,
var nameserver: string,
// Read at the first query: the search domains, ndots, the hosts file.
var configured: bool,
var search: array<string>,
var ndots: int,
var hosts: string,
// One slot per query until its result is taken; a slot whose id is 0 is
// free.
val queryIds: array<int>,
val queryHosts: array<string>,
// The candidate names, one per line, and the one being asked.
val queryCandidates: array<string>,
val queryCandidateIndex: array<int>,
val querySawNoData: array<bool>,
val queryTypes: array<int>,
val queryDescriptors: array<int>,
val queryIdentifiers: array<int>,
val queryDeadlines: array<int>,
val querySentAt: array<int>,
val queryFinished: array<bool>,
var results: array<DnsAsyncResult>,
var nextId: int,
var inFlight: int
)
Owns sockets and results for outstanding asynchronous DNS queries. Create it with dnsAsyncResolver and drive it with step or an external poller.
DnsAsyncResolver.drop (method)
fun drop(): void
Closes the resolver and its active query sockets.
dnsAsyncResolver (fun)
fun dnsAsyncResolver(options: DnsAsyncOptions = DnsAsyncOptions()): DnsAsyncResolver
Creates a resolver configured with options. Resolver configuration and hosts are read when the first query starts.
DnsAsyncResolver.close (extension fun)
fun DnsAsyncResolver.close(): void
Closes every query's socket and drops the results not yet taken.
DnsAsyncResolver.release (extension fun)
fun DnsAsyncResolver.release(slot: int): void
Closes the active query socket and clears the slot for reuse.
DnsAsyncResolver.finish (extension fun)
fun DnsAsyncResolver.finish(
slot: int,
resolution: DnsResolution,
error: string
): void
Queues the query result or error and releases its slot.
DnsAsyncResolver.configure (extension fun)
fun DnsAsyncResolver.configure(): void
Loads resolver settings and hosts once, consulting the configured options for the name server.
dnsAsyncLine (fun)
fun dnsAsyncLine(lines: string, index: int): string
Line index of lines.
DnsAsyncResolver.candidate (extension fun)
fun DnsAsyncResolver.candidate(slot: int): string
Returns the hostname currently selected for the query slot.
DnsAsyncResolver.send (extension fun)
fun DnsAsyncResolver.send(slot: int): bool
Sends the slot's DNS query to its name server and reports whether the datagram was sent.
DnsAsyncResolver.ask (extension fun)
fun DnsAsyncResolver.ask(slot: int): bool
Asks for the slot's current candidate under a fresh identifier and deadline; false when the send failed (the query is then finished).
DnsAsyncResolver.advance (extension fun)
fun DnsAsyncResolver.advance(slot: int): bool
The candidate failed with NXDOMAIN or no records: ask for the next, or finish with no records or "dns name not found" after the last.
DnsAsyncResolver.start (extension fun)
fun DnsAsyncResolver.start(host: string, recordType: int = 1): int
Starts resolving host for recordType (1 = A, 28 = AAAA) and returns the query's id. The result is ready at once for a literal address (the address itself when its family matches the type, no addresses otherwise), a name the hosts file lists with that type, and a name that cannot be queried or sent.
DnsAsyncResolver.slotOf (extension fun)
fun DnsAsyncResolver.slotOf(id: int): int
Returns the slot for the given active query ID, or -1 for zero or an unknown ID.
DnsAsyncResolver.descriptorOf (extension fun)
fun DnsAsyncResolver.descriptorOf(id: int): int
The socket of query id until its result is taken (-1 for a query that needed none, or once taken).
DnsAsyncResolver.done (extension fun)
fun DnsAsyncResolver.done(id: int): bool
Whether query id has a result waiting for take().
DnsAsyncResolver.waiting (extension fun)
fun DnsAsyncResolver.waiting(slot: int): bool
Returns true if allocated slot has an unfinished query and an open descriptor. An out-of-range slot panics.
DnsAsyncResolver.descriptors (extension fun)
fun DnsAsyncResolver.descriptors(): array<int>
Every in-flight query's socket, to watch for reading in another poller.
DnsAsyncResolver.pending (extension fun)
fun DnsAsyncResolver.pending(): int
The number of queries still in flight.
DnsAsyncResolver.receive (extension fun)
fun DnsAsyncResolver.receive(descriptor: int): bool
Reads one datagram from descriptor (a socket from descriptors() that polled readable). True when it completed its query (false when it only moved the query to its next candidate name).
DnsAsyncResolver.sweep (extension fun)
fun DnsAsyncResolver.sweep(now: int = linuxMonotonicMilliseconds()): void
Ends the queries past their deadline with "dns timeout" and sends again those whose last send is resendMilliseconds old.
DnsAsyncResolver.step (extension fun)
trusted fun DnsAsyncResolver.step(timeoutMilliseconds: int = 0): int
Progresses every query for up to timeoutMilliseconds (0 never blocks): waits for a reply on any in-flight socket, reads the ready ones, then sweeps. Returns the number of datagrams read. Returns at once when nothing is in flight.
DnsAsyncResolver.take (extension fun)
fun DnsAsyncResolver.take(id: int): DnsAsyncResult?
Removes and returns query id's result, closing its socket, or null while it is in flight.
DnsAsyncResolver.takeResults (extension fun)
fun DnsAsyncResolver.takeResults(): array<DnsAsyncResult>
Removes and returns every finished result, in completion order.
DnsAsyncResolver.cancel (extension fun)
fun DnsAsyncResolver.cancel(id: int): void
Abandons query id: closes its socket and drops its result.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.