//------------------------------------------------------------------------------------- void ServerApp::onAppActiveTick(Mercury::Channel* pChannel, COMPONENT_TYPE componentType, COMPONENT_ID componentID) { if(componentType != CLIENT_TYPE) if(pChannel->isExternal()) return; Mercury::Channel* pTargetChannel = NULL; if(componentType != CONSOLE_TYPE && componentType != CLIENT_TYPE) { Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(componentType, KBEngine::getUserUID(), componentID); if(cinfos == NULL || cinfos->pChannel == NULL) { ERROR_MSG(boost::format("ServerApp::onAppActiveTick[%1%]: %2%:%3% not found.\n") % pChannel % COMPONENT_NAME_EX(componentType) % componentID); return; } pTargetChannel = cinfos->pChannel; pTargetChannel->updateLastReceivedTime(); } else { pChannel->updateLastReceivedTime(); pTargetChannel = pChannel; } //DEBUG_MSG("ServerApp::onAppActiveTick[%x]: %s:%"PRAppID" lastReceivedTime:%"PRIu64" at %s.\n", // pChannel, COMPONENT_NAME_EX(componentType), componentID, pChannel->lastReceivedTime(), pTargetChannel->c_str()); }
//------------------------------------------------------------------------------------- void Loginapp::onReqCreateAccountResult(Mercury::Channel* pChannel, MemoryStream& s) { SERVER_ERROR_CODE failedcode; std::string accountName; std::string password; std::string retdatas = ""; s >> failedcode >> accountName >> password; s.readBlob(retdatas); DEBUG_MSG(boost::format("Loginapp::onReqCreateAccountResult: accountName=%1%, failedcode=%2%.\n") % accountName.c_str() % failedcode); PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName); if(ptinfos == NULL) return; Mercury::Channel* pClientChannel = this->getNetworkInterface().findChannel(ptinfos->addr); if(pClientChannel == NULL) return; pClientChannel->extra(""); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); bundle << failedcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pClientChannel); SAFE_RELEASE(ptinfos); }
//------------------------------------------------------------------------------------- bool Proxy::sendToClient(bool expectData) { if(!clientMailbox()) return false; Mercury::Channel* pChannel = clientMailbox()->getChannel(); if(!pChannel) return false; if(expectData) { if(pChannel->bundles().size() == 0) { WARNING_MSG("Proxy::sendToClient: no data!\n"); return false; } } { // 如果数据大量阻塞发不出去将会报警 AUTO_SCOPED_PROFILE("sendToClient"); pChannel->send(); } return true; }
//------------------------------------------------------------------------------------- void DebugHelper::sync() { lockthread(); if(hasBufferedLogPackets_ == 0) { unlockthread(); return; } if(Mercury::Address::NONE == messagelogAddr_) { if(hasBufferedLogPackets_ > g_kbeSrvConfig.tickMaxBufferedLogs()) { clearBufferedLog(); } canLogFile_ = true; unlockthread(); return; } Mercury::Channel* pMessagelogChannel = pNetworkInterface_->findChannel(messagelogAddr_); if(pMessagelogChannel == NULL) { if(hasBufferedLogPackets_ > g_kbeSrvConfig.tickMaxBufferedLogs()) { clearBufferedLog(); } canLogFile_ = true; unlockthread(); return; } int8 v = Mercury::g_trace_packet; Mercury::g_trace_packet = 0; uint32 i = 0; size_t totalLen = 0; while(!bufferedLogPackets_.empty()) { if(i++ >= g_kbeSrvConfig.tickMaxSyncLogs() || totalLen > (PACKET_MAX_SIZE_TCP * 10)) break; Mercury::Bundle* pBundle = bufferedLogPackets_.front(); bufferedLogPackets_.pop(); totalLen += pBundle->currMsgLength(); pMessagelogChannel->send(pBundle); --hasBufferedLogPackets_; } Mercury::g_trace_packet = v; canLogFile_ = false; unlockthread(); }
//------------------------------------------------------------------------------------- Witness::Bundles & Witness::bundles() { KBE_ASSERT(pEntity_); KBE_ASSERT(pEntity_->getClientMailbox()); Mercury::Channel* pChannel = pEntity_->getClientMailbox()->getChannel(); KBE_ASSERT(pChannel); return pChannel->bundles(); }
//------------------------------------------------------------------------------------- void NetworkInterface::handleChannels(KBEngine::Mercury::MessageHandlers* pMsgHandlers) { ChannelMap::iterator iter = channelMap_.begin(); for(; iter != channelMap_.end(); iter++) { Mercury::Channel* pChannel = iter->second; pChannel->handleMessage(pMsgHandlers); } }
//------------------------------------------------------------------------------------- Proxy::Bundles* Proxy::pBundles() { if(!clientMailbox()) return NULL; Mercury::Channel* pChannel = clientMailbox()->getChannel(); if(!pChannel) return NULL; return &pChannel->bundles(); }
//------------------------------------------------------------------------------------- void DebugHelper::sync() { if(bufferedLogPackets_.size() == 0) return; if(Mercury::Address::NONE == messagelogAddr_) { if(bufferedLogPackets_.size() > g_kbeSrvConfig.tickMaxBufferedLogs()) { clearBufferedLog(); } return; } Mercury::Channel* pMessagelogChannel = pNetworkInterface_->findChannel(messagelogAddr_); if(pMessagelogChannel == NULL) { if(bufferedLogPackets_.size() > g_kbeSrvConfig.tickMaxBufferedLogs()) { clearBufferedLog(); } return; } int8 v = Mercury::g_trace_packet; Mercury::g_trace_packet = 0; uint32 i = 0; size_t totalLen = 0; std::list< Mercury::Bundle* >::iterator iter = bufferedLogPackets_.begin(); for(; iter != bufferedLogPackets_.end();) { if(i++ >= g_kbeSrvConfig.tickMaxSyncLogs() || totalLen > (PACKET_MAX_SIZE_TCP * 10)) break; totalLen += (*iter)->currMsgLength(); pMessagelogChannel->send((*iter)); bufferedLogPackets_.erase(iter++); } Mercury::g_trace_packet = v; }
//------------------------------------------------------------------------------------- void EntityMailbox::c_str(char* s, size_t size) { const char * mailboxName = (type_ == MAILBOX_TYPE_CELL) ? "Cell" : (type_ == MAILBOX_TYPE_BASE) ? "Base" : (type_ == MAILBOX_TYPE_CLIENT) ? "Client" : (type_ == MAILBOX_TYPE_BASE_VIA_CELL) ? "BaseViaCell" : (type_ == MAILBOX_TYPE_CLIENT_VIA_CELL) ? "ClientViaCell" : (type_ == MAILBOX_TYPE_CELL_VIA_BASE) ? "CellViaBase" : (type_ == MAILBOX_TYPE_CLIENT_VIA_BASE) ? "ClientViaBase" : "???"; Mercury::Channel* pChannel = getChannel(); kbe_snprintf(s, size, "%s mailbox id:%d, utype:%u, component=%s[%"PRIu64"], addr: %s.", mailboxName, id_, utype_, COMPONENT_NAME[ENTITY_MAILBOX_COMPONENT_TYPE_MAPPING[type_]], componentID_, (pChannel) ? pChannel->addr().c_str() : "None"); }
//------------------------------------------------------------------------------------- bool EntityMailboxAbstract::postMail(Mercury::Bundle& bundle) { KBE_ASSERT(Components::getSingleton().pNetworkInterface() != NULL); Mercury::Channel* pChannel = getChannel(); if(pChannel && !pChannel->isDead()) { bundle.send(*Components::getSingleton().pNetworkInterface(), pChannel); return true; } else { ERROR_MSG("EntityMailboxAbstract::postMail: invalid channel(%s)!\n", addr_.c_str()); } return false; }
//------------------------------------------------------------------------------------- Proxy::~Proxy() { Baseapp::getSingleton().decProxicesCount(); // 如果被销毁频道仍然存活则将其关闭 Mercury::Channel* pChannel = Baseapp::getSingleton().networkInterface().findChannel(addr_); if(pChannel && !pChannel->isDead()) { Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onKicked); ClientInterface::onKickedArgs1::staticAddToBundle(*pBundle, SERVER_ERR_PROXY_DESTROYED); //pBundle->send(Baseapp::getSingleton().networkInterface(), pChannel); //Mercury::Bundle::ObjPool().reclaimObject(pBundle); this->sendToClient(ClientInterface::onKicked, pBundle); this->sendToClient(); pChannel->condemn(); } SAFE_RELEASE(pProxyForwarder_); }
//------------------------------------------------------------------------------------- void Witness::update() { SCOPED_PROFILE(CLIENT_UPDATE_PROFILE); if(pEntity_ == NULL) return; if(!pEntity_->getClientMailbox()) return; Mercury::Channel* pChannel = pEntity_->getClientMailbox()->getChannel(); if(!pChannel) return; { // 如果数据大量阻塞发不出去将会报警 AUTO_SCOPED_PROFILE("updateClientSend"); pChannel->send(); } }
//------------------------------------------------------------------------------------- void Loginapp::onReqCreateMailAccountResult(Mercury::Channel* pChannel, MemoryStream& s) { SERVER_ERROR_CODE failedcode; std::string accountName; std::string password; std::string retdatas = ""; s >> failedcode >> accountName >> password; s.readBlob(retdatas); DEBUG_MSG(boost::format("Loginapp::onReqCreateMailAccountResult: accountName=%1%, failedcode=%2%.\n") % accountName.c_str() % failedcode); if(failedcode == SERVER_SUCCESS) { threadPool_.addTask(new SendActivateEMailTask(accountName, retdatas, g_kbeSrvConfig.getLoginApp().http_cbhost, g_kbeSrvConfig.getLoginApp().http_cbport)); } PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName); if(ptinfos == NULL) return; Mercury::Channel* pClientChannel = this->getNetworkInterface().findChannel(ptinfos->addr); if(pClientChannel == NULL) return; pClientChannel->extra(""); retdatas = ""; Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); bundle << failedcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pClientChannel); SAFE_RELEASE(ptinfos); }
int ChannelClientApp::handleTimeout( Mercury::TimerID id, void * arg ) { ServerInterface::msg1Args & args = ServerInterface::msg1Args::start( pChannel_->bundle() ); args.traits = pChannel_->traits(); args.seq = outSeq_++; args.data = 0; if (outSeq_ == numToSend_) { ServerInterface::disconnectArgs & args = ServerInterface::disconnectArgs::start( pChannel_->bundle() ); args.seq = outSeq_; this->stopTimer(); pChannel_->isIrregular( true ); } pChannel_->send(); return 0; }
//------------------------------------------------------------------------------------- void ServerApp::onAppActiveTick(Mercury::Channel* pChannel, COMPONENT_TYPE componentType, COMPONENT_ID componentID) { if(pChannel->isExternal()) return; Mercury::Channel* pTargetChannel = NULL; if(componentType != CONSOLE_TYPE) { Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent(componentType, KBEngine::getUserUID(), componentID); KBE_ASSERT(cinfos != NULL); pTargetChannel = cinfos->pChannel; pTargetChannel->updateLastReceivedTime(); } else { pChannel->updateLastReceivedTime(); pTargetChannel = pChannel; } DEBUG_MSG("ServerApp::onAppActiveTick[%x]: %s:%"PRAppID" lastReceivedTime:%"PRIu64" at %s.\n", pChannel, COMPONENT_NAME[componentType], componentID, pChannel->lastReceivedTime(), pTargetChannel->c_str()); }
//------------------------------------------------------------------------------------- void GlobalDataClient::onDataChanged(std::string& key, std::string& value, bool isDelete) { Components::COMPONENTS& channels = Components::getSingleton().getComponents(serverComponentType_); Components::COMPONENTS::iterator iter1 = channels.begin(); uint8 dataType = dataType_; ArraySize slen = 0; for(; iter1 != channels.end(); iter1++) { Mercury::Channel* lpChannel = iter1->pChannel; KBE_ASSERT(lpChannel != NULL); Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(DbmgrInterface::onBroadcastGlobalDataChange); (*pBundle) << dataType; (*pBundle) << isDelete; slen = key.size(); (*pBundle) << slen; (*pBundle).assign(key.data(), slen); if(!isDelete) { slen = value.size(); (*pBundle) << slen; (*pBundle).assign(value.data(), slen); } (*pBundle) << g_componentType; (*pBundle).send(*lpChannel->endpoint()); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } }
//------------------------------------------------------------------------------------- void GlobalDataServer::broadcastDataChange(Mercury::Channel* pChannel, COMPONENT_TYPE componentType, const std::string& key, const std::string& value, bool isDelete) { INFO_MSG(boost::format("GlobalDataServer::broadcastDataChange: writer(%1%), key_size=%2%, val_size=%3%, isdelete=%4%.\n") % COMPONENT_NAME_EX(componentType) % key.size() % value.size() % (int)isDelete); std::vector<COMPONENT_TYPE>::iterator iter = concernComponentTypes_.begin(); for(; iter != concernComponentTypes_.end(); iter++) { COMPONENT_TYPE ct = (*iter); Components::COMPONENTS& channels = Components::getSingleton().getComponents(ct); Components::COMPONENTS::iterator iter1 = channels.begin(); for(; iter1 != channels.end(); iter1++) { Mercury::Channel* lpChannel = iter1->pChannel; KBE_ASSERT(lpChannel != NULL); if(pChannel == lpChannel) continue; Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); switch(dataType_) { case GLOBAL_DATA: if(componentType == CELLAPP_TYPE) { (*pBundle).newMessage(CellappInterface::onBroadcastGlobalDataChange); } else if(componentType == BASEAPP_TYPE) { (*pBundle).newMessage(BaseappInterface::onBroadcastGlobalDataChange); } else { KBE_ASSERT(false && "componentType is error!\n"); } break; case GLOBAL_BASES: (*pBundle).newMessage(BaseappInterface::onBroadcastGlobalBasesChange); break; case CELLAPP_DATA: (*pBundle).newMessage(CellappInterface::onBroadcastCellAppDataChange); break; default: KBE_ASSERT(false && "dataType is error!\n"); break; }; (*pBundle) << isDelete; ArraySize slen = key.size(); (*pBundle) << slen; (*pBundle).assign(key.data(), slen); if(!isDelete) { slen = value.size(); (*pBundle) << slen; (*pBundle).assign(value.data(), slen); } (*pBundle).send(*lpChannel->endpoint()); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } } }
//------------------------------------------------------------------------------------- bool RestoreEntityHandler::process() { Components::COMPONENTS& cts = Components::getSingleton().getComponents(CELLAPP_TYPE); Mercury::Channel* pChannel = NULL; if(cts.size() > 0) { Components::COMPONENTS::iterator ctiter = cts.begin(); if((*ctiter).pChannel == NULL) return true; pChannel = (*ctiter).pChannel; } if(pChannel == NULL) return true; int count = 0; // 首先需要找到这个cell上的space // KBE_ASSERT(restoreSpaces_.size() > 0); // 如果spaceEntity不在这个baseapp上创建则继续等待 // 当spaceEntity的cell创建好了之后会广播给所有的baseapp, 每个baseapp // 去判断是否有需要恢复的entity if(restoreSpaces_.size() > 0) { if(timestamp() - tickReport_ > uint64( 3 * stampsPerSecond() )) { tickReport_ = timestamp(); INFO_MSG(boost::format("RestoreEntityHandler::process(%3%): wait for localSpace to get cell!, entitiesSize(%1%), spaceSize=%2%\n") % entities_.size() % restoreSpaces_.size() % cellappID_); } int spaceCellCount = 0; // 必须等待space恢复 std::vector<RestoreData>::iterator restoreSpacesIter = restoreSpaces_.begin(); for(; restoreSpacesIter != restoreSpaces_.end(); restoreSpacesIter++) { Base* pBase = Baseapp::getSingleton().findEntity((*restoreSpacesIter).id); if(pBase) { if(++count > (int)g_kbeSrvConfig.getBaseApp().entityRestoreSize) { return true; } if((*restoreSpacesIter).creatingCell == false) { (*restoreSpacesIter).creatingCell = true; pBase->restoreCell(NULL); } else { if(pBase->cellMailbox() == NULL) { return true; } else { spaceCellCount++; if(!(*restoreSpacesIter).processed) { (*restoreSpacesIter).processed = true; pBase->onRestore(); } } } } else { ERROR_MSG(boost::format("RestoreEntityHandler::process(%1%): lose space(%2%).\n") % cellappID_ % (*restoreSpacesIter).id); } } if(spaceCellCount != (int)restoreSpaces_.size()) return true; // 通知其他baseapp, space恢复了cell if(!broadcastOtherBaseapps_) { broadcastOtherBaseapps_ = true; INFO_MSG(boost::format("RestoreEntityHandler::process(%1%): begin broadcast-spaceGetCell to otherBaseapps...\n") % cellappID_); std::vector<RestoreData>::iterator restoreSpacesIter = restoreSpaces_.begin(); for(; restoreSpacesIter != restoreSpaces_.end(); restoreSpacesIter++) { Base* pBase = Baseapp::getSingleton().findEntity((*restoreSpacesIter).id); bool destroyed = (pBase == NULL || pBase->isDestroyed()); COMPONENT_ID baseappID = g_componentID; COMPONENT_ID cellappID = 0; SPACE_ID spaceID = (*restoreSpacesIter).spaceID; ENTITY_ID spaceEntityID = (*restoreSpacesIter).id; ENTITY_SCRIPT_UID utype = 0; if(!destroyed) { utype = pBase->scriptModule()->getUType(); cellappID = pBase->cellMailbox()->componentID(); } spaceIDs_.erase(std::remove(spaceIDs_.begin(), spaceIDs_.end(), spaceID), spaceIDs_.end()); Mercury::Channel* pChannel = NULL; Components::COMPONENTS& cts = Componentbridge::getComponents().getComponents(BASEAPP_TYPE); Components::COMPONENTS::iterator comsiter = cts.begin(); for(; comsiter != cts.end(); comsiter++) { pChannel = (*comsiter).pChannel; if(pChannel) { INFO_MSG(boost::format("RestoreEntityHandler::process(%5%): broadcast baseapp[%1%, %2%], spaceID[%3%], utype[%4%]...\n") % (*comsiter).cid % pChannel->c_str() % spaceID % utype % cellappID_); Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(BaseappInterface::onRestoreSpaceCellFromOtherBaseapp); (*pBundle) << baseappID << cellappID << spaceID << spaceEntityID << utype << destroyed; pBundle->send(Baseapp::getSingleton().getNetworkInterface(), pChannel); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } } } } } if(spaceIDs_.size() > 0) { if(timestamp() - tickReport_ > uint64( 3 * stampsPerSecond() )) { tickReport_ = timestamp(); INFO_MSG(boost::format("RestoreEntityHandler::process(%1%): wait for otherBaseappSpaces to get cell!, entitiesSize(%2%), spaceSize=%3%\n") % cellappID_ % entities_.size() % spaceIDs_.size()); } return true; } // 恢复其他entity std::vector<RestoreData>::iterator iter = entities_.begin(); for(; iter != entities_.end(); ) { RestoreData& data = (*iter); Base* pBase = Baseapp::getSingleton().findEntity(data.id); if(pBase) { if(++count > g_kbeSrvConfig.getBaseApp().entityRestoreSize) { return true; } if(pBase->cellMailbox() != NULL) { if(!data.processed) { data.processed = true; pBase->onRestore(); } iter = entities_.erase(iter); } else { if(!data.creatingCell) { data.creatingCell = true; EntityMailboxAbstract* cellMailbox = NULL; std::vector<RestoreData>::iterator restoreSpacesIter = restoreSpaces_.begin(); for(; restoreSpacesIter != restoreSpaces_.end(); restoreSpacesIter++) { Base* pSpace = Baseapp::getSingleton().findEntity((*restoreSpacesIter).id); if(pSpace && pBase->spaceID() == pSpace->spaceID()) { cellMailbox = pSpace->cellMailbox(); break; } } if(cellMailbox == NULL) { restoreSpacesIter = otherRestoredSpaces_.begin(); for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++) { if(pBase->spaceID() == (*restoreSpacesIter).spaceID && (*restoreSpacesIter).cell) { cellMailbox = (*restoreSpacesIter).cell; break; } } } if(cellMailbox) { pBase->restoreCell(cellMailbox); } else { ENTITY_ID delID = pBase->id(); pBase->destroy(); WARNING_MSG(boost::format("RestoreEntityHandler::process(%1%): not fount spaceCell, killed base(%2%)!") % cellappID_ % delID); if(Baseapp::getSingleton().findEntity(delID) == NULL) iter = entities_.erase(iter); continue; } } iter++; } } else { iter = entities_.erase(iter); } } if(entities_.size() == 0) { std::vector<RestoreData>::iterator restoreSpacesIter = otherRestoredSpaces_.begin(); for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++) { if((*restoreSpacesIter).cell) { Py_DECREF((*restoreSpacesIter).cell); (*restoreSpacesIter).cell = NULL; } } otherRestoredSpaces_.clear(); inProcess_ = false; Baseapp::getSingleton().onRestoreEntitiesOver(this); return false; } return true; }
//------------------------------------------------------------------------------------- void Loginapp::onReqCreateMailAccountResult(Mercury::Channel* pChannel, MemoryStream& s) { SERVER_ERROR_CODE failedcode; std::string accountName; std::string password; std::string retdatas = ""; s >> failedcode >> accountName >> password; s.readBlob(retdatas); DEBUG_MSG(boost::format("Loginapp::onReqCreateMailAccountResult: accountName=%1%, failedcode=%2%.\n") % accountName.c_str() % failedcode); if(failedcode == SERVER_SUCCESS) { Components::COMPONENTS& loginapps = Components::getSingleton().getComponents(LOGINAPP_TYPE); std::string http_host = "localhost"; if(startGroupOrder_ == 1) { if(strlen((const char*)&g_kbeSrvConfig.getLoginApp().externalAddress) > 0) http_host = g_kbeSrvConfig.getBaseApp().externalAddress; else http_host = inet_ntoa((struct in_addr&)Loginapp::getSingleton().getNetworkInterface().extaddr().ip); } else { Components::COMPONENTS::iterator iter = loginapps.begin(); for(; iter != loginapps.end(); iter++) { if((*iter).groupOrderid == 1) { if(strlen((const char*)&(*iter).externalAddressEx) > 0) http_host = (*iter).externalAddressEx; else http_host = inet_ntoa((struct in_addr&)(*iter).pExtAddr->ip); } } } threadPool_.addTask(new SendActivateEMailTask(accountName, retdatas, http_host, g_kbeSrvConfig.getLoginApp().http_cbport)); } PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.remove(accountName); if(ptinfos == NULL) return; Mercury::Channel* pClientChannel = this->getNetworkInterface().findChannel(ptinfos->addr); if(pClientChannel == NULL) return; pClientChannel->extra(""); retdatas = ""; Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); bundle << failedcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pClientChannel); SAFE_RELEASE(ptinfos); }
//------------------------------------------------------------------------------------- void DebugHelper::sync() { if(bufferedLogPackets_.size() == 0) return; if(messagelogAddr_.isNone()) { if(bufferedLogPackets_.size() > 128) { ERROR_MSG("DebugHelper::sync: can't found messagelog. packet size=%u.\n", bufferedLogPackets_.size()); clearBufferedLog(); } return; } int8 v = Mercury::g_trace_packet; Mercury::g_trace_packet = 0; Mercury::Channel* pChannel = pNetworkInterface_->findChannel(messagelogAddr_); if(pChannel == NULL) { if(bufferedLogPackets_.size() > 1024) { messagelogAddr_.ip = 0; messagelogAddr_.port = 0; WARNING_MSG("DebugHelper::sync: is no use the messagelog, packet size=%u.\n", bufferedLogPackets_.size()); clearBufferedLog(); } Mercury::g_trace_packet = v; return; } if(bufferedLogPackets_.size() > 0) { if(bufferedLogPackets_.size() > 32) { WARNING_MSG("DebugHelper::sync: packet size=%u.\n", bufferedLogPackets_.size()); } int i = 0; size_t totalLen = 0; std::list< Mercury::Bundle* >::iterator iter = bufferedLogPackets_.begin(); for(; iter != bufferedLogPackets_.end();) { if(i++ >= 32 || totalLen > (PACKET_MAX_SIZE_TCP * 10)) break; totalLen += (*iter)->currMsgLength(); pChannel->send((*iter)); Mercury::Bundle::ObjPool().reclaimObject((*iter)); bufferedLogPackets_.erase(iter++); } } Mercury::g_trace_packet = v; }