Beispiel #1
0
bool NFCNet::SendMsg(const char* msg, const uint32_t nLen, const int nSockIndex)
{
    if (nLen <= 0)
    {
        return false;
    }

    std::map<int, NetObject*>::iterator it = mmObject.find(nSockIndex);
    if (it != mmObject.end())
    {
        NetObject* pNetObject = (NetObject*)it->second;
        if (pNetObject)
        {
            bufferevent* bev = pNetObject->GetBuffEvent();
            if (NULL != bev)
            {
                bufferevent_write(bev, msg, nLen);

                return true;
            }
        }
    }

    return false;
}
Beispiel #2
0
bool NFCNet::SendMsgToAllClient( const NFIPacket& msg )
{
    std::map<int, NetObject*>::iterator it = mmObject.begin();
    for (; it != mmObject.end(); ++it)
    {
        NetObject* pNetObject = (NetObject*)it->second;
        if (pNetObject && !pNetObject->GetRemoveState())
        {
            bufferevent* bev = pNetObject->GetBuffEvent();
            if (NULL != bev)
            {
                bufferevent_write(bev, msg.GetPacketData(), msg.GetPacketLen());
            }
        }
    }

    return true;
}
Beispiel #3
0
void NFCNet::CloseObject( const int nSockIndex )
{
    std::map<int, NetObject*>::iterator it = mmObject.find(nSockIndex);
    if (it != mmObject.end())
    {
        NetObject* pObject = it->second;

        struct bufferevent* bev = pObject->GetBuffEvent();
        //bev->cbarg = NULL;

        bufferevent_free(bev);
        evutil_closesocket(nSockIndex);

        mmObject.erase(it);

        delete pObject;
        pObject = NULL;
    }
}
Beispiel #4
0
bool NFCNet::SendMsgToAllClient( const char* msg, const uint32_t nLen )
{
    if (nLen <= 0)
    {
        return false;
    }

    std::map<int, NetObject*>::iterator it = mmObject.begin();
    for (; it != mmObject.end(); ++it)
    {
        NetObject* pNetObject = (NetObject*)it->second;
        if (pNetObject && !pNetObject->GetRemoveState())
        {
            bufferevent* bev = pNetObject->GetBuffEvent();
            if (NULL != bev)
            {
                bufferevent_write(bev, msg, nLen);
            }
        }
    }

    return true;
}