예제 #1
0
        /// <summary>
        /// 接收事件压入队列
        /// </summary>
        /// <param name="dataLen">数据长度</param>
        public void PushReceiveEvent(int dataLen)
        {
            NetEvent netEvent = CInstacePoolKeepNumber <NetEvent> .Alloc();

            netEvent.m_nEvtType = NetEvtType.Event_Receive;
            netEvent.m_dataLen  = dataLen;
            this.EnQueue(netEvent);
        }
예제 #2
0
        /// <summary>
        /// 连接事件压入队列
        /// </summary>
        /// <param name="bSuccess">是否连接成功</param>
        public void PushConnectEvent(bool bSuccess)
        {
            NetEvent netEvent = CInstacePoolKeepNumber <NetEvent> .Alloc();

            netEvent.m_nEvtType = NetEvtType.Event_Connect;
            netEvent.m_bSuccess = bSuccess;
            this.EnQueue(netEvent);
        }
예제 #3
0
        /// <summary>
        /// 关闭事件压入队列
        /// </summary>
        /// <param name="nErrCode">关闭错误码</param>
        public void PushClosedEvent(NetErrCode nErrCode)
        {
            NetEvent netEvent = CInstacePoolKeepNumber <NetEvent> .Alloc();

            netEvent.m_nEvtType = NetEvtType.Event_Closed;
            netEvent.m_nErrCode = nErrCode;
            this.EnQueue(netEvent);
        }
예제 #4
0
        /// <summary>
        /// 处理收发消息
        /// </summary>
        /// <returns>处理的消息数</returns>
        public int ProcessMsg()
        {
            int result;

            if (this.m_oProcess == null || this.m_oSocket == null)
            {
                result = 0;
            }
            else
            {
                if (this.GetState() == SocketState.State_Connected)
                {
                    this.m_oSocket.CheckBeginSend();//也就是fixedUpdate每帧都在执行,在NetworkManager下
                }
                int    num = 0;
                object obj = this.DeQueue();//消息事件出队列
                while (obj != null)
                {
                    NetEvent netEvent = obj as NetEvent;
                    if (netEvent == null)
                    {
                        Trace.Assert(false);
                    }
                    else
                    {
                        switch (netEvent.m_nEvtType)
                        {
                        case NetEvtType.Event_Connect:
                            this.m_oProcess.OnConnect(netEvent.m_bSuccess);
                            break;

                        case NetEvtType.Event_Closed:
                            this.m_oProcess.OnClosed(netEvent.m_nErrCode);
                            break;

                        case NetEvtType.Event_Receive:
                            this.m_oProcess.OnReceive(netEvent.m_dataLen);
                            break;

                        default:
                            Trace.Assert(false);
                            break;
                        }
                        CInstacePoolKeepNumber <NetEvent> .Release(ref netEvent);

                        num++;
                        obj = this.DeQueue();
                    }
                }
                result = num;
            }
            return(result);
        }