Beispiel #1
0
///echo请求的请求消息
int CwxEchoApp::onRecvMsg(CwxMsgBlock* msg, CwxAppHandler4Msg& conn, CwxMsgHead const& header, bool& bSuspendConn){

    msg->event().setSvrId(conn.getConnInfo().getSvrId());
    msg->event().setHostId(conn.getConnInfo().getHostId());
    msg->event().setConnId(conn.getConnInfo().getConnId());
    msg->event().setIoHandle(conn.getHandle());
    msg->event().setConnUserData(NULL);
    msg->event().setMsgHeader(header);
    msg->event().setEvent(CwxEventInfo::RECV_MSG);
    msg->event().setTimestamp(CwxDate::getTimestamp());
    ///不停止继续接受
    bSuspendConn = false;
    CWX_ASSERT (msg);
    ///将消息放到线程池队列中,有内部的线程调用其处理handle来处理
    m_threadPool->append(msg);
    return 0;

}
Beispiel #2
0
///收到消息的响应函数
int CwxMqApp::onRecvMsg(CwxAppHandler4Msg& conn, bool&) {
  if (SVR_TYPE_MONITOR == conn.getConnInfo().getSvrId()) {
    char szBuf[1024];
    ssize_t recv_size = CwxSocket::recv(conn.getHandle(), szBuf, 1024);
    if (recv_size <= 0) { //error or signal
      if ((0 == recv_size) || ((errno != EWOULDBLOCK) && (errno != EINTR))) {
        return -1; //error
      } else { //signal or no data
        return 0;
      }
    }
    ///监控消息
    return monitorStats(szBuf, (CWX_UINT32) recv_size, conn);
  } else {
    CWX_ASSERT(0);
  }
  return -1;
}
Beispiel #3
0
int CwxAppFramework::onRecvMsg(CwxAppHandler4Msg& conn,
                      bool& )
{
    CWX_DEBUG(("recv msg, svr_id=%u, host_id=%u, conn_id=%u",
        conn.getConnInfo().getSvrId(),
        conn.getConnInfo().getHostId(),
        conn.getConnInfo().getConnId()));
    char szBuf[4096];
    int ret = 0;
    while(1)
    {
        ret = CwxSocket::read(conn.getHandle(), szBuf, 4096);
        if (0>=ret)
        {
            if ((0 == ret) || (errno != EWOULDBLOCK))
            {
                return -1; //error
            }
            return 0;
        }
        if (ret < 4096) return 0;
    }
    return ret;
}