Пример #1
0
void C4Network2IO::OnDisconn(const C4NetIO::addr_t &addr, C4NetIO *pNetIO, const char *szReason)
{
    // punch?
    if (pNetIO == pNetIO_UDP)
        if (PuncherAddr.sin_addr.s_addr && AddrEqual(PuncherAddr, addr))
        {
            ZeroMem(&PuncherAddr, sizeof(PuncherAddr));
            return;
        }
#if(C4NET2IO_DUMP_LEVEL > 1)
    Application.InteractiveThread.ThreadLogS("OnDisconn: %s %s",
            C4TimeMilliseconds::Now().AsString().getData(),
            getNetIOName(pNetIO));
#endif
    // find connection
    C4Network2IOConnection *pConn = GetConnection(addr, pNetIO);
    if (!pConn) pConn = GetConnectionByConnAddr(addr, pNetIO);
    if (!pConn) return;
#if(C4NET2IO_DUMP_LEVEL > 0)
    // log
    Application.InteractiveThread.ThreadLogS("Network: %s connection to %s:%d %s (%s)",
            getNetIOName(pNetIO), inet_ntoa(addr.sin_addr), htons(addr.sin_port), pConn->isConnecting() ? "failed" : "closed" , szReason);
#endif
    // already closed? ignore
    if (!pConn->isClosed())
        // not accepted yet? count as connection failure
        pConn->SetStatus(pConn->isHalfAccepted() ? CS_Closed : CS_ConnectFail);
    // keep connection for main thread message
    pConn->AddRef();
    // check for pending welcome packets
    SendConnPackets();
    // signal to main thread
    Application.InteractiveThread.PushEvent(Ev_Net_Disconn, pConn);
    // don't remove connection from list - wait for postmortem or timeout
}
Пример #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;
}