Bug 1838739 - Initialize result of SetAsGPUOutOfMemoryError. r=webgpu-reviewers,nical
[gecko.git] / netwerk / dns / GetAddrInfo.h
blob13bc2412d28c3301c524da56d1af25504f6f776f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef netwerk_dns_GetAddrInfo_h
8 #define netwerk_dns_GetAddrInfo_h
10 #include "nsError.h"
11 #include "nscore.h"
12 #include "nsINativeDNSResolverOverride.h"
13 #include "nsHashKeys.h"
14 #include "nsTHashMap.h"
15 #include "mozilla/RWLock.h"
16 #include "nsTArray.h"
17 #include "prio.h"
18 #include "mozilla/net/DNS.h"
20 #if defined(XP_WIN)
21 # define DNSQUERY_AVAILABLE 1
22 #else
23 # undef DNSQUERY_AVAILABLE
24 #endif
26 namespace mozilla {
27 namespace net {
29 class AddrInfo;
31 /**
32 * Look up a host by name. Mostly equivalent to getaddrinfo(host, NULL, ...) of
33 * RFC 3493.
35 * @param aHost[in] Character string defining the host name of interest
36 * @param aAddressFamily[in] May be AF_INET, AF_INET6, or AF_UNSPEC.
37 * @param aFlags[in] May be either PR_AI_ADDRCONFIG or
38 * PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include PR_AI_NOCANONNAME to
39 * suppress the determination of the canonical name corresponding to
40 * hostname (PR_AI_NOCANONNAME will be ignored if the TTL is retrieved).
41 * @param aAddrInfo[out] Will point to the results of the host lookup, or be
42 * null if the lookup failed.
43 * @param aGetTtl[in] If true, the TTL will be retrieved if DNS provides the
44 * answers..
46 nsresult GetAddrInfo(const nsACString& aHost, uint16_t aAddressFamily,
47 uint16_t aFlags, AddrInfo** aAddrInfo, bool aGetTtl);
49 /**
50 * Initialize the GetAddrInfo module.
52 * GetAddrInfoShutdown() should be called for every time this function is
53 * called.
55 nsresult GetAddrInfoInit();
57 /**
58 * Shutdown the GetAddrInfo module.
60 * This function should be called for every time GetAddrInfoInit() is called.
61 * An assertion may throw (but is not guarenteed) if this function is called
62 * too many times.
64 nsresult GetAddrInfoShutdown();
66 class NativeDNSResolverOverride : public nsINativeDNSResolverOverride {
67 NS_DECL_THREADSAFE_ISUPPORTS
68 NS_DECL_NSINATIVEDNSRESOLVEROVERRIDE
69 public:
70 NativeDNSResolverOverride() = default;
72 static already_AddRefed<nsINativeDNSResolverOverride> GetSingleton();
74 private:
75 virtual ~NativeDNSResolverOverride() = default;
76 mozilla::RWLock mLock MOZ_UNANNOTATED{"NativeDNSResolverOverride"};
78 nsTHashMap<nsCStringHashKey, nsTArray<NetAddr>> mOverrides;
79 nsTHashMap<nsCStringHashKey, nsCString> mCnames;
81 friend bool FindAddrOverride(const nsACString& aHost, uint16_t aAddressFamily,
82 uint16_t aFlags, AddrInfo** aAddrInfo);
85 } // namespace net
86 } // namespace mozilla
88 #endif // netwerk_dns_GetAddrInfo_h