Beispiel #1
0
///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;
    }
}