public List <OutgoingCommand> DequeueSendableCommands(int bufferOffset, int bufferSize)
        {
            var result = new List <OutgoingCommand>();
            int index  = bufferOffset;

            while (_commands.Count > 0)
            {
                OutgoingCommand command = _commands.Peek();

                if (command == null)
                {
                    return(result);
                }

                //preventing buffer overflow, pendding command
                if (index + command.Size > bufferSize)
                {
                    return(result);
                }

                index += command.Size;

                result.Add(_commands.Dequeue());
            }
            return(result);
        }
        public override bool EnqueueOutgoingCommand(OutgoingCommand command)
        {
            command.ReliableSequenceNumber   = Channel.OutgoingReliableSequenceNumber;
            command.UnreliableSequenceNumber = ++Channel.OutgoingUnreliableSequenceNumber;
            Commands.Enqueue(command);

            return(true);
        }
示例#3
0
 public override bool EnqueueOutgoingCommand(OutgoingCommand command)
 {
     if (command != null)
     {
         Commands.Enqueue(command);
         return(true);
     }
     return(false);
 }
 public void CreateConnectionClose(ushort reasonCode,
                                   string reasonText,
                                   out OutgoingCommand request,
                                   out ushort replyClassId,
                                   out ushort replyMethodId)
 {
     request       = new OutgoingCommand(new Impl.ConnectionClose(reasonCode, reasonText, 0, 0));
     replyClassId  = ClassConstants.Connection;
     replyMethodId = ConnectionMethodConstants.CloseOk;
 }
        public override bool EnqueueOutgoingCommand(OutgoingCommand command)
        {
            if (UdpChannel.InitialSequenceNumber == command.ReliableSequenceNumber)
            {
                command.ReliableSequenceNumber = ++Channel.OutgoingReliableSequenceNumber;
            }

            Commands.Enqueue(command);

            return(true);
        }
        internal OutgoingCommand RemoveSentReliableCommand(IncomingCommand inCommand)
        {
            lock (_sentCommands)
            {
                //채널과 reliableSequenceNumber가 동일한 command를 삭제한다.
                OutgoingCommand command = _sentCommands.Find(o => o != null &&
                                                             o.ReliableSequenceNumber == inCommand.AckReceivedReliableSequenceNumber &&
                                                             o.Channel == inCommand.Channel);

                if (command != null)
                {
                    _sentCommands.Erase(command);

                    if (_sentCommands.Count > 0)
                    {
                        Interlocked.Exchange(ref _resendingTimeout, (int)(_sentCommands[0].SentTime + _sentCommands[0].RoundTripTimeout));
                    }
                }
                return(command);
            }
        }
        internal bool EnqueueSentCommand(OutgoingCommand command, uint currentSendingTime, uint newRtt, uint disconnectTimeout)
        {
            command.SentTime = currentSendingTime;
            command.SendAttempts++; // 송신 횟수
            // 재전송을 위한 평균 RTT + 평균 분산 값
            command.RoundTripTimeout = newRtt * command.SendAttempts;

            lock (_sentCommands)
            {
                // sentReliableCommands 비어 있을 경우, 현재 command를 기준으로 재전송 시간을 설정한다.
                OutgoingCommand oc = _sentCommands.Count > 0 ? _sentCommands[0] : command;
                Interlocked.Exchange(ref _resendingTimeout, (int)(oc.SentTime + command.RoundTripTimeout));

                if (command.SendAttempts <= 1)
                {
                    command.SendingTimeout = command.SentTime + disconnectTimeout;
                    _sentCommands.Add(command);
                }
            }

            return(true);
        }
示例#8
0
 public void CreateConnectionClose(ushort reasonCode, string reasonText, out OutgoingCommand request, out ProtocolCommandId replyProtocolCommandId)
 {
     request = new OutgoingCommand(new Impl.ConnectionClose(reasonCode, reasonText, 0, 0));
     replyProtocolCommandId = ProtocolCommandId.ConnectionCloseOk;
 }
示例#9
0
 public void CreateChannelClose(ushort reasonCode,
                                string reasonText,
                                out OutgoingCommand request)
 {
     request = new OutgoingCommand(new Impl.ChannelClose(reasonCode, reasonText, 0, 0));
 }
 public abstract bool EnqueueOutgoingCommand(OutgoingCommand command);