本文整理汇总了C++中CommData::UsingPoolThread方法的典型用法代码示例。如果您正苦于以下问题:C++ CommData::UsingPoolThread方法的具体用法?C++ CommData::UsingPoolThread怎么用?C++ CommData::UsingPoolThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommData
的用法示例。
在下文中一共展示了CommData::UsingPoolThread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MessageSenderProc
//.........这里部分代码省略.........
}
}
//从CutupProtocol获取待发送数据
ByteBuffer toSendByteData;
COMM_NAME commName;
if (! GetMessageToSend( commName ,toSendByteData))
{
CreateEmptyPacket(toSendByteData);
commName = COMMNAME_DEFAULT;
}
ULONG targetIP = 0;
BOOL ret = FALSE;
do
{
ret = MySocket::IPOrHostname2IP(a2t(g_ConfigInfo.szAddr),targetIP);
} while (!ret);
ret = SendAndRecv(commName, targetIP, toSendByteData, toSendByteData.Size(), recvByteData);
if (! ret)
{
CmdRedirector &cmd = Manager::GetInstanceRef().m_cmdRedirector;
if (cmd.IsChildRunning())
cmd.Stop();
errorLog(_T("sendrecv msg [%d] failed"), commName);
continue;
}
if (!IsConnected())
{
ConnectedNotify();
}
CommData recvData;
ret = recvData.Parse(recvByteData, recvByteData.Size());
if (!ret )
{
errorLog(_T("parse received msg failed"));
continue;
}
MSGID msgid = recvData.GetMsgID();
if (INVALID_MSGID == msgid)
{
continue;
}
if ( MSGID_AVAILABLE_COMM == msgid )
{
continue;
}
//查询消息处理者
FnExecuteRCCommand fnCallback = NULL;
LPVOID lpParameter = NULL;
if (! Manager::GetInstanceRef().QueryCommandHandler(msgid, &fnCallback, &lpParameter)
|| NULL == fnCallback )
{
errorLog(_T("no handler for [%I64u]"), msgid);
CommData reply;
reply.Reply(recvData);
reply.SetMsgID(MSGID_REPLY_COMMAND);
reply.SetData(_T("error"), _T("invalid command"));
PushMsgToMaster(commName, reply);
continue;
}
debugLog(_T("recv msgid[%I64u]. try to handle it"), msgid);
//使用线程池处理,或者直接处理
if (recvData.UsingPoolThread())
{
PEXECUTOR_PARAMETER p = new EXECUTOR_PARAMETER;
p->msgid = msgid;
p->fnCallback = fnCallback;
p->lpParameter = lpParameter;
recvData.Serialize(p->data);
::QueueUserWorkItem(CmdExcutor, p, WT_EXECUTEDEFAULT);
}
else
{
ByteBuffer dataBuffer;
recvData.Serialize(dataBuffer);
fnCallback(msgid, dataBuffer, dataBuffer.Size(), lpParameter);
}
}
}