本文整理汇总了C++中CwxMsgBlock::length方法的典型用法代码示例。如果您正苦于以下问题:C++ CwxMsgBlock::length方法的具体用法?C++ CwxMsgBlock::length怎么用?C++ CwxMsgBlock::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CwxMsgBlock
的用法示例。
在下文中一共展示了CwxMsgBlock::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Echo
void CwxEchoThriftIf::Echo(echo_thrift::EchoData& _return, const std::string& echo_data) {
EchoTss* tss = (EchoTss*)CwxTss::instance();
CwxMsgBlock* msg = CwxMsgBlockAlloc::malloc(echo_data.length());
memcpy(msg->wr_ptr(), echo_data.c_str(), echo_data.length());
msg->wr_ptr(echo_data.length());
msg->event().setSvrId(CwxEchoApp::SVR_TYPE_ECHO);
msg->event().setEvent(CwxEventInfo::RECV_MSG);
msg->event().setConnUserData(&tss->m_queue);
tss->m_curId++;
msg->event().m_ullArg = tss->m_curId;
m_app->GetThreadPool()->append(msg);
while(true) {
if (tss->m_queue.dequeue(msg) != -1) {
if (msg->event().m_ullArg == tss->m_curId) {
_return.data.assign(msg->rd_ptr(), msg->length());
CwxMsgBlockAlloc::free(msg);
return;
}
CwxMsgBlockAlloc::free(msg);
} else {
_return.data = "";
}
}
}
示例2: main
int main(int argc, char** argv) {
int iRet = parseArg(argc, argv);
if (0 == iRet) return 0;
if (-1 == iRet) return 1;
CwxSockStream stream;
CwxINetAddr addr(g_unPort, g_strHost.c_str());
CwxSockConnector conn;
if (0 != conn.connect(stream, addr)) {
printf("failure to connect ip:port: %s:%u, errno=%d\n", g_strHost.c_str(),
g_unPort, errno);
return 1;
}
CwxPackageWriter writer;
CwxPackageReader reader;
CwxMsgHead head;
CwxMsgBlock* block = NULL;
char szErr2K[2048];
char const* pErrMsg = NULL;
CwxKeyValueItem item;
if (g_file.length()) {
item.m_szData = g_szData;
item.m_uiDataLen = g_uiDataLen;
} else {
item.m_szData = (char*) g_data.c_str();
item.m_uiDataLen = g_data.length();
}
do {
if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::packRecvData(&writer,
block,
0,
item,
g_user.c_str(),
g_passwd.c_str(),
g_zip,
szErr2K))
{
printf("failure to pack message package, err=%s\n", szErr2K);
iRet = 1;
break;
}
if (block->length() != (CWX_UINT32) CwxSocket::write_n(stream.getHandle(), block->rd_ptr(),
block->length()))
{
printf("failure to send message, errno=%d\n", errno);
iRet = 1;
break;
}
CwxMsgBlockAlloc::free(block);
block = NULL;
//recv msg
if (0 >= CwxSocket::read(stream.getHandle(), head, block)) {
printf("failure to read the reply, errno=%d\n", errno);
iRet = 1;
break;
}
if (CwxMqPoco::MSG_TYPE_RECV_DATA_REPLY != head.getMsgType()) {
printf("recv a unknow msg type, msg_type=%u\n", head.getMsgType());
iRet = 1;
break;
}
CWX_UINT64 ullSid;
if (CWX_MQ_ERR_SUCCESS != CwxMqPoco::parseRecvDataReply(&reader,
block,
iRet,
ullSid,
pErrMsg,
szErr2K))
{
printf("failure to unpack reply msg, err=%s\n", szErr2K);
iRet = 1;
break;
}
if (CWX_MQ_ERR_SUCCESS != iRet) {
printf("failure to send message, err_code=%d, err=%s\n", iRet, pErrMsg);
iRet = 1;
break;
}
iRet = 0;
printf("success to send msg, data's sid=%s\n",
CwxCommon::toString(ullSid, szErr2K, 10));
} while (0);
if (g_szData) free(g_szData);
if (block) CwxMsgBlockAlloc::free(block);
stream.close();
return iRet;
}