- // Larbin
- //fileName: main.cc
- // Sebastien Ailleret
- // 09-11-99 -> 08-03-00
- //comment:anzijin
- //2008.12.25
- #include <unistd.h>
- #include <iostream.h>
- #include <signal.h>
- #include <time.h>
- #include <netdb.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include "global.h"
- #include "xutils/GenericFifo.h"
- #include "xutils/url.h"
- #include "xutils/text.h"
- #include "xutils/threads.h"
- #include "xfetcher/checker.h"
- #include "xsequencer/sequencer.h"
- #include "xfetcher/fetchOpen.h"
- #include "xfetcher/fetchPipe.h"
- #include "xinterf/input.h"
- #include "xutils/debug.h"
- #include "xutils/webserver.h"
- // If this thread terminates, the whole program exits
- int main (int argc, char *argv[])
- {
- //可以不包含参数,直接写调用
- // create all the structures
- global glob(argc, argv); //大部分操作在构造函数中完成,除了getProxyFds函数的调用
- // let's ignore SIGPIPE
- static struct sigaction sn, so;
- sigemptyset(&sn.sa_mask);//初始化由set指定的信号集,信号集里面的所有信号被清空
- sn.sa_flags=SA_RESTART; //系统调用就会重启
- sn.sa_handler = SIG_IGN; //目前SIG_IGN的作用还不清楚,似乎不是一个函数
- /*
- int sigaction(int signum, const struct sigaction * act, struct sigaction * oldact);
- 函数说明:sigaction()会依照参数signum制定的信号编号来设置该信号的处理函数。参数signum
- 可以指定为SIGKILL和SIGSTOP以外的所有信号
- 参数结构sigaction定义如下:
- struct sigaction
- {
- void (*sa_handler)(int);
- sigset_t sa_mask;
- int sa_flags;
- void (*sa_restorer)(void);
- }
- sahandler: 此参数和signal()的参数handler相同,代表新的信号处理函数,其他意义请参考signal()
- sa_mask: 用来设置在处理该信号时暂时将sa_mask指定的信号搁置。
- sa_restorer 此参数没有使用
- sa_flags 用来设置信号处理的其他相关操作,下面的值可用
- SA_RESETHAND/SA_ONESHOT 将信号的处理函数重置为缺省值
- SA_RESTART 被信号中断的系统调用会自行重启。
- SA_NOMASK/SA_NODEFER 在处理此信号未结束前不理会此信号的再次到来,那么在该信号处理函数运行时,内核将不会阻塞该信号
- 关于返回值:执行成功则返回0,如果有错误则返回-1
- 错误代码:
- EINVAL 参数signum不合法,或是企图拦截SIGKILL/SIGSTOPSIGKILL信号
- EFAULT 参数act,oudact的指针地址无法存取
- EINTR 此调用被中断
- SIGPIPE 信号表示:当向一个没有读中端的管道写数据时产生该信号。
- */
- if (sigaction(SIGPIPE, &sn, &so)) //用来检测和改变信号行为且功能强大的一个函数
- {
- cerr << "Unable to disable SIGPIPE/n";
- }
- // Start all threads
- crash("Launch all threads");
- if (startThread(startSequencer, NULL) //startSequencer函数位于sequencer文件中
- || startThread(startFetchBlock, NULL) //startFetchBlock函数位于fetchOpen文件中
- || startThread(startFetchNonBlock, NULL) //startFetchNonBlock函数位于fetchOpen文件中
- || startThread(startFetchPipe, NULL) //startFetchPipe函数位于fetchPipe文件中
- || startThread(startInput, NULL) //startInput函数位于input文件中
- || startThread(startOutput, NULL)) //函数定义在output.h 文件中
- {
- cerr << "Unable to launch a thread/n";
- exit(1);
- }
- // Start the search
- cerr << global::userAgent;
- cerr << " is starting its search/n";
- check( new url(newString(global::firstUrl), global::depthInSite) ); //check函数在checker文件中,check函数只有一个参数
- // Launch the web server
- crash("Launch the webserver");
- webserver(); //webserver函数位于webserver文件中
- }
Larbin 搜索引擎源码赏析——(一)搜索引擎的main函数
最新推荐文章于 2024-01-18 21:25:10 发布