int IBCOperBase::process(QModeMsg& req, char* ack, int& ack_len) { ACE_DEBUG((LM_DEBUG, "[%D] IBCOperBase start to process msg\n")); snprintf(ack, ack_len, "%s|", (*(req.get_map()))["info"].c_str()); return 0; }
int IsgwOperBase::is_auth(QModeMsg& req, char* ack, int& ack_len) { if (1 == cmd_auth_flag_) { if (cmd_auth_map_[req.get_cmd()] != 1) { ACE_DEBUG((LM_ERROR, "[%D] IsgwOperBase auth failed" ",cmd %d not allowed\n" , req.get_cmd() )); snprintf(ack, ack_len-1,"info=invalid cmd %d", req.get_cmd()); return -1; } } if (1 == svc_auth_flag_) { int iSvc = atoi(((*(req.get_map()))[FIELD_NAME_SVC]).c_str()); if (svc_auth_map_[iSvc] != 1) { ACE_DEBUG((LM_ERROR, "[%D] IsgwOperBase auth failed" ",svc %d not allowed\n" , iSvc )); snprintf(ack, ack_len-1,"info=invalid service %d", iSvc); return -1; } } return 0; }
// 测试异步连接管理器 int TempProxy::test(QModeMsg &req) { unsigned int uin = req.get_uin(); char req_buf[1024]; memset(req_buf, 0, sizeof(req_buf)); // 告知本进程接收到后端的返回消息是否要进行加工处理还是直接透传 int rflag = atoi((*(req.get_map()))["rflag"].c_str()); int timeout = atoi((*(req.get_map()))["timeout"].c_str()); if (timeout <= 0) { timeout = 1; } PlatConnMgrAsy* conn_mgr = get_conmgr(); if (NULL == conn_mgr) { ACE_DEBUG((LM_ERROR, "[%D] TempProxy test failed" ",conn mgr is null" ",uin=%u\n" , uin )); return -1; } //需要把消息的唯一标识 传给后端,不然无法区分回来的消息 snprintf(req_buf, sizeof(req_buf)-1 , "_sockfd=%d&_sock_seq=%d&_msg_seq=%d&_prot=%d&_time=%d&_rflag=%d&cmd=%d&uin=%u\n" , req.get_handle() , req.get_sock_seq() , req.get_msg_seq() , req.get_prot() , req.get_time() , rflag, 103, uin); // 如果需要,设置回调相关的信息 ASYRMsg rmsg; rmsg.key.sock_fd = req.get_handle(); rmsg.key.sock_seq = req.get_sock_seq(); rmsg.key.msg_seq = req.get_msg_seq(); //在init的时候设置, 不需要每次调用都设置,除非回调函数有变化 //rmsg.value.asy_proc = &TempProxy::cb_test; //content 可以保存此消息相关的上下文,业务字段等 rmsg.value.content="test content string info"; ACE_DEBUG((LM_DEBUG, "[%D] TempProxy test,uin=%u,req_buf=%s\n", uin, req_buf)); //调用有回调参数的发送接口(针对每个消息指定回调信息) int ret = conn_mgr->send(req_buf, strlen(req_buf), rmsg); if (ret == -1) //-1才为失败 { ACE_DEBUG((LM_ERROR, "[%D] TempProxy test send failed" ",uin=%u" ",req=%s\n" , uin , req_buf )); return -1; } ACE_DEBUG((LM_INFO, "[%D] TempProxy test send succ" ",uin=%u" ",req_buf=%s" "\n" , uin , req_buf )); return 0; }
int IsgwOperBase::internal_process(QModeMsg& req, char* ack, int& ack_len) { int ret =0; switch(req.get_cmd()) { //框架测试指令1 case CMD_TEST: { ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase start to process CMD_TEST\n")); //调用业务处理逻辑类的相关接口处理请求 #ifdef ISGW_USE_IBC int max = 100; for(int i=0; i<max; i++) { char msg[100]=""; snprintf(msg, sizeof(msg) , "cmd=%d&uin=%u&total=%d&info=%d test|" , req.get_cmd() , req.get_uin() , max , i ); QModeMsg *new_req = new QModeMsg(msg, req.get_handle() , req.get_sock_seq(), req.get_msg_seq(), req.get_prot() , req.get_time(), req.get_sock_ip()); if (IBCMgrSvc::instance()->putq(new_req) == -1) { //入队失败回收消息,避免内存泄漏 delete new_req; new_req = NULL; } } //此处不返回消息 ack_len = -1; #else //memset(ack,'@',ack_len); snprintf(ack, ack_len-1, "%s", "info=in test process in test process in test process in test process in test process in test process"); ack_len = atoi((*(req.get_map()))["ack_len"].c_str()); #endif //测试用 awayfang //sleep(100); ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase process CMD_TEST succ\n")); } break; case CMD_SELF_TEST: { QMSG_MAP& req_map = *req.get_map(); int testlevel = 0; if(req_map.count("testlevel")) { testlevel = atoi(req_map["testlevel"].c_str()); } int overproctime = 0; std::string errmsg; struct timeval start, end; ::gettimeofday(&start, NULL); ret = self_test(testlevel, errmsg); ::gettimeofday(&end, NULL); unsigned diff = EASY_UTIL::get_span(&start, &end); int self_test_time_threshold = 500; SysConf::instance()->get_conf_int("system", "self_test_time_threshold", &self_test_time_threshold); overproctime = static_cast<int>(diff) - self_test_time_threshold; // ret值不为0, overproctime>0均引起告警 snprintf(ack, MAX_INNER_MSG_LEN, "overproctime=%d&errmsg=%s", overproctime, errmsg.c_str()); return ret; } break; case CMD_GET_SERVER_VERSION: { snprintf(ack, MAX_INNER_MSG_LEN, "ver=%s", SERVER_VERSION); return ret; } break; case CMD_SYS_LOAD_CONF: ISGWSighdl::instance()->handle_signal(SIGUSR1); break; case CMD_SYS_GET_CONTRL_STAT: { ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase start to process CMD_SYS_GET_CONTRL_STAT\n")); int cmd_no = atoi((*(req.get_map()))["cmd_no"].c_str()); ISGWMgrSvc::freq_obj_->get_statiscs(cmd_no, ack, ack_len); } break; case CMD_SYS_SET_CONTRL_STAT: { int cmd_no = atoi((*(req.get_map()))["cmd_no"].c_str()); int status = atoi((*(req.get_map()))["status"].c_str()); ISGWMgrSvc::freq_obj_->set_status(cmd_no, status); snprintf(ack, ack_len, "info=succ"); } break; case CMD_SYS_SET_CONTRL_SWITCH: { //运行时设置流量控制功能的开关 //0 关闭,1打开,2只查询开关状态 int flag = atoi((*(req.get_map()))["switch"].c_str()); if(0==flag) { ISGWMgrSvc::control_flag_ = 0; } else if(1==flag) { ISGWMgrSvc::control_flag_ = 1; } snprintf(ack, ack_len, "switch=%d&info=succ", ISGWMgrSvc::control_flag_); } break; } return 0; }