📄 fetcho~1.cc
字号:
// Larbin// Sebastien Ailleret// 15-11-99 -> 14-02-00#include <adns.h>#include <iostream.h>#include <errno.h>#include "global.h"#include "xutils/Site.h"#include "xutils/Fifo.h"#include "xutils/debug.h"/* Opens sockets * Never block (eg only opens sockets on allready known sites) * Only one thread for this */void *startFetchNonBlock (void *none) { crash("FetchNonBlock on"); uint i=0; // Avoid active wait at the beginning sleep (2*global::waitDuration); for (;;) { stateNonBlock(i++); global::okSites->get()->fetchNonBlock(); }}/* Number of pending dns calls */uint nbCalls = 0;/* Opens sockets * This function uses adns, which is non thread safe * so do not launch more than one thread with this function */void *startFetchBlock (void *none) { crash("FetchBlock on"); for (;;) { stateBlock(1); // Submit queries while (nbCalls == 0) { // Avoid cpu use if no dns call are in progress // No active wait Site *site = global::dnsSites->get(); site->newQuery(&nbCalls); } stateBlock(2); while (nbCalls<global::dnsConn) { Site *site = global::dnsSites->tryGet(); if (site == NULL) { break; } else { site->newQuery(&nbCalls); } } // Read answers // wait instead of check if nbCalls==global::dnsConn : avoid active wait assert (nbCalls); { // Avoid active wait Site *site; adns_query quer = NULL; adns_answer *ans; crash("Wait for an adns query"); stateBlock(31); int res = adns_wait(global::ads, &quer, &ans, (void**)&site); stateBlock(32); assert (res != ESRCH); nbCalls--; site->dnsAns(ans); free(ans); } // Check for (;;) { Site *site; adns_query quer = NULL; adns_answer *ans; crash("Wait for an adns query"); stateBlock(41); int res = adns_check(global::ads, &quer, &ans, (void**)&site); stateBlock(42); if (res == ESRCH || res == EAGAIN) { // No more query or no more answers break; } nbCalls--; site->dnsAns(ans); free(ans); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -