Esempio n. 1
0
void CNetConnection::Resend()
{
    for(CNetChunkResend *pResend = m_Buffer.First(); pResend; pResend = m_Buffer.Next(pResend))
        ResendChunk(pResend);
}
Esempio n. 2
0
int CNetConnection::Update()
{
    int64 Now = time_get();

    if(State() == NET_CONNSTATE_ERROR && m_TimeoutSituation && (Now-m_LastRecvTime) > time_freq()*g_Config.m_ConnTimeoutProtection)
    {
        m_TimeoutSituation = false;
        SetError("Timeout Protection over");
    }

    if(State() == NET_CONNSTATE_OFFLINE || State() == NET_CONNSTATE_ERROR)
        return 0;

    m_TimeoutSituation = false;

    // check for timeout
    if(State() != NET_CONNSTATE_OFFLINE &&
            State() != NET_CONNSTATE_CONNECT &&
            (Now-m_LastRecvTime) > time_freq()*g_Config.m_ConnTimeout)
    {
        m_State = NET_CONNSTATE_ERROR;
        SetError("Timeout");
        m_TimeoutSituation = true;
    }

    // fix resends
    if(m_Buffer.First())
    {
        CNetChunkResend *pResend = m_Buffer.First();

        // check if we have some really old stuff laying around and abort if not acked
        if(Now-pResend->m_FirstSendTime > time_freq()*g_Config.m_ConnTimeout)
        {
            m_State = NET_CONNSTATE_ERROR;
            char aBuf[512];
            str_format(aBuf, sizeof(aBuf), "Too weak connection (not acked for %d seconds)", g_Config.m_ConnTimeout);
            SetError(aBuf);
            m_TimeoutSituation = true;
        }
        else
        {
            // resend packet if we havn't got it acked in 1 second
            if(Now-pResend->m_LastSendTime > time_freq())
                ResendChunk(pResend);
        }
    }

    // send keep alives if nothing has happend for 250ms
    if(State() == NET_CONNSTATE_ONLINE)
    {
        if(time_get()-m_LastSendTime > time_freq()/2) // flush connection after 500ms if needed
        {
            int NumFlushedChunks = Flush();
            if(NumFlushedChunks && g_Config.m_Debug)
                dbg_msg("connection", "flushed connection due to timeout. %d chunks.", NumFlushedChunks);
        }

        if(time_get()-m_LastSendTime > time_freq())
            SendControl(NET_CTRLMSG_KEEPALIVE, 0, 0);
    }
    else if(State() == NET_CONNSTATE_CONNECT)
    {
        if(time_get()-m_LastSendTime > time_freq()/2) // send a new connect every 500ms
            SendControl(NET_CTRLMSG_CONNECT, SECURITY_TOKEN_MAGIC, sizeof(SECURITY_TOKEN_MAGIC));
    }
    else if(State() == NET_CONNSTATE_PENDING)
    {
        if(time_get()-m_LastSendTime > time_freq()/2) // send a new connect/accept every 500ms
            SendControl(NET_CTRLMSG_CONNECTACCEPT, SECURITY_TOKEN_MAGIC, sizeof(SECURITY_TOKEN_MAGIC));
    }

    return 0;
}
Esempio n. 3
0
int CNetConnection::Update()
{
	int64 Now = time_get();

	if(State() == NET_CONNSTATE_OFFLINE || State() == NET_CONNSTATE_ERROR)
		return 0;
	
	// check for timeout
	if(State() != NET_CONNSTATE_OFFLINE &&
		State() != NET_CONNSTATE_CONNECT &&
		(Now-m_LastRecvTime) > time_freq()*10)
	{
		m_State = NET_CONNSTATE_ERROR;
		SetError("timeout");
	}

	// fix resends
	if(m_Buffer.First())
	{
		CNetChunkResend *pResend = m_Buffer.First();

		// check if we have some really old stuff laying around and abort if not acked
		if(Now-pResend->m_FirstSendTime > time_freq()*10)
		{
			m_State = NET_CONNSTATE_ERROR;
			SetError("too weak connection (not acked for 10 seconds)");
		}
		else
		{
			// resend packet if we havn't got it acked in 1 second
			if(Now-pResend->m_LastSendTime > time_freq())
				ResendChunk(pResend);
		}
	}
	
	// send keep alives if nothing has happend for 250ms
	if(State() == NET_CONNSTATE_ONLINE)
	{
		if(time_get()-m_LastSendTime > time_freq()/2) // flush connection after 500ms if needed
		{
			int NumFlushedChunks = Flush();
			if(NumFlushedChunks && g_Config.m_Debug)
				dbg_msg("connection", "flushed connection due to timeout. %d chunks.", NumFlushedChunks);
		}
			
		if(time_get()-m_LastSendTime > time_freq())
			SendControl(NET_CTRLMSG_KEEPALIVE, 0, 0);
	}
	else if(State() == NET_CONNSTATE_CONNECT)
	{
		if(time_get()-m_LastSendTime > time_freq()/2) // send a new connect every 500ms
			SendControl(NET_CTRLMSG_CONNECT, 0, 0);
	}
	else if(State() == NET_CONNSTATE_PENDING)
	{
		if(time_get()-m_LastSendTime > time_freq()/2) // send a new connect/accept every 500ms
			SendControl(NET_CTRLMSG_CONNECTACCEPT, 0, 0);
	}
	
	return 0;
}