private void AckHandler(IncomingCommand command) { uint currentRoundTripTime = command.TimestampOfReceive - command.AckReceivedSentTime; // Find a channel that the command came, and remove a sent command. UdpChannel channel = _channels[command.Channel]; OutgoingCommand reliableCommand = channel.ReliableSendQueue.ReceiveAck(command); //if reliableCommand is null, current command is already received. if (reliableCommand == null) return; if (reliableCommand.CommandType == CommandType.SNTP) { ProcessSntp(command, currentRoundTripTime); } _roundTripTime.Update((int)currentRoundTripTime); if (_allowStatistics) { _statistics.UpdateRoundTripTime(_roundTripTime); _statistics.ReceiveAck(command.TimestampOfReceive); } }
internal void EnqueueOutgoingCommand(OutgoingCommand command) { UdpChannel udpChannel = _channels[command.Channel]; lock (udpChannel) { SendQueueBase queue = command.IsReliable ? (SendQueueBase)udpChannel.ReliableSendQueue : udpChannel.UnreliableSendQueue; queue.EnqueueOutgoingCommand(command); } }
private void EnqueueSentCommand(OutgoingCommand command, uint currentSendingTime) { UdpChannel channel = _channels[command.Channel]; channel.ReliableSendQueue.EnqueueSentCommand(command, currentSendingTime, _roundTripTime.NewRoundTripTime(), (uint)DisconnectTimeout); if (_allowStatistics && command.SendAttempts > 1) { _statistics.ResendCommand(); } }
private void SendAck() { do { lock (_udpBuffer) { Array.Clear(_udpBuffer, 0, _udpBuffer.Length); _udpBufferIndex = MtuHeaderLength; uint currentTime = EnvironmentTimer.GetTickCount(); int commandCountToSend = SerializeAck(currentTime); if (!EnqueueResendingCommands(currentTime)) return; //Ping 전송이 필요한지 판단하여 송신 if (_udpSocket.State == SocketState.Connected && currentTime - _timestampOfLastReliableSend > PingInterval) { OutgoingCommand command = new OutgoingCommand(CommandType.Ping, 0); EnqueueOutgoingCommand(command); // Ping이 Reliable command이기 때문에, Reliable command들을 Serialize 한다. for (int i = 0; i < _channels.Count; i++) { commandCountToSend += SerializeQueue(_channels[i].ReliableSendQueue, currentTime); } _timestampOfLastReliableSend = currentTime; } SendBuffer(commandCountToSend, currentTime); } } while (RemainingAckCommands() > 0); }
public static void Erase(this List <OutgoingCommand> commands, OutgoingCommand command) { command.Dispose(); commands.Remove(command); }