Ejemplo n.º 1
0
        public void AddTask(ConnectionUDP conn, int sequence)
        {
            ResendItem resendItem = new ResendItem(conn, sequence);

            resendItem.ResendTime = GetNewResendTime(conn);
            TaskList.Add(resendItem);
        }
Ejemplo n.º 2
0
        public void Run()
        {
            while (true)
            {
                // try
                ResendItem resendItem = TaskList.Take();

                if (resendItem.Conn.IsConnected)
                {
                    long sleepTime = resendItem.ResendTime - DateTimeExtensions.CurrentTimeMillis();
                    if (sleepTime > 0)
                    {
                        while (sleepTime - Int32.MaxValue > 0)
                        {
                            sleepTime -= Int32.MaxValue;
                            Thread.Sleep(Int32.MaxValue);
                        }
                        Thread.Sleep((int)sleepTime);
                    }
                    resendItem.AddCount();

                    if (resendItem.Conn.MySender.GetDataPacket(resendItem.Sequence) != null)
                    {
                        if (!resendItem.Conn.StopNow)
                        {
                            resendItem.Conn.MySender.Resend(resendItem.Sequence, resendItem.Count);
                        }
                    }

                    if (resendItem.Count < RUDPConfig.ReSendTryTimes)
                    {
                        resendItem.ResendTime = GetNewResendTime(resendItem.Conn);
                        TaskList.Add(resendItem);
                    }
                }
                if (resendItem.Conn.MyClientControl.Closed)
                {
                    break;
                }
            }
        }