int testsignal() { int i; signal = net_signal_create(); nthread_create(read,NULL); nthread_create(write,NULL); system("pause"); return 0 ; }
// * ================================================================================ * // @ main // * ================================================================================ * int main(int argc, char ** argv) { //open the log file pLogFile = &CCLogFile; CCLogFile.startlog(1); CCLogFile.SetLogSize(2*1000*1000); CCLogFile.SetLoglevel(1); CCLogFile.logopen(); if ( myconfig.readfile(CONFIG_FILE_PATH) == 0 ) { printf("appserver: read config file '%s' error\n", CONFIG_FILE_PATH); LOG(LOG1, "appserver: read config file '%s' error\n", CONFIG_FILE_PATH); sleep(2); exit(0); } CCLogFile.SetLoglevel(ToInt(myconfig["LogLevel"][1])); //TANG 2010-9-4 11:02 //处理命令行参数 if ( argc == 3 && strcmp(argv[1], "reload") == 0 && strcmp(argv[2], "config") == 0 ) { send_msg_reload_config("127.0.0.1", (( ToInt(myconfig["AppServerListenPort"][1]) > 0 ) ? ToInt(myconfig["AppServerListenPort"][1]) : 4016)); exit(0); } LOG(LOG1, "appserver: start\n"); child_process_init(SN3_SERVICE_NUMBER); //application_envinit(); //LOG(LOG1, "appserver: application_envinit() done\n"); _appserver_initial(); LOG(LOG1, "appserver: _appserver_initial() done\n"); nthread_create(thread_sockserver, NULL, 64*1024); nthread_create(thread_procdata_sendsmsg, NULL, 64*1024); tcp_server1.SetpLog(&CCLogFile); tcp_server1.SetCallBackFunc(deal_client_msg); if ( ToInt(myconfig["AppServerListenPort"][1]) > 0 ) { tcp_server1.Listen(ToInt(myconfig["AppServerListenPort"][1]), 180); } else { tcp_server1.Listen(4016, 180); } //NPOSITION pos; //rundata_realtest* p_runtest; string s_terminal, s_msg_type; time_t t_check_hb_timeout = time(NULL); time_t t_check_test_timeout = time(NULL); while(g_appserver.m_runing) { child_process_hb(SN3_SERVICE_NUMBER); /* pos = NULL; while(NULL != (p_runtest = realtest_next(pos))) { if ( time(NULL) >= p_runtest->tm_end ) { CClientMsg::ansy_getitem(p_runtest->s_testdata.c_str(), "terminal", s_terminal); CClientMsg::ansy_getitem(p_runtest->s_testdata.c_str(), "msg", s_msg_type); //PESQ的实时测试,ftp扫描单元可能直接修改数据库的测试结果为X CNString sql; sql.Format("select * from BUSSOP where BUSSOP_ID = '%s' and (STATUS != 'X' and STATUS != 'Y');", p_runtest->s_bussopid.c_str()); DATASET dbresult; if ( DB1.db_select(sql.c_str(), dbresult, LOG6) > 0 ) { LOG(LOG1, "测试超时 [%s] '%c', s_bussopid='%s', timeout=%ds\n\n", s_terminal.c_str(), p_runtest->u_buss, p_runtest->s_bussopid.c_str(), p_runtest->tm_end - p_runtest->tm_start ); int i_rescode = 1; if ( dbresult[0]["STATUS"] == "W" ) i_rescode = 5001; appserver_dbupdate_bussop_error(p_runtest->s_bussopid.c_str(), i_rescode); } t_uchar u_buss = p_runtest->u_buss; p_runtest = realtest_next(pos); realtest_delete(s_terminal.c_str(), u_buss); } } */ n_sleep(1000); if ( time(NULL) >= t_check_hb_timeout + 10*60 ) { CNString sql; sql.Format("select * from CONFIG_TERMINAL where TERMINAL_STATE = 0 and HEARTBEAT_STATE = 0 and %u >= T_RECV_HEARTBEAT + %d;", time(NULL), ToInt(myconfig["SMS_HEARTBEAT_TIMEOUT"][1])); DATASET dbresult; if ( DB1.db_select(sql.c_str(), dbresult, LOG6) > 0 ) { //某终端心跳短信超时 for ( int i=0; i<dbresult.size(); i++ ) { string s_terminal = dbresult[i]["TERMINAL_ID"]; string s_bussopid; string s_starttime = time_format_str(time(NULL), 1); _ori_bussopid(s_bussopid, BUSSOPTYPE_ROUTINE, s_terminal.c_str(), "IA", s_starttime.c_str()); appserver_dbinsert_bussop(s_bussopid.c_str(), BUSSOPTYPE_ROUTINE, "IA", s_terminal.c_str(), s_starttime.c_str(), "", 'X'); insert_bussop_exception_result(s_bussopid.c_str(), "HEARTBEAT_TMOUT"); update_terminal_heartbeat_timeout(s_terminal.c_str()); } } t_check_hb_timeout = time(NULL); } if ( time(NULL) >= t_check_test_timeout + 60 ) { DATASET dbresult; CNString sql; sql.Format("SELECT * from BUSSOP where (STATUS != 'X' and STATUS != 'Y') and INIVATE_TYPE = 'T' and '%s' >= TIMEOUT order by STARTTIME;", time_format_str(time(NULL), 1).c_str()); if ( DB1.db_select(sql.c_str(), dbresult, LOG6) > 0 ) { //测试超时 for ( int i=0; i<dbresult.size(); i++ ) { LOG(LOG1, "DB 测试超时 terminal='%s', KQI='%s', s_bussopid='%s', tid='%s', timeout=%ds\n\n", dbresult[i]["TERMINAL_ID"].c_str(), dbresult[i]["KQI_TYPE"].c_str(), dbresult[i]["BUSSOP_ID"].c_str(), dbresult[i]["TID"].c_str(), time_string_to_time_t(dbresult[i]["TIMEOUT"]) - time_string_to_time_t(dbresult[i]["STARTTIME"]) ); int i_rescode = 1; if ( dbresult[i]["STATUS"] == "W" ) i_rescode = 5001; appserver_dbupdate_bussop_error(dbresult[i]["BUSSOP_ID"].c_str(), i_rescode); } } t_check_test_timeout = time(NULL); } } _appserver_destroy(); tcp_server1.Close(); LOG(LOG1, "appserver: exit\n"); return 0; }