Esempio n. 1
0
        /// <summary>
        /// 释放所有命令
        /// </summary>
        /// <param name="head"></param>
        /// <param name="end"></param>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        internal ClientCommand.CommandBase Free(ClientCommand.CommandBase head, ClientCommand.CommandBase end, int startIndex)
        {
            DisposeTimeout();
            bool isNext = false;

            freeEndIndexLock.EnterSleepFlag();
            try
            {
                foreach (CommandLink[] array in arrays)
                {
                    if (isNext)
                    {
                        if (array == null)
                        {
                            break;
                        }
                        for (startIndex = array.Length; startIndex != 0;)
                        {
                            ClientCommand.Command command = array[--startIndex].Command;
                            if (command != null)
                            {
                                array[startIndex].Command = null;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }
                    }
                    else
                    {
                        isNext = true;
                        do
                        {
                            ClientCommand.Command command = array[startIndex].Command;
                            if (command != null)
                            {
                                array[startIndex].Command = null;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }while (++startIndex != array.Length);
                    }
                }
            }
            finally { freeEndIndexLock.ExitSleepFlag(); }
            return(head);
        }
Esempio n. 2
0
        /// <summary>
        /// 释放所有命令
        /// </summary>
        /// <param name="head"></param>
        /// <param name="end"></param>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        internal ClientCommand.CommandBase Free(ClientCommand.CommandBase head, ClientCommand.CommandBase end, int startIndex)
        {
            bool isNext = false;

            foreach (CommandLink[] array in arrays)
            {
                if (isNext)
                {
                    if (array == null)
                    {
                        break;
                    }
                    for (startIndex = array.Length; startIndex != 0;)
                    {
                        ClientCommand.Command command = array[--startIndex].Command;
                        if (command != null)
                        {
                            array[startIndex].Command = null;
                            if (head == null)
                            {
                                head = end = command;
                            }
                            else
                            {
                                end.LinkNext = command;
                                end          = command;
                            }
                        }
                    }
                }
                else
                {
                    isNext = true;
                    do
                    {
                        ClientCommand.Command command = array[startIndex].Command;
                        if (command != null)
                        {
                            array[startIndex].Command = null;
                            if (head == null)
                            {
                                head = end = command;
                            }
                            else
                            {
                                end.LinkNext = command;
                                end          = command;
                            }
                        }
                    }while (++startIndex != array.Length);
                }
            }
            return(head);
        }
Esempio n. 3
0
        /// <summary>
        /// 超时事件
        /// </summary>
        /// <param name="seconds">超时秒计数</param>
        private void onTimeout(uint seconds)
        {
            int startIndex = ClientCommand.KeepCommand.CommandPoolIndex, index = 0;

            ClientCommand.CommandBase head = null, end = null;
            while (System.Threading.Interlocked.CompareExchange(ref freeEndIndexLock, 1, 0) != 0)
            {
                if (isTimeout == 0)
                {
                    AutoCSer.Threading.ThreadYield.YieldOnly();
                }
                else
                {
                    System.Threading.Thread.Sleep(0);
                }
            }
            try
            {
                isTimeout = 1;
                foreach (CommandLink[] array in arrays)
                {
                    if (index != 0)
                    {
                        if (array == null)
                        {
                            break;
                        }
                        for (startIndex = 0; startIndex != array.Length; ++startIndex, ++index)
                        {
                            ClientCommand.Command command = array[startIndex].CheckTimeout(seconds, commandCount);
                            if (command != null)
                            {
                                arrays[freeEndIndex >> bitSize][freeEndIndex & arraySizeAnd].Next = index;
                                freeEndIndex = index;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }
                    }
                    else
                    {
                        index = array.Length;
                        do
                        {
                            ClientCommand.Command command = array[startIndex].CheckTimeout(seconds, commandCount);
                            if (command != null)
                            {
                                arrays[freeEndIndex >> bitSize][freeEndIndex & arraySizeAnd].Next = startIndex;
                                freeEndIndex = startIndex;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }while (++startIndex != index);
                    }
                }
            }
            finally
            {
                isTimeout = 0;
                System.Threading.Interlocked.Exchange(ref freeEndIndexLock, 0);
                if (head != null)
                {
                    ClientCommand.CommandBase.CancelLink(head, ReturnType.Timeout);
                }
                client.CallOnTimeout();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 释放所有命令
        /// </summary>
        /// <param name="head"></param>
        /// <param name="end"></param>
        /// <param name="startIndex"></param>
        /// <returns></returns>
        internal ClientCommand.CommandBase Free(ClientCommand.CommandBase head, ClientCommand.CommandBase end, int startIndex)
        {
            DisposeTimeout();
            bool isNext = false;

            while (System.Threading.Interlocked.CompareExchange(ref freeEndIndexLock, 1, 0) != 0)
            {
                if (isTimeout == 0)
                {
                    AutoCSer.Threading.ThreadYield.YieldOnly();
                }
                else
                {
                    System.Threading.Thread.Sleep(0);
                }
            }
            try
            {
                foreach (CommandLink[] array in arrays)
                {
                    if (isNext)
                    {
                        if (array == null)
                        {
                            break;
                        }
                        for (startIndex = array.Length; startIndex != 0;)
                        {
                            ClientCommand.Command command = array[--startIndex].Command;
                            if (command != null)
                            {
                                array[startIndex].Command = null;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }
                    }
                    else
                    {
                        isNext = true;
                        do
                        {
                            ClientCommand.Command command = array[startIndex].Command;
                            if (command != null)
                            {
                                array[startIndex].Command = null;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }while (++startIndex != array.Length);
                    }
                }
            }
            finally { System.Threading.Interlocked.Exchange(ref freeEndIndexLock, 0); }
            return(head);
        }
Esempio n. 5
0
        /// <summary>
        /// 超时事件
        /// </summary>
        /// <param name="seconds">超时秒计数</param>
        private void onTimeout(uint seconds)
        {
            int startIndex = ClientCommand.KeepCommand.CommandPoolIndex, index = 0;

            ClientCommand.CommandBase head = null, end = null;
            freeEndIndexLock.EnterSleepFlag();
            try
            {
                foreach (CommandLink[] array in arrays)
                {
                    if (index != 0)
                    {
                        if (array == null)
                        {
                            break;
                        }
                        for (startIndex = 0; startIndex != array.Length; ++startIndex, ++index)
                        {
                            ClientCommand.Command command = array[startIndex].CheckTimeout(seconds, commandCount);
                            if (command != null)
                            {
                                arrays[freeEndIndex >> bitSize][freeEndIndex & arraySizeAnd].Next = index;
                                freeEndIndex = index;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }
                    }
                    else
                    {
                        index = array.Length;
                        do
                        {
                            ClientCommand.Command command = array[startIndex].CheckTimeout(seconds, commandCount);
                            if (command != null)
                            {
                                arrays[freeEndIndex >> bitSize][freeEndIndex & arraySizeAnd].Next = startIndex;
                                freeEndIndex = startIndex;
                                if (head == null)
                                {
                                    head = end = command;
                                }
                                else
                                {
                                    end.LinkNext = command;
                                    end          = command;
                                }
                            }
                        }while (++startIndex != index);
                    }
                }
            }
            finally
            {
                freeEndIndexLock.ExitSleepFlag();
                if (head != null)
                {
                    ClientCommand.CommandBase.CancelLink(head, ReturnType.Timeout);
                }
                client.CallOnTimeout();
            }
        }