LookupHostWithin
function LookupHostWithin(const aName: string; aFamily: tHostLookupFamily; aWithinMs: Cardinal; aCancelled: tHostLookupCancelQuery; out aAnswer: tHostLookupAnswer; aResolve: tHostResolveFunc = nil): tHostLookupResult;
LookupHostWithin resolves aName with the operating system's resolver - the getaddrinfo LookupHost uses, so the hosts file, the system's DNS servers of either address family and its cache all take part - and waits for the answer at most aWithinMs milliseconds (0: hlrTimedOut at once, nothing started), asking aCancelled (when assigned) at least every 10 ms. getaddrinfo cannot be interrupted, so the lookup runs on a thread of its own. One still running when the wait ends is abandoned: it finishes in the background, holds everything it uses, and its answer is discarded. aResolve, when assigned, runs in getaddrinfo's place, on the same thread and under the same wait.
Native lookups cannot be forcibly stopped. Before unloading a DLL or runtime package containing this unit, stop its request callers, call ShutdownHostLookups, and unload only after it returns True and all callers have returned. Resolver callbacks and their modules must remain alive until that barrier succeeds too. Never call these APIs from library initialization or finalization (DllMain), or ShutdownHostLookups from a resolver callback. Windows loader-lock callbacks cannot safely wait for thread exit. Ordinary executable finalization gives pending lookups up to 20 s to finish.