void C4Network2ClientListBox::ConnectionListItem::Update()
{
	C4Network2IOConnection *pConn = GetConnection();
	if (!pConn)
	{
		// No connection: Shouldn't happen
		pDesc->SetText("???");
		pPing->SetText("???");
		return;
	}
	// update connection ping
	int iPing = pConn->getLag();
	pPing->SetText(FormatString("%d ms", iPing).getData());
	// update description
	// get connection usage
	const char *szConnType;
	C4Network2Client *pNetClient = ::Network.Clients.GetClientByID(iClientID);
	if (pNetClient->getDataConn() == pNetClient->getMsgConn())
		szConnType = "Data/Msg";
	else if (iConnID)
		szConnType = "Msg";
	else
		szConnType = "Data";
	// display info
	pDesc->SetText(FormatString("%s: %s (%s l%d)",
	                            szConnType,
	                            ::Network.NetIO.getNetIOName(pConn->getNetClass()),
	                            pConn->getPeerAddr().ToString().getData(),
	                            pConn->getPacketLoss()).getData());
}
Beispiel #2
0
C4Network2IOConnection *C4Network2IO::GetConnectionByConnAddr(const C4NetIO::addr_t &addr, C4NetIO *pNetIO) // by both
{
    CStdLock ConnListLock(&ConnListCSec);
    // search
    for (C4Network2IOConnection *pConn = pConnList; pConn; pConn = pConn->pNext)
        if (pConn->getNetClass() == pNetIO && AddrEqual(pConn->getConnectAddr(), addr))
            return pConn;
    return NULL;
}
Beispiel #3
0
void C4Network2IO::GenerateStatistics(int iInterval)
{
    int iTCPIRateSum = 0, iTCPORateSum = 0, iUDPIRateSum = 0, iUDPORateSum = 0;

    // acquire lock, get connection statistics
    CStdLock ConnListLock(&ConnListCSec);
    for (C4Network2IOConnection *pConn = pConnList; pConn; pConn = pConn->pNext)
        if (pConn->isOpen())
        {
            bool fTCP = pConn->getNetClass() == pNetIO_TCP;
            pConn->DoStatistics(iInterval, fTCP ? &iTCPIRateSum : &iUDPIRateSum,
                                fTCP ? &iTCPORateSum : &iUDPORateSum);
        }
    ConnListLock.Clear();

    // get broadcast statistics
    int inTCPBCRate = 0, inUDPBCRate = 0;
    if (pNetIO_TCP) pNetIO_TCP->GetStatistic(&inTCPBCRate);
    if (pNetIO_UDP) pNetIO_UDP->GetStatistic(&inUDPBCRate);

    // normalize everything
    iTCPIRateSum = iTCPIRateSum * 1000 / iInterval;
    iTCPORateSum = iTCPORateSum * 1000 / iInterval;
    iUDPIRateSum = iUDPIRateSum * 1000 / iInterval;
    iUDPORateSum = iUDPORateSum * 1000 / iInterval;
    inTCPBCRate = inTCPBCRate * 1000 / iInterval;
    inUDPBCRate = inUDPBCRate * 1000 / iInterval;

    // clear
    if (pNetIO_TCP) pNetIO_TCP->ClearStatistic();
    if (pNetIO_UDP) pNetIO_UDP->ClearStatistic();

    // save back
    iTCPIRate = iTCPIRateSum;
    iTCPORate = iTCPORateSum;
    iTCPBCRate = inTCPBCRate;
    iUDPIRate = iUDPIRateSum;
    iUDPORate = iUDPORateSum;
    iUDPBCRate = inUDPBCRate;
}