当前位置: 首页>>代码示例>>C++>>正文


C++ CwxMsgBlock类代码示例

本文整理汇总了C++中CwxMsgBlock的典型用法代码示例。如果您正苦于以下问题:C++ CwxMsgBlock类的具体用法?C++ CwxMsgBlock怎么用?C++ CwxMsgBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CwxMsgBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: syncSendBinLog

/**
@brief Handler的redo事件,在每次dispatch时执行。
@return -1:处理失败,会调用close(); 0:处理成功
*/
int CwxMqInnerDispHandler::onRedo() {
  ///发送下一条binlog
  int iState = syncSendBinLog(m_tss);
  if (-1 == iState) {
    CWX_ERROR(("%s, from:%s:%u", m_tss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
    CwxMsgBlock* msg = NULL;
    if (CWX_MQ_ERR_ERROR != CwxMqPoco::packSyncErr(m_tss->m_pWriter,
      msg,
      m_header.getTaskId(),
      CWX_MQ_ERR_ERROR,
      m_tss->m_szBuf2K,
      m_tss->m_szBuf2K))
    {
      CWX_ERROR(("Failure to pack sync data reply, err=%s, from:%s:%u", m_tss->m_szBuf2K, m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
    msg->send_ctrl().setMsgAttr(CwxMsgSendCtrl::CLOSE_NOTICE);
    if (!putMsg(msg)) {
      CwxMsgBlockAlloc::free(msg);
      CWX_ERROR(("Failure push msg to send queue. from:%s:%u", m_strPeerHost.c_str(), m_unPeerPort));
      return -1;
    }
  } else if (0 == iState) { ///产生continue的消息
    channel()->regRedoHander(this);
  }
  return 0;
}
开发者ID:azureplus,项目名称:flatq,代码行数:31,代码来源:CwxMqInnerDispHandler.cpp

示例2: channel

int UnistorHandler4Trans::open (void * arg){
    m_bAuth = false;
    int ret = CwxAppHandler4Channel::open(arg);
    if (0 == ret){
        UnistorTss* tss = (UnistorTss*)CwxTss::instance();
        ///发送认证消息
        CwxMsgBlock* block = NULL;
        if (UNISTOR_ERR_SUCCESS != UnistorPoco::packRecvAuth(tss->m_pWriter,
            block,
            0,
            m_pApp->getConfig().getRecv().getUser().length()?m_pApp->getConfig().getRecv().getUser().c_str():"",
            m_pApp->getConfig().getRecv().getPasswd().length()?m_pApp->getConfig().getRecv().getPasswd().c_str():"",
            tss->m_szBuf2K))
        {
            CWX_ERROR(("Failure to pack recv auth package, err=%s", tss->m_szBuf2K));
            ret = channel()->removeHandler(this);
            if (0 != ret){
                CWX_ERROR(("Failure to remove handler from channel"));
            }
            return -1;
        }
        (*m_handlers)[m_uiConnId] = this;
        block->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
        ///发送消息
        putMsg(block);
    }
    return 0;
}
开发者ID:burstas,项目名称:cwx-kv,代码行数:28,代码来源:UnistorHandler4Trans.cpp

示例3: while

///发送topic状态表
int CwxMqInnerDispHandler::syncTopicState(CwxMqTss* pTss) {
  if (m_syncSession->m_topicIsChanged) {
    map<string, CWX_UINT8> topicState;
    map<string, CwxBinlogMgrCursor*>::iterator iter = m_syncSession->m_binlogCursor.begin();
    while (iter != m_syncSession->m_binlogCursor.end()) {
      topicState.insert(pair<string, CWX_UINT8>(iter->first, iter->second->m_binlogMgr->getZkTopicState()));
      CWX_DEBUG(("sync topic:%s, state:%d", iter->first.c_str(), iter->second->m_binlogMgr->getZkTopicState()));
      iter++;
    }
    CwxMsgBlock* pBlock;
    int ret = CwxMqPoco::packTopicState(pTss->m_pWriter, pTss->m_pItemWriter, pBlock, 0, topicState, pTss->m_szBuf2K);
    if (ret != CWX_MQ_ERR_SUCCESS) {
      CWX_ERROR(("Failure to pack topicState err:%s", pTss->m_szBuf2K));
      return -1;
    }
    ///根据svr类型,发送数据包
    pBlock->send_ctrl().setConnId(CWX_APP_INVALID_CONN_ID);
    pBlock->send_ctrl().setSvrId(CwxMqApp::SVR_TYPE_INNER_DISP);
    pBlock->send_ctrl().setHostId(0);
    pBlock->send_ctrl().setMsgAttr(CwxMsgSendCtrl::NONE);
    if (!putMsg(pBlock)) {
      CwxCommon::snprintf(pTss->m_szBuf2K, 2047, "Failure to send topicState msg.");
      CWX_ERROR((pTss->m_szBuf2K));
      CwxMsgBlockAlloc::free(pBlock);
      return -1;
    }
    m_syncSession->m_topicIsChanged = false;
  }
  return 0;
}
开发者ID:azureplus,项目名称:flatq,代码行数:31,代码来源:CwxMqInnerDispHandler.cpp

示例4: memcpy

void CwxEchoChannelEventHandler::replyMessage()
{
    ///设置echo回复的消息类型,为请求的消息类型+1
    m_recvMsgData->event().getMsgHeader().setMsgType(m_recvMsgData->event().getMsgHeader().getMsgType() + 1);
    ///设置echo回复的数据包长度
    m_recvMsgData->event().getMsgHeader().setDataLen(m_recvMsgData->length());
    ///创建回复的数据包
    CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(m_recvMsgData->length() + CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的包头
    memcpy(pBlock->wr_ptr(), m_recvMsgData->event().getMsgHeader().toNet(), CwxMsgHead::MSG_HEAD_LEN);
    ///滑动block的写指针
    pBlock->wr_ptr(CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的数据
    memcpy(pBlock->wr_ptr(), m_recvMsgData->rd_ptr(), m_recvMsgData->length());
    ///滑动block的写指针
    pBlock->wr_ptr(m_recvMsgData->length());
    if (!putMsg(pBlock))
    {
        CWX_ERROR(("Failure to put message"));
        CwxMsgBlockAlloc::free(pBlock);
    }
    m_ullMsgNum ++;
    if (m_ullMsgNum && !(m_ullMsgNum%10000))
    {
        char szBuf[64];
        CwxCommon::toString(m_ullMsgNum, szBuf, 10);
        CWX_INFO(("Recv echo message num:%s", szBuf));
    }


}
开发者ID:chenper,项目名称:cwinux,代码行数:31,代码来源:CwxEchoChannelEventHandler.cpp

示例5: onConnClosed

///连接关闭
int CwxProProxyApp::onConnClosed(CwxAppHandler4Msg& ,
    CwxAppHandler4Msg& conn,
    CwxMsgHead const& ,
    bool& ) {
  CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
  pBlock->event().setSvrId(conn.getConnInfo().getSvrId());
  pBlock->event().setHostId(conn.getConnInfo().getHostId());
  pBlock->event().setConnId(conn.getConnInfo().getConnId());
  pBlock->event().setEvent(CwxEventInfo::CONN_CLOSED);
  m_mqThreadPool->append(pBlock);
  return 0;
}
开发者ID:azureplus,项目名称:flatq,代码行数:13,代码来源:CwxProductProxyApp.cpp

示例6: innerNoticeSendMsgBySvr

///notice send msg by svr
void CwxAppFramework::innerNoticeSendMsgBySvr(CwxAppFramework* pApp,
                                    CwxAppNotice* pNotice)
{
    CwxMsgBlock* msg = (CwxMsgBlock*)pNotice->m_noticeArg;
    if (0 != pApp->onSendMsgBySvr(msg))
    {
        if (msg->send_ctrl().isFailNotice())
        {
            pApp->onFailSendMsg(msg);
        }
        if (msg) CwxMsgBlockAlloc::free(msg);
    }
    pNotice->m_noticeArg = NULL;
}
开发者ID:chenper,项目名称:cwinux,代码行数:15,代码来源:CwxAppFramework.cpp

示例7: onConnClosed

///连接关闭
int CwxMqApp::onConnClosed(CwxAppHandler4Msg& conn) {
  if ((SVR_TYPE_RECV == conn.getConnInfo().getSvrId())
    || (SVR_TYPE_MASTER == conn.getConnInfo().getSvrId()))
  {
    CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
    pBlock->event().setSvrId(conn.getConnInfo().getSvrId());
    pBlock->event().setHostId(conn.getConnInfo().getHostId());
    pBlock->event().setConnId(conn.getConnInfo().getConnId());
    ///设置事件类型
    pBlock->event().setEvent(CwxEventInfo::CONN_CLOSED);
    m_recvThreadPool->append(pBlock);
  } else if (SVR_TYPE_MONITOR == conn.getConnInfo().getSvrId()) { ///若是监控的连接关闭,则必须释放先前所创建的string对象。
    if (conn.getConnInfo().getUserData()) {
      delete (string*) conn.getConnInfo().getUserData();
      conn.getConnInfo().setUserData(NULL);
    }
  } else {
    CWX_ASSERT(0);
  }
  return 0;
}
开发者ID:burstas,项目名称:cwinux-mq,代码行数:22,代码来源:CwxMqApp.cpp

示例8: header

///往master转发消息
bool UnistorHandler4Trans::transMsg(UnistorTss* , CWX_UINT32 uiTaskId, CwxMsgBlock* msg){
    CwxMsgBlock* block = NULL;
    ///如果没有完成认证的连接,则失败
    if (!m_uiAuthConnNum) return false;
    ///往master转发消息
    block = CwxMsgBlockAlloc::malloc(CwxMsgHead::MSG_HEAD_LEN + msg->length());
    CwxMsgHead header(msg->event().getMsgHeader());
    header.setDataLen(msg->length());
    header.setTaskId(uiTaskId);
    CWX_UINT8 ucAttr=header.getAttr();
    header.setAttr(UnistorPoco::clearFromMaster(ucAttr));
    memcpy(block->wr_ptr(), header.toNet(), CwxMsgHead::MSG_HEAD_LEN);
    memcpy(block->wr_ptr() + CwxMsgHead::MSG_HEAD_LEN, msg->rd_ptr(), msg->length());
    block->wr_ptr( CwxMsgHead::MSG_HEAD_LEN + msg->length());
    block->event().setTaskId(uiTaskId);
    block->send_ctrl().setMsgAttr(CwxMsgSendCtrl::FAIL_FINISH_NOTICE);
    if (!m_authConn[msg->event().getConnId()%m_uiAuthConnNum]->putMsg(block)){
        CwxMsgBlockAlloc::free(block);
        return false;
    }
    return true;
}
开发者ID:burstas,项目名称:cwx-kv,代码行数:23,代码来源:UnistorHandler4Trans.cpp

示例9: while

int UnistorHandler4Trans::onConnClosed()
{
    list<CwxTaskBoardTask*> tasks;
    CwxTss* pThrEnv = CwxTss::instance();
    CwxMsgBlock* msg = CwxMsgBlockAlloc::malloc(0);
    msg->event().setHostId(0);
    msg->event().setConnId(m_uiConnId);
    m_pApp->getTaskBoard().noticeConnClosed(msg, pThrEnv, tasks);
    if (!tasks.empty())
    {
        list<CwxTaskBoardTask*>::iterator iter = tasks.begin();
        while(iter != tasks.end()){
            (*iter)->execute(pThrEnv);
            iter++;
        }
        tasks.clear();
    }
    m_handlers->erase(m_uiConnId);
    m_bRebuildConn = true;
    m_bCanTrans = false;
    return -1;
}
开发者ID:burstas,项目名称:cwx-kv,代码行数:22,代码来源:UnistorHandler4Trans.cpp

示例10: CWX_ERROR

///notice send msg
void CwxAppFramework::innerNoticeSendMsgByConn(CwxAppFramework* pApp,
                                               CwxAppNotice* pNotice)
{
    CwxMsgBlock* msg = (CwxMsgBlock*)pNotice->m_noticeArg;
    CwxAppHandler4Msg* pConn = (CwxAppHandler4Msg*)pApp->m_pReactor->getHandlerByConnId(msg->send_ctrl().getConnId());
    if (!pConn || 
        (CwxAppConnInfo::ESTABLISHED != pConn->getConnInfo().getState()))
    {
        if (msg->send_ctrl().isFailNotice())
        {
            pApp->onFailSendMsg(msg);
        }
        if (msg) CwxMsgBlockAlloc::free(msg);
        pNotice->m_noticeArg = NULL;
        return;
    }
    if (!msg->send_ctrl().isUndoConn())
    {
        int ret = 0;
        if (msg->send_ctrl().isResumeConn())
        {
            ret = pConn->reactor()->resumeHandler(pConn, CwxAppHandler4Base::READ_MASK);
            if (0 != ret)
            {
                CWX_ERROR(("Failure to resume handler, conn_id=[%u]", msg->send_ctrl().getConnId()));
                pConn->close();
            }
        }
        else if (msg->send_ctrl().isSuspendConn())
        {
            ret = pConn->reactor()->suspendHandler(pConn, CwxAppHandler4Base::READ_MASK);
            if (0 != ret)
            {
                CWX_ERROR(("Failure to resume handler, conn_id=[%u]", msg->send_ctrl().getConnId()));
                pConn->close();
            }
        }
    }
    if (!pConn->putMsg(msg))
    {
        if (msg->send_ctrl().isFailNotice())
        {
            pApp->onFailSendMsg(msg);
        }
        if (msg) CwxMsgBlockAlloc::free(msg);
        pNotice->m_noticeArg = NULL;
    }
}
开发者ID:chenper,项目名称:cwinux,代码行数:49,代码来源:CwxAppFramework.cpp

示例11: onConnCreated

///连接建立
int CwxMqApp::onConnCreated(CwxAppHandler4Msg& conn,
                            bool&,
                            bool&)
{
  if ((SVR_TYPE_RECV == conn.getConnInfo().getSvrId())
    || (SVR_TYPE_MASTER == conn.getConnInfo().getSvrId()))
  {
    CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
    pBlock->event().setSvrId(conn.getConnInfo().getSvrId());
    pBlock->event().setHostId(conn.getConnInfo().getHostId());
    pBlock->event().setConnId(conn.getConnInfo().getConnId());
    ///设置事件类型
    pBlock->event().setEvent(CwxEventInfo::CONN_CREATED);
    ///将事件添加到消息队列
    m_recvThreadPool->append(pBlock);
  } else if (SVR_TYPE_MONITOR == conn.getConnInfo().getSvrId()) { ///如果是监控的连接建立,则建立一个string的buf,用于缓存不完整的命令
    string* buf = new string();
    conn.getConnInfo().setUserData(buf);
  } else {
    CWX_ASSERT(0);
  }
  return 0;
}
开发者ID:burstas,项目名称:cwinux-mq,代码行数:24,代码来源:CwxMqApp.cpp

示例12: memcpy

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 = "";
    }
  }
}
开发者ID:chenper,项目名称:cwinux,代码行数:24,代码来源:CwxEchoThriftIf.cpp

示例13: onRecvMsg

///echo请求的处理函数
int CwxEchoEventHandler::onRecvMsg(CwxMsgBlock*& msg, CwxTss* )
{
    ///设置echo回复的消息类型,为请求的消息类型+1
    msg->event().getMsgHeader().setMsgType(msg->event().getMsgHeader().getMsgType() + 1);
    ///设置echo回复的数据包长度
    msg->event().getMsgHeader().setDataLen(msg->length());
    ///创建回复的数据包
    CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(msg->length() + CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的包头
    memcpy(pBlock->wr_ptr(), msg->event().getMsgHeader().toNet(), CwxMsgHead::MSG_HEAD_LEN);
    ///滑动block的写指针
    pBlock->wr_ptr(CwxMsgHead::MSG_HEAD_LEN);
    ///拷贝数据包的数据
    memcpy(pBlock->wr_ptr(), msg->rd_ptr(), msg->length());
    ///滑动block的写指针
    pBlock->wr_ptr(msg->length());
    ///设置回复消息的发送控制信息
    pBlock->send_ctrl().reset();
    ///设置回复消息对应连接的svr-id
    pBlock->send_ctrl().setSvrId(msg->event().getSvrId());
    ///设置回复消息对应连接的host-id
    pBlock->send_ctrl().setHostId(msg->event().getHostId());
    ///设置回复消息的连接id
    pBlock->send_ctrl().setConnId(msg->event().getConnId());
    ///回复消息
    if (0 != this->m_pApp->sendMsgByConn(pBlock))
    {
        CWX_ERROR(("Failure to send msg"));
        return -1;
    }
    m_ullMsgNum ++;
    if (m_ullMsgNum && !(m_ullMsgNum%10000))
    {
        char szBuf[64];
        CwxCommon::toString(m_ullMsgNum, szBuf, 10);
        CWX_INFO(("Recv echo message num:%s", szBuf));
    }
    return 1;
}
开发者ID:chenper,项目名称:cwinux,代码行数:40,代码来源:CwxEchoEventHandler.cpp

示例14: isClockBack

///时钟函数
void CwxProProxyApp::onTime(CwxTimeValue const& current) {
  ///调用基类的onTime函数
  CwxAppFramework::onTime(current);
  m_ttCurTime = current.sec();
  ///检查超时
  static CWX_UINT32 ttTimeBase = 0; ///<时钟回跳的base时钟
  static CWX_UINT32 ttLastTime = 0; ///<上次检查时间
  bool bClockBack = isClockBack(ttTimeBase, m_ttCurTime);
  if (bClockBack || (m_ttCurTime >= ttLastTime + 1)) {
    ttLastTime = m_ttCurTime;
    if (m_zkThreadPool) { ///发送超时检查到zk线程
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_PRO_TYPE_ZK);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      m_zkThreadPool->append(pBlock);
    }
    if (m_mqThreadPool) { ///发送超时检查到mq线程
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_PRO_TYPE_RECV);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      m_mqThreadPool->append(pBlock);
    }
  }
}
开发者ID:azureplus,项目名称:flatq,代码行数:25,代码来源:CwxProductProxyApp.cpp

示例15: isClockBack

///时钟函数
void CwxMqApp::onTime(CwxTimeValue const& current) {
  ///调用基类的onTime函数
  CwxAppFramework::onTime(current);
  m_ttCurTime = current.sec();
  ///检查超时
  static CWX_UINT32 ttTimeBase = 0; ///<时钟回跳的base时钟
  static CWX_UINT32 ttLastTime = m_ttCurTime; ///<上一次检查的时间
  bool bClockBack = isClockBack(ttTimeBase, m_ttCurTime);
  if (bClockBack || (m_ttCurTime >= ttLastTime + 1)) {
    ttLastTime = m_ttCurTime;
    if (m_config.getCommon().m_bMaster) {
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_TYPE_RECV);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      //将超时检查事件,放入事件队列
      m_recvThreadPool->append(pBlock);
    } else {
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_TYPE_MASTER);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      //将超时检查事件,放入事件队列
      m_recvThreadPool->append(pBlock);
    }
    //若存在分发线程池,则往分发线程池append TIMEOUT_CHECK
    if (m_dispThreadPool) {
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_TYPE_DISP);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      //将超时检查事件,放入事件队列
      m_dispThreadPool->append(pBlock);
    }
    //若存在mq程池,则往mq线程池append TIMEOUT_CHECK
    if (m_mqThreadPool) {
      CwxMsgBlock* pBlock = CwxMsgBlockAlloc::malloc(0);
      pBlock->event().setSvrId(SVR_TYPE_QUEUE);
      pBlock->event().setEvent(CwxEventInfo::TIMEOUT_CHECK);
      //将超时检查事件,放入事件队列
      m_mqThreadPool->append(pBlock);
    }
  }
}
开发者ID:burstas,项目名称:cwinux-mq,代码行数:42,代码来源:CwxMqApp.cpp


注:本文中的CwxMsgBlock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。