sigint.cpp
来自「最经典的bittorrent协议的实现的源码」· C++ 代码 · 共 65 行
CPP
65 行
#ifndef WINDOWS#include <sys/types.h>#include <signal.h>#include "btcontent.h"#include "tracker.h"#include "peerlist.h"#include "btconfig.h"#include "console.h"#include "sigint.h"RETSIGTYPE sig_catch(int sig_no){ if(SIGINT == sig_no || SIGTERM == sig_no){ Tracker.ClearRestart(); Tracker.SetStoped(); signal(sig_no,sig_catch2); }}static RETSIGTYPE sig_catch2(int sig_no){ if(SIGINT == sig_no || SIGTERM == sig_no){ if( cfg_cache_size ) BTCONTENT.FlushCache(); BTCONTENT.SaveBitfield(); WORLD.CloseAll(); signal(sig_no,SIG_DFL); raise(sig_no); }}// Handler for other signalsRETSIGTYPE signals(int sig_no){ return CONSOLE.Signal(sig_no);}#endifvoid sig_setup(){#ifndef WINDOWS signal(SIGPIPE,SIG_IGN); signal(SIGINT,sig_catch); signal(SIGTERM,sig_catch); // Don't let printf restart a write after SIGTTOU, we will hard-loop! struct sigaction handler; handler.sa_handler = signals; sigemptyset(&(handler.sa_mask)); handler.sa_flags = 0; // SA_RESTART is not set sigaction(SIGTTOU, &handler, (struct sigaction *)0); // Likewise with input after SIGTTIN sigaction(SIGTTIN, &handler, (struct sigaction *)0); signal(SIGCONT,signals); signal(SIGTSTP,signals);#endif}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?