Stdlibnet
dns
import std::net::dns; · source
Name resolution
function resolve(host: Str) -> Result<ResolvedAddrs, IoError>;
function resolve_one(host: Str) -> Result<IpAddr, IoError>;
function lookup(host: Str, port: u16) -> Result<Array<SocketAddr>, IoError>;
| Function / future | Returns |
|---|---|
resolve(host) | Result<ResolvedAddrs, IoError> — blocking. |
resolve_one(host) | The first address. |
lookup(host, port) | Every address paired with port. |
Resolve::start(host) | ResolvedAddrs, without blocking the executor. |
Resolution goes through getaddrinfo, with its error codes mapped into IoError. getaddrinfo has no non-blocking form on any platform, so the three functions block the calling thread.
ResolvedAddrs
type struct ResolvedAddrs {
addrs: Array<IpAddr>;
length(&this) -> u64;
get(&this, index: u64) -> Option<IpAddr>;
first_ipv4(&this, port: u16) -> Option<SocketAddr>;
drop(mut &this) -> void;
}
Every address the resolver returned, in its order. first_ipv4(port) is the common case — the first v4 address paired with a port, ready to dial — and it must be dropped.
Resolve
type struct Resolve {
host: Str;
job: ResolveJob*;
static start(host: Str) -> Resolve;
}
The async spelling of resolve: it runs the same getaddrinfo call on the executor's blocking pool and wakes the task when it finishes, which is what HttpsClient uses. Dropping it mid-resolution releases the future's side of the job; the pool frees the block when the call eventually returns.
Trait implementations
implement trait Future for struct Resolve
implement trait Drop for struct Resolve