Beispiel #1
0
void Task::DoStart(u_int32_t uiTaskIdx, bool bByTaskIdx)
{
    m_uiTaskIdx = uiTaskIdx;

    // 0. 初始化信号
    signal(SIGTERM, boss::task::SigHandle);
	
    // 1. 初始化日志
    SetLogName(m_sTaskName.c_str());

    CCfg cCfg;
	char szErrMsg[1024];
	if(iInitLog(LOG_CFG_FILE_PATH, const_cast<char*>(cCfg.GetLogFilePath()), "main", szErrMsg) < 0)
    {
        printf("iInitLog Error:%s\n", szErrMsg);
		return;
    }
	
	// 2. 调用子类的初始化函数
	if(this->Init() != 0)
		return;
	
    // 3. 初始化接收缓冲区
    char sData[sizeof(MsgBuf) + MAX_PAYLOAD_SIZE];
	MsgBuf *pcMsgBuf = new(sData)MsgBuf;
	
	// 4. 循环处理消息管道
	int iType = 0;
	if(bByTaskIdx)
		iType = m_uiTaskIdx;
	
    while(Task::m_bRunning)
    {
        u_int32_t uiQuota = 0;
		if(m_uiRate > 0)
			uiQuota = m_cFMgr.GetQuota();

		u_int32_t uiCount = 0;
		
		while(1)
		{
		    if((uiQuota > 0) && (uiCount >= uiQuota))
				break;

			pcMsgBuf->SetPayloadLen(MAX_PAYLOAD_SIZE);
			
			if(m_pcIn->Get(pcMsgBuf, iType) != 0)
				break;			

			this->Handle(pcMsgBuf->GetType(), pcMsgBuf->GetCmd(), pcMsgBuf->GetData(), pcMsgBuf->GetPayloadLen());

			uiCount++;
		}
			
		usleep(50 * 1000);
    }	
}
Beispiel #2
0
bool init()
{
    if(g_fileName.isEmpty())
    {
        SetLogName(QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch()) + ".log");
    }
    g_init = g_file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
    return g_init;
}
Beispiel #3
0
int main()
{
	SetLogName("helloWorldTest");
//	while(true)
	{
		INFO("info trace ======================================================================++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..");
		WARNING("hello world" << 550 << "dobule=" << 5.6008);
		ERROR("ERROR");
		DEBUG_LOG("This is a debug log");
		CLOG(1, "%s", "this is a c error log");
		usleep(50000);
	}
	return 0;
}