本文整理汇总了C++中CDnsThread::cacheHit方法的典型用法代码示例。如果您正苦于以下问题:C++ CDnsThread::cacheHit方法的具体用法?C++ CDnsThread::cacheHit怎么用?C++ CDnsThread::cacheHit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDnsThread
的用法示例。
在下文中一共展示了CDnsThread::cacheHit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetIPList
extern "C" int GetIPList(void *data, addr_t* addr, int max, int ipv4, int ipv6) {
CDnsThread *thread = (CDnsThread*)data;
thread->cacheHit();
unsigned int size = thread->cache.size();
unsigned int maxmax = (ipv4 ? thread->nIPv4 : 0) + (ipv6 ? thread->nIPv6 : 0);
if (max > size)
max = size;
if (max > maxmax)
max = maxmax;
int i=0;
while (i<max) {
int j = i + (rand() % (size - i));
do {
bool ok = (ipv4 && thread->cache[j].v == 4) ||
(ipv6 && thread->cache[j].v == 6);
if (ok) break;
j++;
if (j==size)
j=i;
} while(1);
addr[i] = thread->cache[j];
thread->cache[j] = thread->cache[i];
thread->cache[i] = addr[i];
i++;
}
return max;
}
示例2: GetIPList
extern "C" uint32_t GetIPList(void *data, char *requestedHostname, addr_t *addr,
uint32_t max, uint32_t ipv4, uint32_t ipv6) {
CDnsThread *thread = (CDnsThread *)data;
uint64_t requestedFlags = 0;
int hostlen = strlen(requestedHostname);
if (hostlen > 1 && requestedHostname[0] == 'x' &&
requestedHostname[1] != '0') {
char *pEnd;
uint64_t flags = (uint64_t)strtoull(requestedHostname + 1, &pEnd, 16);
if (*pEnd == '.' && pEnd <= requestedHostname + 17 &&
std::find(thread->filterWhitelist.begin(),
thread->filterWhitelist.end(),
flags) != thread->filterWhitelist.end()) {
requestedFlags = flags;
} else {
return 0;
}
} else if (strcasecmp(requestedHostname, thread->dns_opt.host)) {
return 0;
}
thread->cacheHit(requestedFlags);
auto &thisflag = thread->perflag[requestedFlags];
uint32_t size = thisflag.cache.size();
uint32_t maxmax = (ipv4 ? thisflag.nIPv4 : 0) + (ipv6 ? thisflag.nIPv6 : 0);
if (max > size) {
max = size;
}
if (max > maxmax) {
max = maxmax;
}
uint32_t i = 0;
while (i < max) {
uint32_t j = i + (rand() % (size - i));
do {
bool ok = (ipv4 && thisflag.cache[j].v == 4) ||
(ipv6 && thisflag.cache[j].v == 6);
if (ok) {
break;
}
j++;
if (j == size) {
j = i;
}
} while (1);
addr[i] = thisflag.cache[j];
thisflag.cache[j] = thisflag.cache[i];
thisflag.cache[i] = addr[i];
i++;
}
return max;
}
示例3: if
extern "C" int GetIPList(void *data, char *requestedHostname, addr_t* addr, int max, int ipv4, int ipv6) {
CDnsThread *thread = (CDnsThread*)data;
uint64_t requestedFlags = 0;
int hostlen = strlen(requestedHostname);
if (hostlen > 1 && requestedHostname[0] == 'x' && requestedHostname[1] != '0') {
char *pEnd;
uint64_t flags = (uint64_t)strtoull(requestedHostname+1, &pEnd, 16);
if (*pEnd == '.' && pEnd <= requestedHostname+17 && std::find(thread->filterWhitelist.begin(), thread->filterWhitelist.end(), flags) != thread->filterWhitelist.end())
requestedFlags = flags;
else
return 0;
}
else if (strcasecmp(requestedHostname, thread->dns_opt.host))
return 0;
thread->cacheHit(requestedFlags);
unsigned int size = thread->cache[requestedFlags].size();
unsigned int maxmax = (ipv4 ? thread->nIPv4 : 0) + (ipv6 ? thread->nIPv6 : 0);
if (max > size)
max = size;
if (max > maxmax)
max = maxmax;
int i=0;
while (i<max) {
int j = i + (rand() % (size - i));
do {
bool ok = (ipv4 && thread->cache[requestedFlags][j].v == 4) ||
(ipv6 && thread->cache[requestedFlags][j].v == 6);
if (ok) break;
j++;
if (j==size)
j=i;
} while(1);
addr[i] = thread->cache[requestedFlags][j];
thread->cache[requestedFlags][j] = thread->cache[requestedFlags][i];
thread->cache[requestedFlags][i] = addr[i];
i++;
}
return max;
}