// call this regularely internal override void SendQueuedMessages(float now) { // // resends // for (int i = 0; i < m_storedMessages.Length; i++) { NetOutgoingMessage om = m_storedMessages[i].Message; if (om == null) { continue; } float t = m_storedMessages[i].LastSent; if (t > 0 && (now - t) > m_resendDelay) { // deduce sequence number int startSlot = m_windowStart % m_windowSize; int seqNr = m_windowStart; while (startSlot != i) { startSlot--; if (startSlot < 0) { startSlot = m_windowSize - 1; } seqNr--; } //m_connection.m_peer.LogVerbose("Resending due to delay #" + seqNr + " " + om.ToString()); m_connection.m_statistics.MessageResent(MessageResendReason.Delay); m_connection.QueueSendMessage(om, seqNr); m_storedMessages[i].LastSent = now; m_storedMessages[i].NumSent++; } } int num = GetAllowedSends(); if (num < 1) { return; } // queued sends while (m_queuedSends.Count > 0 && num > 0) { NetOutgoingMessage om; if (m_queuedSends.TryDequeue(out om)) { ExecuteSend(now, om); } num--; NetException.Assert(num == GetAllowedSends()); } }
private void ExecuteSend(float now, NetOutgoingMessage message) { m_connection.m_peer.VerifyNetworkThread(); int seqNr = m_sendStart; m_sendStart = (m_sendStart + 1) % NetConstants.NumSequenceNumbers; m_connection.QueueSendMessage(message, seqNr); Interlocked.Decrement(ref message.m_recyclingCount); if (message.m_recyclingCount <= 0) { m_connection.m_peer.Recycle(message); } return; }