BOOL CAPNSClient::ReConnectFeedback() { BOOL bRet = FALSE; StopFeedBackClient(); if (m_pFeedbackClient) { PUSH_SERVER_INFO("feedback client begin to reconnect..."); m_pFeedbackClient->ReConnectAsync(); StopReConnectFeedback(); StartCheckConnectFeedback(); } return bRet; }
BOOL CAPNSClient::ReConnectGateway() { BOOL bRet = FALSE; StopGateWayClient(); if (m_pGatewayClient) { _GetAPNSServerAddress(); PUSH_SERVER_INFO("gateway client begin to reconnect..."); m_pGatewayClient->SetRemoteIP(GetGatewayIP().c_str()); m_pGatewayClient->SetRemotePort(GetGatewayPort()); m_pFeedbackClient->SetRemoteIP(GetFeedbackIP().c_str()); m_pFeedbackClient->SetRemotePort(GetFeedbackPort()); m_pGatewayClient->ReConnectAsync(); StopReConnectGateway(); StartCheckConnectGateway(); bRet = TRUE; } return bRet; }
void CPushSessionHandler::_HandlePushMsg(const char* szBuf, int32_t nBufSize) { CPduMsg pdu_msg; if (!pdu_msg.ParseFromArray(szBuf, nBufSize)) { PUSH_SERVER_ERROR("HandlePushMsg, msg parse failed."); return; } push_session_ptr pSession = CSessionManager::GetInstance()->GetPushSessionBySockID(_GetSockID()); if (pSession == nullptr) { return; } pSession->SetHeartBeat(S_GetTickCount()); IM::Server::IMPushToUserReq msg; if (!msg.ParseFromArray(pdu_msg.Body(), pdu_msg.GetBodyLength())) { PUSH_SERVER_ERROR("HandlePushMsg, msg parse failed."); pSession->Stop(); return; } string strFlash = msg.flash(); string strUserData = msg.data(); apns_client_ptr pClient = CSessionManager::GetInstance()->GetAPNSClient(); if (pClient) { IM::Server::IMPushToUserRsp msg2; for (uint32_t i = 0; i < msg.user_token_list_size(); i++) { IM::BaseDefine::PushResult* push_result = msg2.add_push_result_list(); IM::BaseDefine::UserTokenInfo user_token = msg.user_token_list(i); if (user_token.user_type() != IM::BaseDefine::CLIENT_TYPE_IOS) { push_result->set_user_token(user_token.token()); push_result->set_result_code(1); continue; } m_NotificationID++; PUSH_SERVER_INFO("HandlePushMsg, token: %s, push count: %d, push_type:%d, notification id: %u.", user_token.token().c_str(), user_token.push_count(), user_token.push_type(), m_NotificationID); CAPNSGateWayMsg msg; msg.SetAlterBody(strFlash); msg.SetCustomData(strUserData); msg.SetDeviceToken(user_token.token()); time_t time_now = 0; time(&time_now); msg.SetExpirationDate(time_now + 3600); if (user_token.push_type() == PUSH_TYPE_NORMAL) { msg.SetSound(TRUE); } else { msg.SetSound(FALSE); } msg.SetBadge(user_token.push_count()); msg.SetNotificationID(m_NotificationID); if (msg.SerializeToArray()) { pClient->SendPushMsgToGateway(msg.Data(), msg.GetDataLength()); push_result->set_result_code(0); } else { push_result->set_result_code(1); PUSH_SERVER_WARN("HandlePushMsg, serialize CAPNSGateWayMsg failed."); } push_result->set_user_token(user_token.token()); } CPduMsg pdu_msg2; pdu_msg2.SetServiceID(IM::BaseDefine::SID_OTHER); pdu_msg2.SetCommandID(IM::BaseDefine::CID_OTHER_PUSH_TO_USER_RSP); if (pdu_msg2.SerializeToArray(&msg2)) { pSession->SendMsg(pdu_msg2.Data(), pdu_msg2.GetDataLength()); } else { PUSH_SERVER_WARN("HandlePushMsg, serialize IMPushToUserRsp failed."); } } }