예제 #1
0
        public bool PushHead(object data)
        {
            BASE_LIST_NODE node = null;

            node = new BASE_LIST_NODE();
            if (LOG_ERROR(node != null))
            {
                goto Exit0;
            }
            if (LOG_ERROR(node.Prev == null && node.Next == null))
            {
                goto Exit0;
            }

            node.Data = data;

            node.Prev = m_Head;
            node.Next = m_Head.Next;

            node.Next.Prev = node;
            m_Head.Next    = node;
            ++m_Size;

            return(true);

Exit0:
            return(false);
        }
예제 #2
0
        public bool InsertBefore(BASE_LIST_NODE target, BASE_LIST_NODE node)
        {
            if (LOG_ERROR(target != null))
            {
                goto Exit0;
            }
            if (LOG_ERROR(target.Next != null))
            {
                goto Exit0;
            }
            if (LOG_ERROR(node != null))
            {
                goto Exit0;
            }
            if (LOG_ERROR(node.Prev == null && node.Next == null))
            {
                goto Exit0;
            }

            node.Next        = target;
            node.Prev        = target.Prev;
            target.Prev.Next = node;
            target.Prev      = node;
            ++m_Size;

            return(true);

Exit0:
            return(false);
        }
예제 #3
0
 public static void Clear(BASE_LIST_NODE node)
 {
     if (node != null)
     {
         node.Data = null;
         node.Prev = null;
         node.Next = null;
     }
 }
예제 #4
0
        private void _PostSendThreadProc()
        {
            int            sendDataSockerCount = 0;
            LPSocker       socker   = null;
            BASE_LIST_NODE node     = null;
            BASE_LIST_NODE nextNode = null;

            while (m_CheckDelayRun)
            {
                sendDataSockerCount = 0;

                if (m_ValidSockerList.IsEmpty())
                {
                    Thread.Sleep(1);
                    continue;
                }

                lock (m_ValidListLocker)
                {
                    node = m_ValidSockerList.Head.Next;
                    while (node != null && node != m_ValidSockerList.Rear)
                    {
                        nextNode = node.Next;
                        socker   = (LPSocker)node.Data;
                        if (socker == null)
                        {
                            LOG_ERROR(false);
                            node = nextNode;
                            continue;
                        }

                        if (socker.PostSend())
                        {
                            ++sendDataSockerCount;
                        }

                        node = nextNode;
                    }
                }

                if (sendDataSockerCount > 0)
                {
                    Thread.Sleep(1);
                }
            }

            return;
        }
예제 #5
0
        public BASE_LIST_NODE PopRear()
        {
            BASE_LIST_NODE result = null;

            if (LOG_ERROR(m_Rear.Prev != m_Head))
            {
                goto Exit0;
            }

            result           = m_Rear.Prev;
            m_Rear.Prev      = result.Prev;
            result.Prev.Next = m_Rear;

            result.Prev = null;
            result.Next = null;
            --m_Size;

            return(result);

Exit0:
            return(null);
        }
예제 #6
0
        public BASE_LIST_NODE PopHead()
        {
            BASE_LIST_NODE result = null;

            if (LOG_ERROR(m_Head.Next != m_Rear))
            {
                goto Exit0;
            }

            result           = m_Head.Next;
            m_Head.Next      = result.Next;
            result.Next.Prev = m_Head;

            result.Prev = null;
            result.Next = null;
            --m_Size;

            return(result);

Exit0:
            return(null);
        }
예제 #7
0
        public bool Remove(BASE_LIST_NODE node)
        {
            if (LOG_ERROR(node != null))
            {
                goto Exit0;
            }
            if (LOG_ERROR(node.Prev != null && node.Next != null))
            {
                goto Exit0;
            }

            node.Prev.Next = node.Next;
            node.Next.Prev = node.Prev;

            node.Prev = null;
            node.Next = null;
            --m_Size;

            return(true);

Exit0:
            return(false);
        }
예제 #8
0
        internal void HandleOneEvent()
        {
            LPNetEvent     netEvent = null;
            BASE_LIST_NODE node     = null;

            for (int i = 0; i < m_EventListCount; ++i)
            {
                if (m_EventLists[i].IsEmpty())
                {
                    continue;
                }

                lock (m_EventListLocker[i])
                {
                    node = m_EventLists[i].PopHead();
                    if (LOG_ERROR(node != null))
                    {
                        goto Exit0;
                    }

                    netEvent = (LPNetEvent)node.Data;
                    if (LOG_ERROR(netEvent != null))
                    {
                        goto Exit0;
                    }
                }

                switch (netEvent.eType)
                {
                case ENetEventType.Recv:
                {
                    _ProcRecvEvent(netEvent);
                }
                break;

                case ENetEventType.Terminate:
                {
                    _ProcTerminateEvent(netEvent);
                }
                break;

                case ENetEventType.Establish:
                {
                    _ProcEstablishEvent(netEvent);
                }
                break;

                case ENetEventType.ConnectError:
                {
                    _ProcConnectErrorEvent(netEvent);
                }
                break;

                default:
                    if (LOG_ERROR(false))
                    {
                        goto Exit0;
                    }
                    break;
                }
            }

Exit0:

            if (netEvent != null)
            {
                _FreeEvent(netEvent);
            }

            return;
        }
예제 #9
0
        private void _CheckDelayThreadProc()
        {
            bool           result   = false;
            long           ticks    = 0;
            LPSocker       socker   = null;
            BASE_LIST_NODE node     = null;
            BASE_LIST_NODE nextNode = null;

            while (m_CheckDelayRun)
            {
                Thread.Sleep(5);

                ticks = DateTime.Now.Ticks;

                lock (m_DelayLocker)
                {
                    //检查延迟的关闭连接
                    node = m_DelayCloseList.Head.Next;
                    while (node != null && node != m_DelayCloseList.Rear)
                    {
                        nextNode = node.Next;
                        socker   = (LPSocker)node.Data;
                        if (socker == null)
                        {
                            LOG_ERROR(false);
                            node = nextNode;
                            continue;
                        }

                        if (ticks >= socker.DelayCloseBeginTick + socker.DelayCloseDuration)
                        {
                            socker.Sock.Close();
                            result = m_DelayCloseList.Remove(node);
                            LOG_ERROR(result);

                            DelayRelease(socker);
                        }

                        node = nextNode;
                    }

                    //检查延迟释放的连接
                    node = m_DelayReleaseList.Head.Next;
                    while (node != null && node != m_DelayReleaseList.Rear)
                    {
                        nextNode = node.Next;
                        socker   = (LPSocker)node.Data;
                        if (socker == null)
                        {
                            LOG_ERROR(false);
                            node = nextNode;
                            continue;
                        }

                        if (ticks >= socker.DelayReleaseBeginTick + socker.DelayReleaseDuration)
                        {
                            result = m_DelayReleaseList.Remove(node);
                            LOG_ERROR(result);

                            LP.NetModule.FreeSocker(socker);
                        }

                        node = nextNode;
                    }
                }
            }

            return;
        }