Exemple #1
0
void CDNSChildWorker::TimeOutWork()
{
	//检测和DCS的链接状态
	if(m_DcsNodeFd.moNetStat == TCP_CLOSED)
	{
		TRACE(1, "CDNSChildWorker::TimeOutWork 和DCS链接断开了。");
	}
	uint64 time_now = CTimeBase::get_current_time();
	//发送存活
	if(time_now > m_i64LastKeepLive + KEEP_LIVE_TIME_OUT * 1000)
	{
		KeepLive();
		m_i64LastKeepLive = time_now;
	}

	//dump
	if(time_now > m_i64LastDumpTime + m_pDnsConfig->dump_info_time * 1000)
	{
		Dump();
		m_i64LastDumpTime = time_now;
	}

	//log
	if(time_now > m_i64LastLogTime + m_pDnsConfig->log_file_update_time*1000)
	{
		unsigned int process_id = CCommon::GetProcessId();

		char lszLogFileName[255];
		memset(lszLogFileName, 0, 255);
		CFileStream::GetAppPath(lszLogFileName,255);

		//设置日志文件信息
		SET_TRACE_LEVEL(5);
		unsigned liOptions = (CDebugTrace::Timestamp | CDebugTrace::LogLevel
			& ~CDebugTrace::FileAndLine | CDebugTrace::AppendToFile);
		SET_TRACE_OPTIONS(GET_TRACE_OPTIONS() | liOptions);

		strcpy(strrchr(lszLogFileName,'/'),"//DNS_log");
		CFileStream::CreatePath(lszLogFileName);
		char lszFileDate[50];
		memset(lszFileDate, 0, 50);
		time_t loSystemTime;
		time(&loSystemTime);
		struct tm* lptm = localtime(&loSystemTime);
		sprintf(lszFileDate, "//DNS-%u-%4d%02d%02d%02d%02d.log", process_id,
			1900+lptm->tm_year,1+lptm->tm_mon,lptm->tm_mday, lptm->tm_hour, lptm->tm_min);
		strcat(lszLogFileName,lszFileDate);
		SET_LOG_FILENAME(lszLogFileName);
		m_i64LastLogTime = time_now;
	}

	if(time_now > m_i64LastCheckTimeOut + CRS_DNS_TIMEOUT * 1000)
	{
		CheckTimeOut();
		//test();
		m_i64LastCheckTimeOut = time_now;
	}
}
Exemple #2
0
int main(int argc, char* argv[])
{
	if(argc > 1 && strcmp(argv[1], "-v") == 0)
	{
		cout<<"SinaShow DCS Version Infomation:"<<endl;
		cout<<"CrsTrans Version: "<<gstrDCSWorkerVersion.c_str()<<endl;
		cout<<"Copyright (C) Beijing Sina Information Technology Co.,Ltd 2003-2009"<<endl;
		return 0;
	}

	if(argc > 1 && strcmp(argv[1], "-h") == 0)
	{
		help_info();
		return 0;
	}

	if(argc > 1 && strcmp(argv[1], "-f") != 0)
	{
		help_info();
		return 0;
	}

	string lstrConfigName = "";
	if(argc > 1 && strcmp(argv[1], "-f") == 0)
	{
		lstrConfigName = argv[2];
		if(lstrConfigName.empty())
		{
			help_info();
			return 0;
		}
	}

	char lszLogFileName[255];
	memset(lszLogFileName, 0, 255);
	CFileStream::GetAppPath(lszLogFileName,255);

	string lstrAppPath = lszLogFileName;
	string lstrApp = lstrAppPath.substr(0, lstrAppPath.find_last_of('/'));
	if (chdir(lstrApp.c_str()))
	{
		cout<<"crs_trans error: chdir error."<<lszLogFileName<<endl;
		return 0;
	}

	goDebugTrace = new CDebugTrace;

	unsigned int process_id = CCommon::GetProcessId();

	//设置日志文件信息
	SET_TRACE_LEVEL(5);
	unsigned liOptions = (CDebugTrace::Timestamp | CDebugTrace::LogLevel
		& ~CDebugTrace::FileAndLine | CDebugTrace::AppendToFile);
	SET_TRACE_OPTIONS(GET_TRACE_OPTIONS() | liOptions);

	strcpy(strrchr(lszLogFileName,'/'),"//DCS_log");
	CFileStream::CreatePath(lszLogFileName);
	char lszFileDate[50];
	memset(lszFileDate, 0, 50);
	sprintf(lszFileDate, "//DCS-%u", process_id);
	strcat(lszLogFileName,lszFileDate);
	SET_LOG_FILENAME(lszLogFileName);
	TRACE(1,"\n\n*******************DCS调试日志VERSION:" <<
		gstrDCSWorkerVersion.c_str() << "*******************");

	TRACE(1, "配置文件信息: "<<lstrConfigName.c_str());

	//加载配置文件
	CDCSConfig loDCSConfig;
	loDCSConfig.set_conf_file_name(lstrConfigName.c_str());
	bool bRet = loDCSConfig.load();
	if(!bRet)
	{
		TRACE(1, "ERROR: 加载配置文件失败。");
		return 0;
	}

	CDCSWorker worker;
	worker.SetConfig(&loDCSConfig);
	worker.Run();

	return 0;
}