本文整理汇总了C++中NetAddrElement类的典型用法代码示例。如果您正苦于以下问题:C++ NetAddrElement类的具体用法?C++ NetAddrElement怎么用?C++ NetAddrElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetAddrElement类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CacheEntryEnumerator
PLDHashOperator
CacheEntryEnumerator(PLDHashTable *table, PLDHashEntryHdr *entry,
uint32_t number, void *arg)
{
// We don't pay attention to address literals, only resolved domains.
// Also require a host.
nsHostRecord *rec = static_cast<nsHostDBEnt*>(entry)->rec;
MOZ_ASSERT(rec, "rec should never be null here!");
if (!rec || !rec->addr_info || !rec->host) {
return PL_DHASH_NEXT;
}
DNSCacheEntries info;
info.hostname = rec->host;
info.family = rec->af;
info.expiration = (int64_t)(rec->expiration - TimeStamp::NowLoRes()).ToSeconds();
if (info.expiration <= 0) {
// We only need valid DNS cache entries
return PL_DHASH_NEXT;
}
{
MutexAutoLock lock(rec->addr_info_lock);
NetAddr *addr = nullptr;
NetAddrElement *addrElement = rec->addr_info->mAddresses.getFirst();
if (addrElement) {
addr = &addrElement->mAddress;
}
while (addr) {
char buf[kIPv6CStrBufSize];
if (NetAddrToString(addr, buf, sizeof(buf))) {
info.hostaddr.AppendElement(buf);
}
addr = nullptr;
addrElement = addrElement->getNext();
if (addrElement) {
addr = &addrElement->mAddress;
}
}
}
nsTArray<DNSCacheEntries> *args = static_cast<nsTArray<DNSCacheEntries> *>(arg);
args->AppendElement(info);
return PL_DHASH_NEXT;
}
示例2: HostDB_ClearEntry
static void
HostDB_ClearEntry(PLDHashTable *table,
PLDHashEntryHdr *entry)
{
nsHostDBEnt *he = static_cast<nsHostDBEnt*>(entry);
MOZ_ASSERT(he, "nsHostDBEnt is null!");
nsHostRecord *hr = he->rec;
MOZ_ASSERT(hr, "nsHostDBEnt has null host record!");
LOG(("Clearing cache db entry for host [%s].\n", hr->host));
#if defined(DEBUG) && defined(PR_LOGGING)
{
MutexAutoLock lock(hr->addr_info_lock);
if (!hr->addr_info) {
LOG(("No address info for host [%s].\n", hr->host));
} else {
int32_t now = (int32_t) NowInMinutes();
int32_t diff = (int32_t) hr->expiration - now;
LOG(("Record for [%s] expires in %d minute(s).\n", hr->host, diff));
NetAddrElement *addrElement = nullptr;
char buf[kIPv6CStrBufSize];
do {
if (!addrElement) {
addrElement = hr->addr_info->mAddresses.getFirst();
} else {
addrElement = addrElement->getNext();
}
if (addrElement) {
NetAddrToString(&addrElement->mAddress, buf, sizeof(buf));
LOG((" [%s]\n", buf));
}
}
while (addrElement);
}
}
#endif
NS_RELEASE(he->rec);
}
示例3: memcpy
NS_IMETHODIMP
nsDNSRecord::GetAddresses(nsTArray<NetAddr> & aAddressArray)
{
if (mDone) {
return NS_ERROR_NOT_AVAILABLE;
}
mHostRecord->addr_info_lock.Lock();
if (mHostRecord->addr_info) {
for (NetAddrElement *iter = mHostRecord->addr_info->mAddresses.getFirst();
iter; iter = iter->getNext()) {
if (mHostRecord->Blacklisted(&iter->mAddress)) {
continue;
}
NetAddr *addr = aAddressArray.AppendElement(NetAddr());
memcpy(addr, &iter->mAddress, sizeof(NetAddr));
if (addr->raw.family == AF_INET) {
addr->inet.port = 0;
} else if (addr->raw.family == AF_INET6) {
addr->inet6.port = 0;
}
}
mHostRecord->addr_info_lock.Unlock();
} else {
mHostRecord->addr_info_lock.Unlock();
if (!mHostRecord->addr) {
return NS_ERROR_NOT_AVAILABLE;
}
NetAddr *addr = aAddressArray.AppendElement(NetAddr());
memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
if (addr->raw.family == AF_INET) {
addr->inet.port = 0;
} else if (addr->raw.family == AF_INET6) {
addr->inet6.port = 0;
}
}
return NS_OK;
}
示例4: NS_ENSURE_TRUE
//.........这里部分代码省略.........
}
// If this is an IPV4 or IPV6 specific request, check if there is
// an AF_UNSPEC entry we can use. Otherwise, hit the resolver...
else if (!he->rec->resolving) {
if (!(flags & RES_BYPASS_CACHE) &&
((af == PR_AF_INET) || (af == PR_AF_INET6))) {
// First, search for an entry with AF_UNSPEC
const nsHostKey unspecKey = { host, flags, PR_AF_UNSPEC };
nsHostDBEnt *unspecHe = static_cast<nsHostDBEnt *>
(PL_DHashTableOperate(&mDB, &unspecKey, PL_DHASH_LOOKUP));
NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(unspecHe) ||
(PL_DHASH_ENTRY_IS_BUSY(unspecHe) &&
unspecHe->rec),
"Valid host entries should contain a record");
if (PL_DHASH_ENTRY_IS_BUSY(unspecHe) &&
unspecHe->rec &&
unspecHe->rec->HasUsableResult(flags) &&
TimeStamp::NowLoRes() <= (he->rec->expiration + mGracePeriod)) {
MOZ_ASSERT(unspecHe->rec->addr_info || unspecHe->rec->negative,
"Entry should be resolved or negative.");
LOG((" Trying AF_UNSPEC entry for [%s] af: %s.\n",
host, (af == PR_AF_INET) ? "AF_INET" : "AF_INET6"));
he->rec->addr_info = nullptr;
if (unspecHe->rec->negative) {
he->rec->negative = unspecHe->rec->negative;
} else if (unspecHe->rec->addr_info) {
// Search for any valid address in the AF_UNSPEC entry
// in the cache (not blacklisted and from the right
// family).
NetAddrElement *addrIter =
unspecHe->rec->addr_info->mAddresses.getFirst();
while (addrIter) {
if ((af == addrIter->mAddress.inet.family) &&
!unspecHe->rec->Blacklisted(&addrIter->mAddress)) {
if (!he->rec->addr_info) {
he->rec->addr_info = new AddrInfo(
unspecHe->rec->addr_info->mHostName,
unspecHe->rec->addr_info->mCanonicalName);
}
he->rec->addr_info->AddAddress(
new NetAddrElement(*addrIter));
}
addrIter = addrIter->getNext();
}
}
if (he->rec->HasUsableResult(flags)) {
result = he->rec;
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
METHOD_HIT);
ConditionallyRefreshRecord(he->rec, host);
}
// For AF_INET6, a new lookup means another AF_UNSPEC
// lookup. We have already iterated through the
// AF_UNSPEC addresses, so we mark this record as
// negative.
else if (af == PR_AF_INET6) {
LOG((" No AF_INET6 in AF_UNSPEC entry: "
"[%s] unknown host", host));
result = he->rec;
he->rec->negative = true;
status = NS_ERROR_UNKNOWN_HOST;
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
示例5: if
NS_IMETHODIMP
nsDNSRecord::GetNextAddr(uint16_t port, NetAddr *addr)
{
if (mDone) {
return NS_ERROR_NOT_AVAILABLE;
}
mHostRecord->addr_info_lock.Lock();
if (mHostRecord->addr_info) {
if (mIterGenCnt != mHostRecord->addr_info_gencnt) {
// mHostRecord->addr_info has changed, restart the iteration.
mIter = nullptr;
mIterGenCnt = mHostRecord->addr_info_gencnt;
}
bool startedFresh = !mIter;
do {
if (!mIter) {
mIter = mHostRecord->addr_info->mAddresses.getFirst();
} else {
mIter = mIter->getNext();
}
}
while (mIter && mHostRecord->Blacklisted(&mIter->mAddress));
if (!mIter && startedFresh) {
// If everything was blacklisted we want to reset the blacklist (and
// likely relearn it) and return the first address. That is better
// than nothing.
mHostRecord->ResetBlacklist();
mIter = mHostRecord->addr_info->mAddresses.getFirst();
}
if (mIter) {
memcpy(addr, &mIter->mAddress, sizeof(NetAddr));
}
mHostRecord->addr_info_lock.Unlock();
if (!mIter) {
mDone = true;
return NS_ERROR_NOT_AVAILABLE;
}
}
else {
mHostRecord->addr_info_lock.Unlock();
if (!mHostRecord->addr) {
// Both mHostRecord->addr_info and mHostRecord->addr are null.
// This can happen if mHostRecord->addr_info expired and the
// attempt to reresolve it failed.
return NS_ERROR_NOT_AVAILABLE;
}
memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
mDone = true;
}
// set given port
port = htons(port);
if (addr->raw.family == AF_INET) {
addr->inet.port = port;
}
else if (addr->raw.family == AF_INET6) {
addr->inet6.port = port;
}
return NS_OK;
}