Example #1
0
bool C4Network2IO::BroadcastMsg(const C4NetIOPacket &rPkt) // by both
{
    // TODO: ugly algorithm. do better

    // begin broadcast
    BeginBroadcast(false);
    // select one connection per reachable client
    CStdLock ConnListLock(&ConnListCSec);
    for (C4Network2IOConnection *pConn = pConnList; pConn; pConn = pConn->pNext)
        if (pConn->isAccepted())
        {
            if (pConn->getProtocol() == P_UDP)
                pConn->SetBroadcastTarget(true);
            else if (pConn->getProtocol() == P_TCP)
            {
                C4Network2IOConnection *pConn2 = GetMsgConnection(pConn->getClientID());
                if (pConn == pConn2)
                    pConn->SetBroadcastTarget(true);
                pConn2->DelRef();
            }
        }
    // send
    bool fSuccess = Broadcast(rPkt);
    // end broadcast
    EndBroadcast();
    // return
    return fSuccess;
}
Example #2
0
C4Network2IOConnection *C4Network2IO::GetDataConnection(int iClientID) // by main thread
{
    CStdLock ConnListLock(&ConnListCSec);
    C4Network2IOConnection *pRes = NULL;
    for (C4Network2IOConnection *pConn = pConnList; pConn; pConn = pConn->pNext)
        if (pConn->isAccepted())
            if (pConn->getClientID() == iClientID)
                if (pConn->getProtocol() == P_TCP || !pRes)
                    pRes = pConn;
    // add reference
    if (pRes) pRes->AddRef();
    return pRes;
}