fetcho~1.cc

来自「一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值」· CC 代码 · 共 93 行

CC
93
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?