本文整理汇总了C++中mercury::Channel类的典型用法代码示例。如果您正苦于以下问题:C++ Channel类的具体用法?C++ Channel怎么用?C++ Channel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onAppActiveTick
//-------------------------------------------------------------------------------------
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());
}
示例2: onReqCreateAccountResult
//-------------------------------------------------------------------------------------
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);
}
示例3: sendToClient
//-------------------------------------------------------------------------------------
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;
}
示例4: sync
//-------------------------------------------------------------------------------------
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();
}
示例5:
//-------------------------------------------------------------------------------------
Witness::Bundles & Witness::bundles()
{
KBE_ASSERT(pEntity_);
KBE_ASSERT(pEntity_->getClientMailbox());
Mercury::Channel* pChannel = pEntity_->getClientMailbox()->getChannel();
KBE_ASSERT(pChannel);
return pChannel->bundles();
}
示例6: handleChannels
//-------------------------------------------------------------------------------------
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);
}
}
示例7: pBundles
//-------------------------------------------------------------------------------------
Proxy::Bundles* Proxy::pBundles()
{
if(!clientMailbox())
return NULL;
Mercury::Channel* pChannel = clientMailbox()->getChannel();
if(!pChannel)
return NULL;
return &pChannel->bundles();
}
示例8: sync
//-------------------------------------------------------------------------------------
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;
}
示例9: c_str
//-------------------------------------------------------------------------------------
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");
}
示例10: postMail
//-------------------------------------------------------------------------------------
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;
}
示例11: update
//-------------------------------------------------------------------------------------
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();
}
}
示例12: onReqCreateMailAccountResult
//-------------------------------------------------------------------------------------
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);
}
示例13: handleTimeout
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;
}
示例14: onAppActiveTick
//-------------------------------------------------------------------------------------
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());
}
示例15: onDataChanged
//-------------------------------------------------------------------------------------
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);
}
}