⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input.cc

📁 100 病毒源碼,原始碼,無毒 ......
💻 CC
字号:
// Larbin// Sebastien Ailleret// 03-02-00 -> 03-02-00#include <unistd.h>#include <iostream.h>#include <string.h>#include "types.h"#include "xutils/text.h"#include "xinterf/input.h"#include "xutils/debug.h"static void manageConnection (int fds);/** The way to submit something to fetch * @param urlDoc the Url of the page to fetch */void *startInput (void *none) {  crash("Input is waiting for queries");  int fds;  int nAllowReuse = 1;  struct sockaddr_in addr;  bzero (&addr, sizeof(addr));  addr.sin_addr.s_addr = INADDR_ANY;  addr.sin_family = AF_INET;  addr.sin_port = htons(global::inputPort);  if ((fds = socket(AF_INET, SOCK_STREAM, 0)) == -1	  || setsockopt(fds, SOL_SOCKET, SO_REUSEADDR, (char*)&nAllowReuse, sizeof(nAllowReuse))	  || bind(fds, (struct sockaddr *) &addr, sizeof(addr)) != 0	  || listen(fds, 4) != 0) {	cerr << "Unable to get the socket\n";	exit(1);  }  // manage requests  for (;;) {	struct sockaddr_in addrc;	int fdc;	uint len = sizeof(addr);	fdc = accept(fds, (struct sockaddr *) &addrc, &len);	if (fdc == -1) {	  cerr << "Trouble with startInput...\n";	} else {	  manageConnection(fdc);	}  }  // Needed by startThread  return NULL;}/** read all urls from this socket * The first line gives the status ("priority:1 deapth:3 test:0") */static void manageConnection (int fds) {  // Get status line  char *line = noEndReadline(fds);  if (line != NULL) {	uint priority;	uint deapth;	uint test;	if (sscanf(line, "priority:%u deapth:%u test:%u",               &priority, &deapth, &test) == 3) {      // The first line is valid      delete [] line;      // Get urls      line = noEndReadline(fds);      while (line != NULL) {        url *u = new url(line, deapth);        if (u->isValid()) {          if (test) {            if (global::seen->testSet(u)) {              if (priority) {                global::URLsInput->put(u);              } else {                global::URLsInternal->put(u);              }            } else {              delete u;            }          } else {            global::seen->set(u);            if (priority) {              global::URLsInput->put(u);            } else {              global::URLsInternal->put(u);            }          }        } else {          delete u;        }        line = noEndReadline(fds);      }    } else {      cerr << "The first line of input is not valid... Connection closed\n";    }  }  // close the socket  shutdown(fds, 2);  close(fds);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -